正则表达式 – 具有不对称大小写的Unicode字符.为什么?

为什么以下三个字符不对称toLower,toUpper结果
/**
  * Written in the Scala programming language,typed into the Scala REPL.
  * Results commented accordingly.
  */
/* Unicode Character 'LATIN CAPITAL LETTER SHARP S' (U+1E9E) */
'\u1e9e'.toHexString == "1e9e" // true
'\u1e9e'.toLower.toHexString == "df" // "df" == "df"
'\u1e9e'.toHexString == '\u1e9e'.toLower.toUpper.toHexString // "1e9e" != "df"
/* Unicode Character 'KELVIN SIGN' (U+212A) */
'\u212a'.toHexString == "212a" // "212a" == "212a"
'\u212a'.toLower.toHexString == "6b" // "6b" == "6b"
'\u212a'.toHexString == '\u212a'.toLower.toUpper.toHexString // "212a" != "4b"
/* Unicode Character 'LATIN CAPITAL LETTER I WITH DOT ABOVE' (U+0130) */
'\u0130'.toHexString == "130" // "130" == "130"
'\u0130'.toLower.toHexString == "69" // "69" == "69"
'\u0130'.toHexString == '\u0130'.toLower.toUpper.toHexString // "130" != "49"
对于第一个,有 this explanation

In the German language,the Sharp S (“ß” or U+00df) is a lowercase letter,and it capitalizes to the letters “SS”.

换句话说,U 1E9E小写为U 00DF,但大写U 00DF不是U 1E9E.

对于第二个,U 212A(KELVIN SIGN)小写为U 0068(拉丁小写字母K). U 0068的大写字母是U 004B(LATIN CAPITAL LETTER K).这个似乎对我有意义.

对于第三种情况,U 0130(LATIN CAPITAL LETTER I WITH DOT ABOVE)是土耳其/阿塞拜疆人,小写为U 0069(拉丁小姐I).我想象,如果你在某个土耳其/阿塞拜疆地区不知何故,你会得到正确的大写版本的U 0069,但这可能不一定是普遍的.

字符不一定具有对称的大小写变换.

编辑:为了回应PhiLho在下面的评论,Unicode 6.0 spec有关于U 212A(KELVIN SIGN)的说法:

Three letterlike symbols have been given canonical equivalence to regular letters: U+2126
OHM SIGN,U+212A KELVIN SIGN,and U+212B ANGSTROM SIGN. In all three instances,the regular letter should be used. If text is normalized according to Unicode Standard Annex #15,“Unicode Normalization Forms,” these three characters will be replaced by their regular equivalents.

换句话说,你不应该真的使用U 212A,而应该使用U 004B(LATIN CAPITAL LETTER K),如果你规范化Unicode文本,U 212A应该被替换为U 004B.

相关文章

jquery.validate使用攻略(表单校验) 目录 jquery.validate...
/\s+/g和/\s/g的区别 正则表达式/\s+/g...
自整理几个jquery.Validate验证正则: 1. 只能输入数字和字母...
this.optional(element)的用法 this.optional(element)是jqu...
jQuery.validate 表单动态验证 实际上jQuery.validate提供了...
自定义验证之这能输入数字(包括小数 负数 ) <script ...