Commit 61cdb40
authored
[generator] Fix reserved keywords binary search (#977)
Context: 7068f4b
Context: https://docs.microsoft.com/en-us/dotnet/core/extensions/performing-culture-insensitive-string-operations-in-arrays
Commit 7068f4b enabled string code analyzers, because in e.g. the
`sr` locale, `"Ljava".StartsWith("L")` would be *false*, because `Lj`
was a language-specific digraph, and "special-cased". For intended
behavior, we need to use `.StartsWith("L", StringComparison.Ordinal)`.
There is a ["similar yet different" problem][0] with `Array.Sort()`
and `Array.BinarySearch()` and string arrays: a locale-specific
comparison is performed by default:
var reserved_keywords = new [] {
"as", "catch", "char", "checked", "class", "const",
};
var index = Array.BinarySearch (reserved_keywords, "checked");
The *expectation* is that `index` is 3. In the `cs-CZ` locale, "ch"
is a digraph, and `index` is -7, i.e. was not found.
There is currently no Code Analysis check for this scenario.
Review all `Array.Sort()` and `Array.BinarySearch()` invocations so
that an appropriate `IComparer` instance is provided. This allows
e.g. `checked` to be properly `@escaped` when created a binding in a
machine with a `cs-CZ` locale.
[0]: https://docs.microsoft.com/en-us/dotnet/core/extensions/performing-culture-insensitive-string-operations-in-arrays1 parent 2a882d2 commit 61cdb40
File tree
4 files changed
+31
-5
lines changed- tests/generator-Tests/Unit-Tests
- tools/generator
- Utilities
4 files changed
+31
-5
lines changedLines changed: 14 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
82 | 95 | | |
83 | 96 | | |
Lines changed: 14 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
22 | 35 | | |
23 | 36 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
270 | | - | |
| 270 | + | |
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
84 | | - | |
| 83 | + | |
| 84 | + | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| |||
0 commit comments