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:
Strings are all encoded with the same charset, which is a Unicode encoding internal to Racket. Conversion between strings and bytes requires explicitly reencoding the string.
Text values specify their charset directly, and different text values can have different charsets. Constructing a text value from bytes doesn’t require performing any decoding —
that’s only needed when changing the text’s charset or when converting the text into a string.
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
charset : charset? bytes : immutable-bytes?
procedure
(text-charset txt) → charset?
txt : text?
procedure
(text-bytes txt) → charset?
txt : text?
value
us-ascii : "The ASCII "
procedure
(text-media? m) → boolean?
m : media?
procedure
(text/plain #:charset charset) → media-type?
charset : charset?
procedure
(text->media txt) → text-media?
txt : text?
procedure
(media->text m) → text?
m : text-media?