Skip to content

parsers: correct Unicode and culture-aware string matching - #31

Merged
rameel merged 1 commit into
mainfrom
parsers/string-comparison-semantics
Sep 27, 2026
Merged

rameel merged 1 commit into
mainfrom
parsers/string-comparison-semantics

Conversation

@rameel

@rameel rameel commented Sep 27, 2026 •

Copy link
Copy Markdown
Owner

OneOf could miss Unicode case equivalents because its first-character lookup only included the literal's upper/lower forms:

OneOf(["Σx", "zz"], StringComparison.OrdinalIgnoreCase)
    .Parse("ςx").Success; // false before, true after

OrdinalIgnoreCase now normalizes lookup keys for both literals and input. Culture-aware comparisons check candidates without filtering by the first character.

L and OneOf also:

  • Use CompareInfo.IsPrefix to consume the actual matched source length, which can differ from the literal length.
  • Capture the current culture when created and retain it for matching, ordering, and deduplication.

This changes L's previous behavior: changing the current culture no longer affects an existing parser.

Normalize OrdinalIgnoreCase bucket keys for both literals and input so
OneOf recognizes equivalent characters beyond simple upper/lower pairs.

Match culture-aware candidates without first-character bucketing and
consume the source length returned by CompareInfo.IsPrefix rather than
the literal length.
@rameel
rameel merged commit 1003f27 into main Sep 27, 2026
2 checks passed
@rameel
rameel deleted the parsers/string-comparison-semantics branch September 27, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant