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
// Specifies the culture, case, and sort rules to be used by certain overloads of// the System.String.Compare(System.String,System.String) and System.String.Equals(System.Object)// methods.publicenumStringComparison{// Compare strings using culture-sensitive sort rules and the current culture.CurrentCulture=0,// Compare strings using culture-sensitive sort rules, the current culture, and// ignoring the case of the strings being compared.CurrentCultureIgnoreCase=1,// Compare strings using culture-sensitive sort rules and the invariant culture.InvariantCulture=2,// Compare strings using culture-sensitive sort rules, the invariant culture, and// ignoring the case of the strings being compared.InvariantCultureIgnoreCase=3,// Compare strings using ordinal (binary) sort rules.Ordinal=4,// Compare strings using ordinal (binary) sort rules and ignoring the case of the// strings being compared.OrdinalIgnoreCase=5}
We could implement string.Compare(otherString, StringComparison), but let me know if you agree. The string.Equal() method can then just translate to Compare() == 0.
If we want to expose all of these options, then we will need to get a bit clever in some of the other languages. Particularly around InvariantCulture, which appears to be an artificial / unchanging culture designed by Microsoft to not be country / current locale specific. We could drop support for Invariant completely, or we could fall back to CurrentCulture implementation on languages which do not support it.
C
I'm not too sure about this one, but I think the following should work:
CurrentCulture: utf8_collate
CurrentCultureIgnoreCase: utf8_casefold followed by strcoll
Ordinal: strcmp
OrdinalIgnoreCase: utf8_casefold followed by strcmp
InvariantCulture / InvariantCultureIgnoreCase: no equivalent unless we use the win32 functions.
C++ Win32
Ordinal / OrdinalIgnoreCase: CompareStringOrdinal
InvariantCulture / InvariantCultureIgnoreCase / CurrentCulture / CurrentCultureIgnoreCase can all be done with CompareStringEx
I think that starting with .NET's StringComparison is way too ambitious. I would start with just string.EqualsIgnoreCase (not the ordering comparisons) and list what the target languages provide and only then decide what to implement. Does "culture" affect that? I understand different human languages have different alphabets, with possibly overlapping letters, but does equality depend on the culture?
Before I get started on this, I wanted your thoughts on the API.
There are many ways to compare strings. Some .net best practice guide is here: https://learn.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings?redirectedfrom=MSDN
The C# enum is:
We could implement
string.Compare(otherString, StringComparison)
, but let me know if you agree. Thestring.Equal()
method can then just translate toCompare() == 0
.If we want to expose all of these options, then we will need to get a bit clever in some of the other languages. Particularly around InvariantCulture, which appears to be an artificial / unchanging culture designed by Microsoft to not be country / current locale specific. We could drop support for Invariant completely, or we could fall back to CurrentCulture implementation on languages which do not support it.
C
I'm not too sure about this one, but I think the following should work:
utf8_collate
utf8_casefold
followed bystrcoll
utf8_casefold
followed bystrcmp
C++ Win32
C++ ICU
JS / TS
s1.localeCompare(s2, undefined, { sensitivity: "variant" })
s1. localeCompare(s2, undefined, { sensitivity: "base" })
s1 < s2
s1.toUpperCase() < s2.toUpperCase()
Java
D
Python
Swift
OpenCL
Ignore / not supported
The text was updated successfully, but these errors were encountered: