Strings are UTF-8
UTF-8 is the way almost every web page and file stores text today. In Novis, a string is always
valid UTF-8. A string with invalid bytes is not possible, so your code never has to check for one.
Length counts what a person sees
Section titled “Length counts what a person sees”Core\Str::length counts graphemes. A grapheme is what a person counts as one character. A flag,
an emoji made of several parts and a letter with an accent are each one grapheme. So the length
of "café" is 4, whatever bytes the é uses.
Methods that count bytes or code points also exist. Each has its own name, so you always know which unit you get.
Bytes are a different type
Section titled “Bytes are a different type”Data that is not text, such as an image or a compressed file, has the type bytes. A bytes
value can contain any data. You convert it to a string when you know it is text, and the conversion
checks that it is valid UTF-8.
What it costs
Section titled “What it costs”Counting graphemes is slower than counting bytes. For text that is plain ASCII, Novis counts the bytes, which is fast. For other text, it reads the whole string.
Where to go next
Section titled “Where to go next”- Syntax: strings shows how to write and join strings.
- Unicode strings shows the length of strings with emoji and accents.
