摘记—Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Cha...

What a Unicode string ?

The binaries in RAM have the final word. NOT string literals in Text Editor(VS, Emacs), but the executable binary(in .str section) or binary data file(like cookie cache file in some sort of encoding) and loaded into variables / data structures like std::string.

string literal only tells the compiler to treat string literals as UTF-8 or UTF-16( L / _T() ), and thus come into .str section of a executable file image on disk .

 

code point : index to letters in code pages.

code pages :non-ASCII values (values greater than 127) represent international characters. These code pages are used natively in Windows Me, and are also available on Windows NT and later.


0-31 : ANSI unprintable

32 - 127:ANSI printable

ASCII table

128 + : OEM charsets -> (codified into ANSI)  : ANSI code pages ( IBM,M$)

在 Unicode 使用之前,通过DBCS来操纵编码 single/double byte 混合的char。Joel 称之为, messy system。 尤其突出的,是char分界的问题,比方,s++ and s--  和 Windows' AnsiNext and AnsiPrev 。


Unicode 通过fixed的2个byte。非常好地划定界限。

可是有例如以下的特点

(1)通过debate解决的:UTF-16的 non-ANSI 的 字符集合。 而且,因此导致UTF-16事实上并不仅是65536种可能字符。

(2)在UTF-16中,128下面的每一个char都会被扩展到2bytes,与原本的ANSI不兼容:须要改动之前的代码。

Windows API 在 NT 之后採用了UTF-16,因此,非常多API加上了A或者W的后缀。

(The "A" version handles text based on Windows code pages, while the "W" version handles Unicode text. )

对于英语国家的人来讲。事实上ANSI已经够用了。

(3) 2个byte自然有先后的问题,于是,须要加入BOM头来识别是little/big endian。


UTF-16 因为浪费空间的问题,被“冷遇”了几年,直到做出改进,得到UTF-8。

UTF-8是一个“变长”的编码系统。ANSI部分(0-127)是1byte的编码,这样,能够seamlessly和ANSI对接,而且不须要改动古老的代码。

之后,有2~6bytes不等的编码。但共同点是:没有一个byte是0x0。这一点,对于 old string-processing code that wants to use a single 0 byte as the null-terminator 就不会盲目截断strings了。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值