utf-8 - 如何检查新角色的现有角色的延续?
问题描述
如果您正在读取编码为 UTF-8 的文件,并且您读取了一个字节,那么您如何确定该字节是否是现有字符的延续,而不是新字符的开头?
解决方案
如果字节的二进制值为10xxxxxx
(x可以是 0 或 1),则该字节是 UTF-8 连续字节。初始 UTF-8 字节遵循以下模式:
0xxxxxxx - start (and end) of 1-byte sequence
110xxxxx - start of 2-byte sequence (followed by one continuation byte)
1110xxxx - start of 3-byte sequence (followed by two continuation bytes)
11110xxx - start of 4-byte sequence (followed by three continuation bytes)
推荐阅读
- c# - ML.NET 如何检测 C# 中方法链的结尾?
- java - Elasticsearch Java:无法为对象堆错误保留足够的空间
- typescript - 当与字符串原始类型联合时,使打字稿显示字符串文字的类型提示
- python - 检查列表中是否只有一种元素是连续的?
- python-3.x - 如何将多个 Lambda 函数从 python 2.7 更新到 3.6
- python - 我的第一个 python 程序!所得税计算器
- node.js - 当我将会话存储到 redis 时无法获取 cookie
- angular - 使用 Nestjs 进行社交登录。REST API 的问题
- c++ - 为什么“static”关键字解决了嵌套类中非常量类型的无效初始化但仍然输出错误?
- powerbi - 如何将 o365 安全与合规中心数据导入 PowerBI