Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API proposal: compare chars or Runes for equality under an OrdinalIgnoreCase comparer #32268

Closed
GrabYourPitchforks opened this issue Feb 13, 2020 · 4 comments
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

Comments

@GrabYourPitchforks
Copy link
Member

GrabYourPitchforks commented Feb 13, 2020

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 to string.Equals(a.ToUpperInvariant(), b.ToUpperInvariant(), StringComparison.Ordinal).

This implies that to ask whether two char (or Rune) instances are equal under a case-insensitive comparison, it's no longer sufficient to query if (char.ToUpperInvariant(charA) == char.ToUpperInvariant(charB)) { /* ... */ }. We need to introduce a separate API for code paths which need to check individual char (Rune) instances for case-insensitive equality.

API proposal

namespace System
{
    struct char
    {
        public static bool Equals(char a, char b, bool ordinalIgnoreCase = false);
    }
}

namespace System.Text
{
    struct Rune
    {
        public static bool Equals(Rune a, Rune b, bool ordinalIgnoreCase = false);
    }
}

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 of string.Equals(a, b, StringComparison.OrdinalIgnoreCase) on top of these char-by-char APIs.

/cc @tarekgh

@GrabYourPitchforks GrabYourPitchforks added api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime labels Feb 13, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Feb 13, 2020
@tarekgh
Copy link
Member

tarekgh commented Feb 14, 2020

The proposal looks good to me. I suggest changing ignoreCase to ordinalIgnoreCase to indicate we'll not use cultural casing.

@GrabYourPitchforks
Copy link
Member Author

Sure, no problem. I suppose if we don't want to pollute the char and Rune API surface areas we could shove these as static methods on TextInfo. Just a thought - I don't feel a great pull either way.

@joperezr joperezr removed the untriaged New issue has not been triaged by the area owner label Jul 7, 2020
@joperezr joperezr added this to the Future milestone Jul 7, 2020
Copy link
Contributor

Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

This process is part of our issue cleanup automation.

@dotnet-policy-service dotnet-policy-service bot added backlog-cleanup-candidate An inactive issue that has been marked for automated closure. no-recent-activity labels Jan 6, 2025
Copy link
Contributor

This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

@dotnet-policy-service dotnet-policy-service bot removed this from the Future milestone Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

4 participants