mbrtowc:如果读取空字符,如何确定要跳过的字符数
mbrtowc: howto determine number of characters to skip if null character is read
根据 C99 规范 mbrtowc
函数 returns 0
if the next n or fewer bytes complete the multibyte character that
corresponds to the null wide character (which is the value stored).
在编码的空字符之后立即继续读取输入的最佳方法是什么?
我当前的解决方案是使用给定的编码转换空宽字符,以确定下次调用 mbrtowc
时要跳过的输入字节数。但可能有更优雅的方法来做到这一点。
此外,我想知道 mbrtowc
这种行为背后的基本原理是什么。
一个字节。无论移位状态如何,空字节始终表示空字符,并且不能作为多字节字符的一部分参与。来源是:
5.2.1.2 Multibyte characters
...
- A byte with all bits zero shall be interpreted as a null character independent of shift state. Such a byte shall not occur as part of any other multibyte character.
根据 C99 规范 mbrtowc
函数 returns 0
if the next n or fewer bytes complete the multibyte character that corresponds to the null wide character (which is the value stored).
在编码的空字符之后立即继续读取输入的最佳方法是什么?
我当前的解决方案是使用给定的编码转换空宽字符,以确定下次调用 mbrtowc
时要跳过的输入字节数。但可能有更优雅的方法来做到这一点。
此外,我想知道 mbrtowc
这种行为背后的基本原理是什么。
一个字节。无论移位状态如何,空字节始终表示空字符,并且不能作为多字节字符的一部分参与。来源是:
5.2.1.2 Multibyte characters
...
- A byte with all bits zero shall be interpreted as a null character independent of shift state. Such a byte shall not occur as part of any other multibyte character.