utf8
API Reference
Functions
char
codes
codepoint
len
offset
graphemes
Returns
Code Samples
Utf8 Graphemes
-- "e" followed by a combining acute accent is one grapheme but two codepoints
local str = "ae\u{0301}b"
print(utf8.len(str)) --> 4
for first, last in utf8.graphemes(str) do
local grapheme = string.sub(str, first, last)
print(first, last, #grapheme)
end
--> 1 1 1
--> 2 4 3
--> 5 5 1nfcnormalize
Parameters
Returns
Code Samples
Utf8 NFC Normalize
local decomposed = "e\u{0301}" -- "e" plus a combining acute accent
local composed = utf8.nfcnormalize(decomposed)
print(utf8.len(decomposed)) --> 2
print(utf8.len(composed)) --> 1
print(composed == "\u{00E9}") --> truenfdnormalize
Parameters
Returns
Code Samples
Utf8 NFD Normalize
local composed = "\u{00E9}" -- precomposed "é"
local decomposed = utf8.nfdnormalize(composed)
print(utf8.len(composed)) --> 1
print(utf8.len(decomposed)) --> 2
print(decomposed == "e\u{0301}") --> trueProperties