27 lines
773 B
Plaintext
27 lines
773 B
Plaintext
require "uchar"
|
|
require "gchar"
|
|
local fmt = require("fmt")
|
|
|
|
local w = "voilà"
|
|
local u = uchar.of(w)
|
|
for i = 1, u:len() do
|
|
io.write($"{u:get(i)} ") -- prints the 5 Unicode 'characters'
|
|
end
|
|
print($"\nThe length of {w} is {u:len()}")
|
|
|
|
print("\nIts code-points are:")
|
|
fmt.lprint(u:tocodes(), " ", "") -- prints the code-points as numbers
|
|
|
|
print("\n\nIts bytes are: ")
|
|
fmt.lprint(u:tobytes(), " ", "") -- prints the bytes as numbers
|
|
|
|
local zwe = "👨👩👧"
|
|
local g = gchar.of(zwe)
|
|
local codepoints = g:tocodes()
|
|
local bytes = g:tobytes()
|
|
|
|
print($"\n\n{zwe} has:")
|
|
fmt.print(" %d bytes: %s", #bytes, fmt.swrite(bytes, " ", ""))
|
|
fmt.print(" %d code-points: %s", #codepoints, fmt.swrite(codepoints, " ", ""))
|
|
fmt.print(" %d grapheme", g:len())
|