API proposal: compare chars or Runes for equality under an OrdinalIgnoreCase comparer #32268
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Runtime
backlog-cleanup-candidate
An inactive issue that has been marked for automated closure.
no-recent-activity
Full context at #32247. But the tl;dr is that going forward, it's likely that
string.Equals(a, b, StringComparison.OrdinalIgnoreCase)
will no longer be exactly equivalent tostring.Equals(a.ToUpperInvariant(), b.ToUpperInvariant(), StringComparison.Ordinal)
.This implies that to ask whether two
char
(orRune
) instances are equal under a case-insensitive comparison, it's no longer sufficient to queryif (char.ToUpperInvariant(charA) == char.ToUpperInvariant(charB)) { /* ... */ }
. We need to introduce a separate API for code paths which need to check individualchar
(Rune
) instances for case-insensitive equality.API proposal
Behavior
If ordinalIgnoreCase = false, it's a straight bitwise equality comparison.
If ordinalIgnoreCase = true, we internally calculate the two "caseless"
char
(Rune
) values in the same manner as #32247, and then we compare those caseless values for bitwise equality. This means that it would be possible to write your own implementation ofstring.Equals(a, b, StringComparison.OrdinalIgnoreCase)
on top of these char-by-char APIs./cc @tarekgh
The text was updated successfully, but these errors were encountered: