Open caesay opened 9 months ago
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