Import std.text.unicode
std.text.unicode
std.text.unicode: what Unicode's data says about characters and text, through the runtime's fb_unicode_ functions over utf8proc: each character's general category, normal forms, case folding, and the columns text takes in a terminal.
std/text/unicode.fb
Types
UnicodeCategory
enum
Public Enum UnicodeCategory
A character's general category, in Unicode's order, as Category gives it.
-
Cn, a code point with no character.
-
Lu, an uppercase letter.
-
Ll, a lowercase letter.
-
Lt, a digraph whose first part is uppercase.
-
Lm, a modifier letter.
-
Lo, another letter, like an ideograph.
-
Mn, a mark that takes no space.
-
Mc, a mark that takes space.
-
Me, a mark that encloses its base character.
-
Nd, a decimal digit.
-
Nl, a number of letters, like a Roman numeral.
-
No, another number, like a fraction or a superscript.
-
Pc, a connector, like '_'.
-
Pd, a dash or a hyphen.
-
Ps, an opening bracket.
-
Pe, a closing bracket.
-
Pi, an opening quotation mark.
-
Pf, a closing quotation mark.
-
Po, other punctuation.
-
Sm, a math symbol.
-
Sc, a currency symbol.
-
Sk, a modifier symbol, like an accent on its own.
-
So, another symbol.
-
Zs, a space.
-
Zl, U+2028, the line separator.
-
Zp, U+2029, the paragraph separator.
-
Cc, a control character.
-
Cf, a format character, like a zero-width joiner.
-
Cs, a UTF-16 surrogate.
-
Co, a private use character.
NormalForm
enum
Public Enum NormalForm
The ways Normalize can write the same text.
-
Composed.
-
Decomposed.
-
Composed, with compatibility characters, like "fi" or "²", as their plain ones.
-
Decomposed, with compatibility characters, like "fi" or "²", as their plain ones.
Functions
Category
function
Public Function Category(c: Char): UnicodeCategory
c's general category: a letter of some case, a mark, a number, punctuation, a symbol, a
separator, or another kind.
Normalize
function
@PanicsAtCaller Public Function Normalize(text: String, form: NormalForm = NormalForm.NFC): String
text in the normal form form, so text that looks the same is the same: "é" as one
character in NFC, and as "e" and its accent in NFD. Panics past the most a String holds.
IsNormalized
function
Public Function IsNormalized(text: String, form: NormalForm = NormalForm.NFC): Bool
Whether text is in the normal form form already. One past the most a String holds isn't.
CaseFold
function
@PanicsAtCaller Public Function CaseFold(text: String): String
text case-folded, as Unicode has it, so two texts that differ only by case fold to the same:
"Straße" and "STRASSE" both to "strasse". Panics past the most a String holds.
DisplayWidth
function
Public Function DisplayWidth(c: Char): Int
The columns c takes in a terminal: 2 for a wide one, like "中" or most emoji, 0 for a mark or a
control character, and 1 for the rest.
DisplayWidth
function
Public Function DisplayWidth(text: String): Int
The columns text takes in a terminal, each grapheme cluster as many as its widest character,
so "e" with its accent is 1, and an emoji made of several is 2. A flag is 2, and so is a
character that U+FE0F asks to be drawn as emoji, like "\u{2764}\u{FE0F}", though it's 1 alone.
Report an issue with this page or with FutureBlitz on GitHub.