UTF-8 encode and decode: Difference between revisions

(Add Ruby implementation)
Line 21:
Provided below is a reference implementation in Common Lisp.
 
=={{header|8th}}==
<lang 8th>
hex \ so bytes print nicely
 
[
"\u0041",
"\u00F6",
"\u0416",
"\u20AC"
]
\ add the 0x1D11E one; the '\u' string notation requires four hex digits
"" 1D11E s:+ a:push
 
\ for each test, print it out and its bytes:
(
dup . space
b:new
( . space drop ) b:each
cr
) a:each! drop
 
cr
\ now the inverse:
[
[41],
[C3,B6],
[D0,96],
[E2,82,AC],
[$F0,9D,84,9E]
]
 
(
dup . space
b:new >s . cr
) a:each! drop
 
bye
</lang>
Output:<pre>
A 41
ö c3 b6
Ж d0 96
€ e2 82 ac
𝄞 f0 9d 84 9e
 
[41] A
[c3,b6] ö
[d0,96] Ж
[e2,82,ac] €
[f0,9d,84,9e] 𝄞
</pre>
=={{header|Common Lisp}}==
 
Line 157 ⟶ 208:
T
</lang>
 
 
=={{header|Ada}}==
Anonymous user