UTF-8 encode and decode: Difference between revisions

Content added Content deleted
Line 423: Line 423:
:m<0x110000
:m<0x110000
?Uint8Array.from(
?Uint8Array.from(
[ m>>18&0x07|0xf0,m>>12&0x3f|0x80,m>>6 &0x3f|0x80,m>>0 &0x3f|0x80])
[ m>>18&0x07|0xf0,m>>12&0x3f|0x80,m>>6&0x3f|0x80,m>>0&0x3f|0x80])
:(()=>{throw'Invalid Unicode Code Point!'})())
:(()=>{throw'Invalid Unicode Code Point!'})())
( typeof n==='string'
( typeof n==='string'
Line 455: Line 455:
Uint32Array.from(str,s=>s.codePointAt(0))
Uint32Array.from(str,s=>s.codePointAt(0))
,cus=
,cus=
[ [0x41]
[ [ 0x41]
,[0xc3,0xb6]
,[ 0xc3,0xb6]
,[0xd0,0x96]
,[ 0xd0,0x96]
,[0xe2,0x82,0xac]
,[ 0xe2,0x82,0xac]
,[0xf0,0x9d,0x84,0x9e]]
,[ 0xf0,0x9d,0x84,0x9e]]
.map(a=>Uint8Array.from(a))
.map(a=>Uint8Array.from(a))
,zip3=
,zip3=
([a,...as],[b,...bs],[c,...cs])=>
([a,...as],[b,...bs],[c,...cs])=>
0<as.length+bs.length+cs.length
0<as.length+bs.length+cs.length
?[[a,b,c],...zip3(as,bs,cs)]
?[ [ a,b,c],...zip3(as,bs,cs)]
:[[a,b,c]]
:[ [ a,b,c]]
,inputs=zip3(str,cps,cus);
,inputs=zip3(str,cps,cus);
</lang>
</lang>