/avail/Avail/Foundation/Bootstrap/Special Objects: string
Source: /avail/Avail/Foundation/Bootstrap/Special Objects
Categories: Primitives, Types
Supertypes: tuple
A string represents text without respect to style or encoding. Naturally, the content of a string consists of character s arrayed in a fixed order.

Like integer and double literals, string literals are understood directly by the Avail compiler. A string literal begins with a quotation mark " (U+0022), continues with arbitrary Unicode characters optionally interleaved with escape sequences, and ends with a quotation mark. The string literal metacharacters are quotation mark and reverse solidus \ (U+005C) — also called backslash. A reverse solidus alters the meaning of the next character, called the escaped character:

  • When the escaped character is reverse solidus or quotation mark, then its special meaning as a metacharacter is disabled.
  • When the escaped character is t (U+0074), then the intended character is character tabulation (U+0009), also called horizontal tab.
  • When the escaped character is n (U+006E), then the intended character is line feed (U+000A)
  • .
  • When the escaped character is r (U+0072), then the intended character is carriage return (U+000D).
  • When the escaped character is left parenthesis ( (U+0028), then the compiler expects a sequence of hexadecimal numerals separated by commas , (U+002C) and finally a right parenthesis ) (U+0029). Each hexadecimal numeral must denote an integral value from 0 to 10FFFF 16 ({@code 1114111 }10); the case of the hexadecimal digits A through F does not matter. Each number represents the character associated with the Unicode code point of the same value. The construct as a whole then denotes a sequence of characters.
  • When the escaped character is line feed (U+000A), then the compiler elides the line feed altogether. This permits a string literal to span multiple lines without forcing its content to span multiple lines. Note that an occurrence of carriage return (U+000D) after the reverse solidus, or even the combination carriage return+line feed, is treated similarly; it is stripped from the resulting string.
  • When the escaped character is vertical line | (U+007C), then the compiler discards all whitespace from the beginning of the same line up to the reverse solidus. This region is not permitted to contain characters other than whitespace, in fact. This feature permits nice formatting of multiline string literals within source code, and is particularly powerful in conjunction with escaping of line feeds.
  • The empty string is written as "". It is the same value as the empty tuple, <>.