UTF-8 encode and decode: Difference between revisions
Content deleted Content added
Line 388:
<lang javascript>
/***************************************************************************\
|* Pure UTF-8 handling without detailed error reporting functionality.
|***************************************************************************|
|* utf8encode *|
|* <
|* > Uint8Array encoded_character *|
|* | ErrorString *|
Line 400:
|***************************************************************************|
|* utf8decode *|
|* <
|* > uint32 character *|
|* | ErrorString *|
|* *|
|* utf8decode takes an array of one
|*
\***************************************************************************/
Line 417 ⟶ 414:
m<0x80
?Uint8Array.from(
[ m>>0
:m<0x800
?Uint8Array.from(
[ m>>6
:m<0x10000
?Uint8Array.from(
[ m>>12&0x0f|0xe0,m>>6&0x3f|0x80,m>>0&0x3f|0x80])
:m<0x110000
?Uint8Array.from(
[ m>>18&0x07|0xf0,m>>12&0x3f|0x80,m>>6 &0x3f|0x80,m>>0 &0x3f|0x80])
:(()=>{throw'Invalid Unicode Code Point!'})())
( typeof n==='string'
Line 441 ⟶ 432:
m<0x80
?( m&0x7f)<<0
:0xc1<m&&m<0xe0&&n===(n&0xbf)
?( m&
||0xed<m&&m<0xf0&&
&&o===o&0xbf
?( m&0x0f)<<12|( n&0x3f)<<6|( o&0x3f)<<0
?( m&0x07)<<18|( n&0x3f)<<12|( o&0x3f)<<6|( p&0x3f)<<0
:(()=>{throw'Invalid UTF-8 encoding!'})()
</lang>
|