-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
en_us.POSIX locale environment for .NET Core on Linux #25678
Comments
cc: @tarekgh |
@alexkeh The behavior of the string comparisons when using en-US-POSIX is unuseful and should be avoided if you are doing some linguistic string comparisons. 'c' is not equal to 'C' even when using case insensitive option with en-US-POSIX. That is how the collation rules defined for en-US-POSIX. In other words, en-US-POSIX is not using the expected Unicode collation. I would recommend changing the default locale other than en-US-POSIX to get the desired behavior. you can do that by setting the LC_ALL environment variable or in your code you can set CultureInfo.CurrentCulture. you may look at the thread https://marc.info/?l=icu&m=101779972120281&w=2 too regarding this behavior. |
We wrote .NET Core code to support different kinds of platforms (Windows, Linux and any platforms that .NET Standard2.0 supports). string.compare() is a very common functions and it should handle POSIX character sets properly if POSIX is supported in .NET Core. Our drivers have been verified on Windows with different character sets propery, as .NET Core supports this character sets with no problem. We also tested it on Linux with different character sets and it works, except POSIX. Question: Does Microsoft officially support POSIX in .NET Core? |
@mwoo-o The issue here is if .Net Core supporting POSIX. the issue here is what is the POSIX string comparison behavior. if you look at the link I sent before https://marc.info/?l=icu&m=101779972120281&w=2 you'll see
This makes the POSIX locale has special behavior for string comparison. in another word, en_US_POSIX behavior is really different than en_US behavior. the string comparison behavior is defined by LCDR (Unicode.org) here https://unicode.org/cldr/trac/browser/trunk/common/collation/en_US_POSIX.xml and this behavior is carried by ICU library which the framework depends on for performing the string comparison operations. so, the framework is not really defining the behavior here. You still can control the behavior here by setting the current culture to whatever locale you want or even Invariant if you like. |
We can't control the locale that are used by the customers. So that will mean that if we want to Questions: |
No
You can still set the current culture in your code. using CultureInfo.CurrentCulture
We discourage users to set their locale to POSIX because of the issues we talked about here. If the user decided to use POSIX locale, then that is their choice and they will get the behavior for that locale which may not be desired but that is what the user chose. |
@tarekgh |
The .Net framework chose to use the current culture for the default comparisons. You have the choice to perform the comparisons differently as you desired. Just pass the parameter StringComparison.OrdinalIgnoreCase or StringComparison.InvariantCultureIgnoreCase to the comparison APIs and you'll get what you want: https://msdn.microsoft.com/en-us/library/t4411bks(v=vs.110).aspx why you can't do that? |
@tarekgh In our code, we have a lot of |
You need to look at the places you are doing string comparison in your code and figure out if the comparison you are doing is one of the following cases:
You may look at the code sample https://docs.microsoft.com/en-us/dotnet/api/system.stringcomparison?view=netframework-4.7.1#examples to get some idea about what you expect from each comparison type. To summarize, you need to know what string comparison behavior you want and choose the right option according to that. If you have some example from your code, I can help you tell which option might be good in that case. |
@tarekgh |
Does .NET Core support Linux in en_us.POSIX locale environment?
Based on this commit, which adds a regression test for a bug fix and it invokes CultureInfo("en-US-POSIX"). However, my team has run into a fundamental problem running .NET Core tests in Linux with en_us.POSIX locale. We have no issue with the en_us.UTF8 locale. For example, string.Compare() does not work properly in case-sensitive comparison.
Thanks to @divega for providing some initial help on this question.
The text was updated successfully, but these errors were encountered: