EdwardZZZ / articles

工作点滴记录
2 stars 0 forks source link

String字符串 #23

Open EdwardZZZ opened 7 years ago

EdwardZZZ commented 7 years ago

The String type is the set of all ordered sequences of zero or more 16-bit unsigned integer values (“elements”) up to a maximum length of 2e53 - 1 elements.

String中的每一个字符都被视为独立的UTF-16代码单元,即占2个字节,作用在字符串上的所有操作都视它们为无差别的16位无符号整数(这里的UTF-16,其实是指内部实现,计算机内存中都是基于unicode编码的,只是在存储或读取时会进行UTF-8或者其他编码类型转换)。但是UTF-16却有两种长度的字符,U+0000到U+FFFF之间的字符占2个字节,U+10000到U+10FFFF之间的字符占4字节。对于4字节的字符ES是无法准确处理的,需要自己去根据编码值情况判断,这也是一大坑爹之处。

处理方式可见《emoji》 https://github.com/EdwardZZZ/articles/issues/17