What is exactly an overlong form/encoding?

回眸只為那壹抹淺笑 提交于 2020-01-23 04:24:14

问题


Reading the Wikipedia article on UTF-8, I've been wondering about the term overlong. This term is used various times but the article doesn't provide a definition or reference for its meaning.

I would like to know if someone can explain the term and its purpose.


回答1:


It's an encoding of a code point which takes more code units than it needs to.

For example, U+0020 is represented in UTF-8 by the single byte 0x20. If you decode the two bytes 0xc0 0xa0 in the normal fashion, you'll still end up back at U+0020, but that's an invalid representation.

The Unicode Corrigendum #1 has more information, particularly around table 3.1B.




回答2:


UTF-8 theoretically allows for different representations of characters that also have a shorter one. For example, you could encode an ASCII character in two bytes by setting the MSBs to zero. The UTF-8 specification explicitly forbids this.



来源:https://stackoverflow.com/questions/7113117/what-is-exactly-an-overlong-form-encoding

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