On this page:
text?
text
text-charset
text-bytes
charset?
utf-8
us-ascii
text-media?
text/  plain
text->media
media->text
8.12

8.7 Text Media🔗ℹ

 (require rebellion/media/text/plain) package: rebellion

Text is a type of media that represents a sequence of characters encoded in a bytestring according to a standardized set of rules called a character set, or charset for short. Charsets must be registered with the IANA and their names are assigned in the IANA Character Set Registry.

Text values are very similar to strings. The primary difference between the two is in how character encoding and decoding are handled:

This difference is important when a program produces and consumes textual data without examining it, such as one that copies files from one computer to another. In such cases, the text can be handled without ever changing its encoding, completely avoiding the cost of converting its bytes back and forth between string representations.

procedure

(text? v)  boolean?

  v : any/c
A predicate for text.

procedure

(text charset bytes)  text?

  charset : charset?
  bytes : immutable-bytes?
Constructs text from the given bytes and charset. This function performs no validation whatsoever that bytes conforms to the rules of charset; a noncomforming bytes instead results in an error when the constructed text is converted to a string or reencoded with a different charset. This function runs in constant time and constant space.

procedure

(text-charset txt)  charset?

  txt : text?
Returns the charset of txt.

procedure

(text-bytes txt)  charset?

  txt : text?
Returns the bytes of txt.

procedure

(charset? v)  boolean?

  v : any/c
A predicate for charsets.

value

utf-8 : charset?

The Unicode UTF-8 character set.

value

us-ascii : "The ASCII "

procedure

(text-media? m)  boolean?

  m : media?
A predicate for media whose top level type is text, such as text/plain and text/csv.

procedure

(text/plain #:charset charset)  media-type?

  charset : charset?
Constructs the media type for text encoded according to charset.

procedure

(text->media txt)  text-media?

  txt : text?
Converts txt into media of type text/plain.

procedure

(media->text m)  text?

  m : text-media?
Converts m into text.