You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Added support for hybrid globalization comparison.
* Clean-up. Added exception test cases to docs.
* Nit changes from @kg's review.
* Applied @kg's review.
* Revert unintentional change.
* Refactor: all hybrid globalization js methods in one file.
* Color the syntax.
* Undeline the fact that this PR is only for WASM.
* Move interop functions to proper location.
Copy file name to clipboardExpand all lines: docs/design/features/hybrid-globalization.md
+154Lines changed: 154 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,3 +18,157 @@ Affected public APIs:
18
18
- TextInfo.ToTitleCase.
19
19
20
20
Case change with invariant culture uses `toUpperCase` / `toLoweCase` functions that do not guarantee a full match with the original invariant culture.
21
+
22
+
**String comparison**
23
+
24
+
Affected public APIs:
25
+
- CompareInfo.Compare,
26
+
- String.Compare,
27
+
- String.Equals.
28
+
29
+
The number of `CompareOptions` and `StringComparison` combinations is limited. Originally supported combinations can be found [here for CompareOptions](https://learn.microsoft.com/dotnet/api/system.globalization.compareoptions) and [here for StringComparison](https://learn.microsoft.com/dotnet/api/system.stringcomparison).
30
+
31
+
-`IgnoreWidth` is not supported because there is no equivalent in Web API. Throws `PlatformNotSupportedException`.
32
+
```JS
33
+
let high =String.fromCharCode(65281) // %uff83 = テ
34
+
let low =String.fromCharCode(12486) // %u30c6 = テ
35
+
high.localeCompare(low, "ja-JP", { sensitivity:"case" }) // -1 ; case: a ≠ b, a = á, a ≠ A; expected: 0
36
+
37
+
let wide =String.fromCharCode(65345) // %uFF41 = a
38
+
let narrow ="a"
39
+
wide.localeCompare(narrow, "en-US", { sensitivity:"accent" }) // 0; accent: a ≠ b, a ≠ á, a = A; expected: -1
40
+
```
41
+
42
+
For comparison where "accent" sensitivity is used, ignoring some type of character widths is applied and cannot be switched off (see: point about `IgnoreCase`).
43
+
44
+
-`IgnoreKanaType`:
45
+
46
+
It is always switched on for comparison with locale "ja-JP", even if this comparison option was not set explicitly.
47
+
48
+
```JS
49
+
let hiragana =String.fromCharCode(12353) // %u3041 = ぁ
50
+
let katakana =String.fromCharCode(12449) // %u30A1 = ァ
51
+
let enCmp =hiragana.localeCompare(katakana, "en-US") // -1
52
+
let jaCmp =hiragana.localeCompare(katakana, "ja-JP") // 0
53
+
```
54
+
55
+
For locales different than "ja-JP" it cannot be used separately (no equivalent in Web API) - throws `PlatformNotSupportedException`.
56
+
57
+
-`None`:
58
+
59
+
No equivalent in Web API for "ja-JP" locale. See previous point about `IgnoreKanaType`. For "ja-JP" it throws `PlatformNotSupportedException`.
From this reason, comparison with locale `ja-JP``CompareOption``IgnoreCase` and `StringComparison`: `CurrentCultureIgnoreCase` and `InvariantCultureIgnoreCase` behave like a combination `IgnoreCase | IgnoreKanaType` (see: previous point about `IgnoreKanaType`). For other locales the behavior is unchanged with the following known exceptions:
`IgnoreNonSpace` cannot be used separately without `IgnoreKanaType`. Argument `sensitivity: "case"` is used for comparison and it ignores both types of characters. Option `IgnoreNonSpace` alone throws `PlatformNotSupportedException`.
104
+
105
+
```JS
106
+
let hiraganaAccent =`${String.fromCharCode(12353)} á`// %u3041 = ぁ
107
+
let katakanaNoAccent =`${String.fromCharCode(12449)} a`// %u30A1 = ァ
108
+
hiraganaAccent.localeCompare(katakanaNoAccent, "en-US", { sensitivity:"case" }) // 0; case: a ≠ b, a = á, a ≠ A
109
+
```
110
+
111
+
-`IgnoreNonSpace | IgnoreCase`
112
+
Combination of `IgnoreNonSpace` and `IgnoreCase` cannot be used without `IgnoreKanaType`. Argument `sensitivity: "base"` is used for comparison and it ignores three types of characters. Combination `IgnoreNonSpace | IgnoreCase` alone throws `PlatformNotSupportedException`.
113
+
114
+
```JS
115
+
let hiraganaBigAccent =`${String.fromCharCode(12353)} A á`// %u3041 = ぁ
116
+
let katakanaSmallNoAccent =`${String.fromCharCode(12449)} a a`// %u30A1 = ァ
117
+
hiraganaBigAccent.localeCompare(katakanaSmallNoAccent, "en-US", { sensitivity:"base" }) // 0; base: a ≠ b, a = á, a = A
118
+
```
119
+
120
+
-`IgnoreSymbols`
121
+
122
+
The subset of ignored symbols is limited to the symbols ignored by `string1.localeCompare(string2, locale, { ignorePunctuation: true })`. E.g. currency symbols, & are not ignored
123
+
124
+
```JS
125
+
let hiraganaAccent =`${String.fromCharCode(12353)} á`// %u3041 = ぁ
126
+
let katakanaNoAccent =`${String.fromCharCode(12449)} a`// %u30A1 = ァ
127
+
hiraganaBig.localeCompare(katakanaSmall, "en-US", { sensitivity:"base" }) // 0; base: a ≠ b, a = á, a = A
128
+
```
129
+
130
+
- List of all `CompareOptions` combinations always throwing `PlatformNotSupportedException`:
0 commit comments