C++ check if unicode character is full width

喜你入骨 提交于 2021-01-27 03:53:26

问题


How to check if a unicode character is full width?

I use Win32 / MFC

For example, is full width, A is not full width, is full width, F is not full width.


回答1:


What you need is to retrieve the East Asian Width of the character. You can do it by parsing the EastAsianWidth.txt file from the Unicode Character Database. I could not find a Win32 API that returns this info, but in Python, for example, you can use unicodedata.east_asian_width(unichr).

See the Annex #11 for the background of the problem and more information.




回答2:


What do you mean by "full width"? The width of a character depends on the font it is being displayed in.

If you mean whether it is a single byte character or not, it's still not clear. A single byte character in what encoding? In UTF-8, it will be a single byte character if (and only if) the code point is less than 128; if you're using UTF-16 (probable, since you're under Windows), just compare the character with 128. A single byte encoding in ISO 8859-1 (another wide spread encoding): compare with 256. For anything less than 256, the UTF-16 unit will be numerically identical to the code point in ISO 8859-1 (sometimes known as Latin-1). For the single byte encoding ASCII (almost never used today, but most of the common encodings are identical with it for the first 128 code points), anything less that 128 is good.



来源:https://stackoverflow.com/questions/20661434/c-check-if-unicode-character-is-full-width

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!