我正在学习 UTF-8 标准,这就是我正在学习的内容:
Definition and bytes used
UTF-8 binary representation Meaning
0xxxxxxx 1 byte for 1 to 7 bits chars
110xxxxx 10xxxxxx 2 bytes for 8 to 11 bits chars
1110xxxx 10xxxxxx 10xxxxxx 3 bytes for 12 to 16 bits chars
11110xxx 10xxxxxx 10xxxxxx 10xxxxxx 4 bytes for 17 to 21 bits chars
Run Code Online (Sandbox Code Playgroud)
我想知道,为什么10xxxxxx不是2 字节的 UTF-8 代码,而是使用 4 字节的 UTF-8 代码获得 1 位到 22 位?现在的情况是,丢失了 64 个可能的值(从1000000到10111111)。我不是要争论标准,但我想知道为什么会这样?
**编辑**
甚至,为什么不是
UTF-8 binary representation Meaning
0xxxxxxx 1 byte for 1 to 7 bits chars
110xxxxx xxxxxxxx 2 bytes for 8 to 13 bits chars
1110xxxx xxxxxxxx xxxxxxxx 3 bytes for 14 to 20 bits chars
11110xxx xxxxxxxx xxxxxxxx xxxxxxxx 4 bytes for 21 to 27 bits chars
Run Code Online (Sandbox Code Playgroud)
……?
谢谢!
UTF-8 是自同步的。检查字节的东西可以判断它是在 UTF-8 字符的开头,还是在一个字符的中间。
假设您的方案中有两个字符: 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
如果解析器在第二个八位字节中提取,则无法判断不是将第二个和第三个八位字节读为一个字符。使用 UTF-8,解析器可以判断它位于一个字符的中间并继续前进到下一个字符的开头,同时发出一些状态来提及损坏的符号。
对于编辑:如果最高位是明确的,UTF-8 解析器知道他们正在查看以一个八位字节表示的字符。如果已设置,则它是一个多八位字节字符。
这完全是关于错误恢复和八位字节的简单分类。
| 归档时间: |
|
| 查看次数: |
461 次 |
| 最近记录: |