为什么大写字母不足以进行不区分大小写的比较?

Why is upper casing not enough for case-insensitive comparison?

要不区分大小写地比较两个字符串,一种正确的方法是区分大小写 先折叠它们。这比上壳或下壳好在哪里?

我找到了小写字母无法在线正常工作的例子。为了 例如“σ”和“ς”(“Σ”的两种形式)在以下情况下不会变得相同 转换为小写。但我没找到为什么折叠是 比映射到大写更好。有没有两个字符串的情况 应该不区分大小写地匹配,不要大写相同 字符串?

另一种情况是我想存储不区分大小写的索引。这 推荐的方式似乎是折叠大小写然后归一化。什么是 它比存储映射到大写的字符串的优点和 归一化?规范说不能保证映射到大写 跨版本的 Unicode 稳定,而大小写折叠是。但是有没有 映射到大写字母的任何情况都会在 早期版本的 Unicode?

根据 Unicode stability policy,大小写映射仅对大小写对稳定,即字符对 XY 其中XY的完整大写映射,Y是[=22的完整小写映射=]X。只有当这两个字符都具有这些属性时,它们之间的大小写关系才是固定的。

但是,Unicode 包含许多“不完整”的大小写对,其中仅对小写形式进行了编码,而大写形式则完全缺失。对于传统上仅使用小写字母的转录系统中使用的字母,通常就是这种情况。如果大写形式被发现并随后添加到 Unicode,这些字母将收到一个新的大写映射。

发生这种情况的最新字符是“ʂ”(来自 Unicode 1.1)、“ᶎ”(来自 Unicode 4.1)和“ꞔ”(来自 Unicode 7.0),它们都有全新的大写形式( Ꞔ, Ʂ, Ᶎ) 两年前的 Unicode 12.0.

因为大小写映射不必是唯一的,这使得大写不能很好地替代正确的大小写折叠。例如,U+0434 (д) 和 U+1C81 (ᲁ) 都大写到 U+0414 (Д),但只有前者由于是 U+0414 的完整小写映射而被锁定在大小写对中。如果有人在某个旧手稿中找到U+1C81的专用大写字母版本,就会给它一个新的大写映射,导致U+0434和U+1C81在那个操作下突然不再比较相等。

编辑: 我刚刚想起一个大写字母不足以进行不区分大小写匹配的当前示例:U+1E9E (ẞ) 已经是大写字母,因此大写字母本身。它的小写对应是 U+00DF (ß),但 U+00DF 的大写映射是序列 (S​​S).

uppercase("ẞ") ≠ uppercase(lowercase("ẞ"))

我从 here 中找到了一个列表。

从 Unicode 13.0.0 开始。

具有超过 1 个大写映射的等价物 类。

case fold original UPPER CASE
k 006B LATIN SMALL LETTER K K 004B LATIN CAPITAL LETTER K K 004B LATIN CAPITAL LETTER K
k 006B LATIN SMALL LETTER K K 004B LATIN CAPITAL LETTER K
K 212A KELVIN SIGN K 212A KELVIN SIGN
ss 0073 LATIN SMALL LETTER S; 0073 LATIN SMALL LETTER S ß 00DF LATIN SMALL LETTER SHARP S SS 0053 LATIN CAPITAL LETTER S; 0053 LATIN CAPITAL LETTER S
ẞ 1E9E LATIN CAPITAL LETTER SHARP S ẞ 1E9E LATIN CAPITAL LETTER SHARP S
å 00E5 LATIN SMALL LETTER A WITH RING ABOVE Å 00C5 LATIN CAPITAL LETTER A WITH RING ABOVE Å 00C5 LATIN CAPITAL LETTER A WITH RING ABOVE
å 00E5 LATIN SMALL LETTER A WITH RING ABOVE Å 00C5 LATIN CAPITAL LETTER A WITH RING ABOVE
Å 212B ANGSTROM SIGN Å 212B ANGSTROM SIGN
θ 03B8 GREEK SMALL LETTER THETA Θ 0398 GREEK CAPITAL LETTER THETA Θ 0398 GREEK CAPITAL LETTER THETA
θ 03B8 GREEK SMALL LETTER THETA Θ 0398 GREEK CAPITAL LETTER THETA
ϑ 03D1 GREEK THETA SYMBOL Θ 0398 GREEK CAPITAL LETTER THETA
ϴ 03F4 GREEK CAPITAL THETA SYMBOL ϴ 03F4 GREEK CAPITAL THETA SYMBOL
ω 03C9 GREEK SMALL LETTER OMEGA Ω 03A9 GREEK CAPITAL LETTER OMEGA Ω 03A9 GREEK CAPITAL LETTER OMEGA
ω 03C9 GREEK SMALL LETTER OMEGA Ω 03A9 GREEK CAPITAL LETTER OMEGA
Ω 2126 OHM SIGN Ω 2126 OHM SIGN

并用于小写。

case fold original lower case
s 0073 LATIN SMALL LETTER S S 0053 LATIN CAPITAL LETTER S s 0073 LATIN SMALL LETTER S
s 0073 LATIN SMALL LETTER S s 0073 LATIN SMALL LETTER S
ſ 017F LATIN SMALL LETTER LONG S ſ 017F LATIN SMALL LETTER LONG S
st 0073 LATIN SMALL LETTER S; 0074 LATIN SMALL LETTER T ſt FB05 LATIN SMALL LIGATURE LONG S T ſt FB05 LATIN SMALL LIGATURE LONG S T
st FB06 LATIN SMALL LIGATURE ST st FB06 LATIN SMALL LIGATURE ST
β 03B2 GREEK SMALL LETTER BETA Β 0392 GREEK CAPITAL LETTER BETA β 03B2 GREEK SMALL LETTER BETA
β 03B2 GREEK SMALL LETTER BETA β 03B2 GREEK SMALL LETTER BETA
ϐ 03D0 GREEK BETA SYMBOL ϐ 03D0 GREEK BETA SYMBOL
ε 03B5 GREEK SMALL LETTER EPSILON Ε 0395 GREEK CAPITAL LETTER EPSILON ε 03B5 GREEK SMALL LETTER EPSILON
ε 03B5 GREEK SMALL LETTER EPSILON ε 03B5 GREEK SMALL LETTER EPSILON
ϵ 03F5 GREEK LUNATE EPSILON SYMBOL ϵ 03F5 GREEK LUNATE EPSILON SYMBOL
θ 03B8 GREEK SMALL LETTER THETA Θ 0398 GREEK CAPITAL LETTER THETA θ 03B8 GREEK SMALL LETTER THETA
θ 03B8 GREEK SMALL LETTER THETA θ 03B8 GREEK SMALL LETTER THETA
ϑ 03D1 GREEK THETA SYMBOL ϑ 03D1 GREEK THETA SYMBOL
ϴ 03F4 GREEK CAPITAL THETA SYMBOL θ 03B8 GREEK SMALL LETTER THETA
ι 03B9 GREEK SMALL LETTER IOTA ◌ͅ 0345 COMBINING GREEK YPOGEGRAMMENI ◌ͅ 0345 COMBINING GREEK YPOGEGRAMMENI
Ι 0399 GREEK CAPITAL LETTER IOTA ι 03B9 GREEK SMALL LETTER IOTA
ι 03B9 GREEK SMALL LETTER IOTA ι 03B9 GREEK SMALL LETTER IOTA
ι 1FBE GREEK PROSGEGRAMMENI ι 1FBE GREEK PROSGEGRAMMENI
ΐ 03B9 GREEK SMALL LETTER IOTA; 0308 COMBINING DIAERESIS; 0301 COMBINING ACUTE ACCENT ΐ 0390 GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS ΐ 0390 GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS
ΐ 1FD3 GREEK SMALL LETTER IOTA WITH DIALYTIKA AND OXIA ΐ 1FD3 GREEK SMALL LETTER IOTA WITH DIALYTIKA AND OXIA
κ 03BA GREEK SMALL LETTER KAPPA Κ 039A GREEK CAPITAL LETTER KAPPA κ 03BA GREEK SMALL LETTER KAPPA
κ 03BA GREEK SMALL LETTER KAPPA κ 03BA GREEK SMALL LETTER KAPPA
ϰ 03F0 GREEK KAPPA SYMBOL ϰ 03F0 GREEK KAPPA SYMBOL
μ 03BC GREEK SMALL LETTER MU µ 00B5 MICRO SIGN µ 00B5 MICRO SIGN
Μ 039C GREEK CAPITAL LETTER MU μ 03BC GREEK SMALL LETTER MU
μ 03BC GREEK SMALL LETTER MU μ 03BC GREEK SMALL LETTER MU
π 03C0 GREEK SMALL LETTER PI Π 03A0 GREEK CAPITAL LETTER PI π 03C0 GREEK SMALL LETTER PI
π 03C0 GREEK SMALL LETTER PI π 03C0 GREEK SMALL LETTER PI
ϖ 03D6 GREEK PI SYMBOL ϖ 03D6 GREEK PI SYMBOL
ρ 03C1 GREEK SMALL LETTER RHO Ρ 03A1 GREEK CAPITAL LETTER RHO ρ 03C1 GREEK SMALL LETTER RHO
ρ 03C1 GREEK SMALL LETTER RHO ρ 03C1 GREEK SMALL LETTER RHO
ϱ 03F1 GREEK RHO SYMBOL ϱ 03F1 GREEK RHO SYMBOL
σ 03C3 GREEK SMALL LETTER SIGMA Σ 03A3 GREEK CAPITAL LETTER SIGMA σ 03C3 GREEK SMALL LETTER SIGMA
ς 03C2 GREEK SMALL LETTER FINAL SIGMA ς 03C2 GREEK SMALL LETTER FINAL SIGMA
σ 03C3 GREEK SMALL LETTER SIGMA σ 03C3 GREEK SMALL LETTER SIGMA
ΰ 03C5 GREEK SMALL LETTER UPSILON; 0308 COMBINING DIAERESIS; 0301 COMBINING ACUTE ACCENT ΰ 03B0 GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS ΰ 03B0 GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS
ΰ 1FE3 GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND OXIA ΰ 1FE3 GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND OXIA
φ 03C6 GREEK SMALL LETTER PHI Φ 03A6 GREEK CAPITAL LETTER PHI φ 03C6 GREEK SMALL LETTER PHI
φ 03C6 GREEK SMALL LETTER PHI φ 03C6 GREEK SMALL LETTER PHI
ϕ 03D5 GREEK PHI SYMBOL ϕ 03D5 GREEK PHI SYMBOL
в 0432 CYRILLIC SMALL LETTER VE В 0412 CYRILLIC CAPITAL LETTER VE в 0432 CYRILLIC SMALL LETTER VE
в 0432 CYRILLIC SMALL LETTER VE в 0432 CYRILLIC SMALL LETTER VE
ᲀ 1C80 CYRILLIC SMALL LETTER ROUNDED VE ᲀ 1C80 CYRILLIC SMALL LETTER ROUNDED VE
д 0434 CYRILLIC SMALL LETTER DE Д 0414 CYRILLIC CAPITAL LETTER DE д 0434 CYRILLIC SMALL LETTER DE
д 0434 CYRILLIC SMALL LETTER DE д 0434 CYRILLIC SMALL LETTER DE
ᲁ 1C81 CYRILLIC SMALL LETTER LONG-LEGGED DE ᲁ 1C81 CYRILLIC SMALL LETTER LONG-LEGGED DE
о 043E CYRILLIC SMALL LETTER O О 041E CYRILLIC CAPITAL LETTER O о 043E CYRILLIC SMALL LETTER O
о 043E CYRILLIC SMALL LETTER O о 043E CYRILLIC SMALL LETTER O
ᲂ 1C82 CYRILLIC SMALL LETTER NARROW O ᲂ 1C82 CYRILLIC SMALL LETTER NARROW O
с 0441 CYRILLIC SMALL LETTER ES С 0421 CYRILLIC CAPITAL LETTER ES с 0441 CYRILLIC SMALL LETTER ES
с 0441 CYRILLIC SMALL LETTER ES с 0441 CYRILLIC SMALL LETTER ES
ᲃ 1C83 CYRILLIC SMALL LETTER WIDE ES ᲃ 1C83 CYRILLIC SMALL LETTER WIDE ES
т 0442 CYRILLIC SMALL LETTER TE Т 0422 CYRILLIC CAPITAL LETTER TE т 0442 CYRILLIC SMALL LETTER TE
т 0442 CYRILLIC SMALL LETTER TE т 0442 CYRILLIC SMALL LETTER TE
ᲄ 1C84 CYRILLIC SMALL LETTER TALL TE ᲄ 1C84 CYRILLIC SMALL LETTER TALL TE
ᲅ 1C85 CYRILLIC SMALL LETTER THREE-LEGGED TE ᲅ 1C85 CYRILLIC SMALL LETTER THREE-LEGGED TE
ъ 044A CYRILLIC SMALL LETTER HARD SIGN Ъ 042A CYRILLIC CAPITAL LETTER HARD SIGN ъ 044A CYRILLIC SMALL LETTER HARD SIGN
ъ 044A CYRILLIC SMALL LETTER HARD SIGN ъ 044A CYRILLIC SMALL LETTER HARD SIGN
ᲆ 1C86 CYRILLIC SMALL LETTER TALL HARD SIGN ᲆ 1C86 CYRILLIC SMALL LETTER TALL HARD SIGN
ѣ 0463 CYRILLIC SMALL LETTER YAT Ѣ 0462 CYRILLIC CAPITAL LETTER YAT ѣ 0463 CYRILLIC SMALL LETTER YAT
ѣ 0463 CYRILLIC SMALL LETTER YAT ѣ 0463 CYRILLIC SMALL LETTER YAT
ᲇ 1C87 CYRILLIC SMALL LETTER TALL YAT ᲇ 1C87 CYRILLIC SMALL LETTER TALL YAT
ṡ 1E61 LATIN SMALL LETTER S WITH DOT ABOVE Ṡ 1E60 LATIN CAPITAL LETTER S WITH DOT ABOVE ṡ 1E61 LATIN SMALL LETTER S WITH DOT ABOVE
ṡ 1E61 LATIN SMALL LETTER S WITH DOT ABOVE ṡ 1E61 LATIN SMALL LETTER S WITH DOT ABOVE
ẛ 1E9B LATIN SMALL LETTER LONG S WITH DOT ABOVE ẛ 1E9B LATIN SMALL LETTER LONG S WITH DOT ABOVE
ꙋ A64B CYRILLIC SMALL LETTER MONOGRAPH UK ᲈ 1C88 CYRILLIC SMALL LETTER UNBLENDED UK ᲈ 1C88 CYRILLIC SMALL LETTER UNBLENDED UK
Ꙋ A64A CYRILLIC CAPITAL LETTER MONOGRAPH UK ꙋ A64B CYRILLIC SMALL LETTER MONOGRAPH UK
ꙋ A64B CYRILLIC SMALL LETTER MONOGRAPH UK ꙋ A64B CYRILLIC SMALL LETTER MONOGRAPH UK

小写(大写(X))。

case fold original lower case of upper case
ss 0073 LATIN SMALL LETTER S; 0073 LATIN SMALL LETTER S ß 00DF LATIN SMALL LETTER SHARP S ss 0073 LATIN SMALL LETTER S; 0073 LATIN SMALL LETTER S
ẞ 1E9E LATIN CAPITAL LETTER SHARP S ß 00DF LATIN SMALL LETTER SHARP S

对于大写(小写),没有等价组有多个结果。