encoding - UTF-8 可以在中间包含零字节吗?
问题描述
UTF-8 对每个字符使用 1-4 个字节。
这是Python 2len('') == 4
和 JavaScript中的 4 字节字符So encodeURI('') === "%F0%9F%90%8D"
。
问题是,UTF-8 可以在中间包含一个零字节吗?
例如,第一个俄语字母А
由 2 个字节组成:0xD0, 0x90
.
可能存在一个字母中间没有前导零或零的字母,像这样0xAB, 0, 0xCD
?
解决方案
The only zero byte in a valid UTF-8 stream would be a representation of U+0000 NULL, which is just 00
(hex) in UTF-8.
No valid encoding of any other character in UTF-8 will produce a full byte without any bits set.
In other words: if your input characters does not contain the NULL character, then your output byte stream is guaranteed to not contain any zero bytes.
推荐阅读
- python - 如何在熊猫数据框中创建一个通过dict或list循环的列?
- java - 如何在 JAVA 中进行 VLOOKUP
- javascript - 反应复选框功能只有一个选择
- php - 为特定类别生成 URL
- directx - DirectCompute 着色器:如何摆脱警告 X3205: 'round'
- excel - VBA - 将文件另存为 PDF 到具有预定义名称的特定位置
- spring-boot - Spring集成HttpRequestExecutingMessageHandler ContentType问题
- python-3.x - 返回 Null 类型数据的 Python 函数
- spring - Spring将不同的属性文件绑定到不同的bean
- swift - Reality Composer 默认锚点