Methods by type

Unicode & graphemes

Full

Grapheme-aware length, codepoints, names, values, and normalization.

Raku strings are sequences of graphemes (what a reader perceives as a character), not bytes or codepoints. .chars counts graphemes, and Raku++ normalises combining sequences the way Rakudo does — so a base letter plus a combining mark is one character and composes to a single codepoint.

Grapheme-aware length #

.chars counts graphemes, so a base letter plus a combining mark is one character.

say "café".chars;
my $s = "e" ~ "\x[301]";
say $s.chars;
Output
4
1

Codepoints, names, and values #

.ord/.chr convert between a character and its codepoint; .uniname gives the Unicode name, .uniprop a property, .unival a numeric value.

say "A".ord;
say 65.chr;
say "α".uniname;
say "½".unival;
Output
65
A
GREEK SMALL LETTER ALPHA
0.5

Normalization #

A composed and a decomposed spelling of the same text compare equal, because both normalise: e plus a combining acute becomes the single codepoint é.

my $s = "e" ~ "\x[301]";
say $s.codes;
say $s eq "é";
Output
1
True

.codes is 1 — the two-codepoint input was composed to one. The .NFD/.NFC methods expose the forms explicitly: decomposed is two codepoints, composed is one.

say "é".NFD.codes;
say "é".NFC.codes;
Output
2
1

Notes #