具有不对称大小写的 Unicode 字符。为什么?

发布于 2024-12-06 04:08:31 字数 926 浏览 1 评论 0原文

为什么以下三个字符的 toLowertoUpper 结果不对称

/**
  * 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"

Why do the following three characters have not symmetric toLower, toUpper results

/**
  * 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"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

﹏半生如梦愿梦如真 2024-12-13 04:08:31

对于第一个,有这个解释

在德语中,Sharp S(“ß”或 U+00df)是一个小写字母,它大写为字母“SS”。

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

对于第二个,U+212A(开尔文符号)小写为 U+0068(拉丁文小写字母 K)。 U+0068 的大写字母是 U+004B(拉丁文大写字母 K)。这对我来说似乎是有道理的。

对于第三种情况,U+0130(上面带点的拉丁文大写字母 I)是土耳其/阿塞拜疆字符,小写为 U+0069(拉丁文小写字母 I)。我想,如果您在土耳其/阿塞拜疆语言环境中,您会得到 U+0069 的正确大写版本,但这不一定是通用的。

字符不一定需要具有对称的大小写转换。

编辑:为了回应下面 PhiLho 的评论,Unicode 6.0 规范对 U+212A (KELVIN SIGN) 有这样的规定:

三个类似字母的符号已被赋予与常规字母等效的规范:U+2126
欧姆符号、U+212A 开尔文符号和 U+212B 安斯特罗姆符号。在所有三种情况下,都应使用常规字母。如果根据 Unicode 标准附件 #15“Unicode 规范化形式”对文本进行规范化,则这三个字符将被其常规等效字符替换。

换句话说,您不应该真正使用 U+212A,而应该使用 U+004B(拉丁文大写字母 K),如果您规范化 Unicode 文本,则 U+212A 应替换为 U+004B。

For the first one, there is this explanation:

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

In other words, U+1E9E lower-cases to U+00DF, but the upper-case of U+00DF is not U+1E9E.

For the second one, U+212A (KELVIN SIGN) lower-cases to U+0068 (LATIN SMALL LETTER K). The upper-case of U+0068 is U+004B (LATIN CAPITAL LETTER K). This one seems to make sense to me.

For the third case, U+0130 (LATIN CAPITAL LETTER I WITH DOT ABOVE) is a Turkish/Azerbaijani character that lower-cases to U+0069 (LATIN SMALL LETTER I). I would imagine that if you were somehow in a Turkish/Azerbaijani locale you'd get the proper upper-case version of U+0069, but that might not necessarily be universal.

Characters need not necessarily have symmetric upper- and lower-case transformations.

Edit: To respond to PhiLho's comment below, the Unicode 6.0 spec has this to say about 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.

In other words, you shouldn't really be using U+212A, you should be using U+004B (LATIN CAPITAL LETTER K) instead, and if you normalize your Unicode text, U+212A should be replaced with U+004B.

空气里的味道 2024-12-13 04:08:31

我可以参考另一篇关于 Unicode 和大小写的帖子吗?
认为某种语言的符号必须有大写和小写是一个常见的错误!

Java 中的 Unicode 正确标题大小写

May I refer to another post about Unicode and upper and lower case..
It is a common mistake to think that signs for a language have to be available in upper and lower case!

Unicode-correct title case in Java

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文