UTF-8 encode and decode: Difference between revisions

m
Update to supported Julia 1.x (tested in 1.8.5), also works in 0.6
m (Update to supported Julia 1.x (tested in 1.8.5), also works in 0.6)
Line 3:
As described in [[UTF-8]] and in [[wp:UTF-8|Wikipedia]], UTF-8 is a popular encoding of (multi-byte) [[Unicode]] code-points into eight-bit octets.
 
The goal of this task is to write a encoder that takes a unicode code-point (an integer representing a unicode character) and returns a sequence of 1-41–4 bytes representing that character in the UTF-8 encoding.
 
Then you have to write the corresponding decoder that takes a sequence of 1-41–4 UTF-8 encoded bytes and return the corresponding unicode character.
 
Demonstrate the functionality of your encoder and decoder on the following five characters:
Line 3,161:
 
=={{header|Julia}}==
Julia supports by defaultthe UTF-8 encoding (and others through packages).
{{works with|Julia|0.6}}
 
end</syntaxhighlight lang="julia">
Julia supports by default UTF-8 encoding.
<syntaxhighlight lang="julia">for t in ("A", "ö", "Ж", "€", "𝄞")
 
println(dect, " → ", enccodeunits(t))
<syntaxhighlight lang="julia">for t in ("A", "ö", "Ж", "€", "𝄞")
end
enc = Vector{UInt8}(t)
</syntaxhighlight>
dec = String(enc)
println(dec, " → ", enc)
end</syntaxhighlight>
 
{{out}}
1

edit