UTF-8 encode and decode: Difference between revisions

Line 295:
𝄞 MUSICAL SYMBOL G CLEF 119070 U+1D11E F0 9D 84 9E 𝄞
😜 FACE WITH STUCK-OUT TONGUE AND WINKING EYE 128540 U+1F61C F0 9F 98 9C 😜</pre>
 
=={{header|Phix}}==
Standard autoinclude, see the manual and/or builtins/utfconv.e
( http://phix.x10.mx/docs/html/utfconv.htm and/or https://bitbucket.org/petelomax/phix/src )<br>
As requested in the task description:
<lang Phix>constant tests = {#0041, #00F6, #0416, #20AC, #1D11E}
 
function hex(sequence s, string fmt) -- output helper
for i=1 to length(s) do
s[i] = sprintf(fmt,s[i])
end for
return join(s,',')
end function
 
for i=1 to length(tests) do
integer codepoint = tests[i]
sequence s = utf32_to_utf8({codepoint}),
r = utf8_to_utf32(s)
printf(1,"#%04x -> {%s} -> {%s}\n",{codepoint, hex(s,"#%02x"),hex(r,"#%04x")})
end for</lang>
{{out}}
<pre>
#0041 -> {#41} -> {#0041}
#00F6 -> {#C3,#B6} -> {#00F6}
#0416 -> {#D0,#96} -> {#0416}
#20AC -> {#E2,#82,#AC} -> {#20AC}
#1D11E -> {#F0,#9D,#84,#9E} -> {#1D11E}
</pre>
 
=={{header|Racket}}==
7,820

edits