RosettaCodeData/Task/UTF-8-encode-and-decode/V-(Vlang)/utf-8-encode-and-decode.v

14 lines
390 B
Coq
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
import encoding.hex
2026-04-30 12:34:36 -04:00
fn decode(s string) ![]u8 {
2023-07-01 11:58:00 -04:00
return hex.decode(s)
}
fn main() {
println("${'Char':-7} ${'Unicode':7}\tUTF-8 encoded\tDecoded")
for codepoint in [`A`, `ö`, `Ж`, ``, `𝄞`] {
encoded := codepoint.bytes().hex()
2026-04-30 12:34:36 -04:00
decoded := decode(encoded)!
2023-07-01 11:58:00 -04:00
println("${codepoint:-7} U+${codepoint:04X}\t${encoded:-12}\t${decoded.bytestr()}")
}
}