Bugzilla – Bug 316666
String.Compare("HIJ", "hij", false) gives wrong result
Last modified: 2007-09-15 21:24:46 UTC
---- Reported by bmaurer@users.sf.net 2004-12-11 19:04:22 MST ---- [benm@omega benm]$ cat t.cs using System; class X { static void Main () { Console.WriteLine (String.Compare("HIJ", "hij", false)); } } [benm@omega benm]$ mcs t.cs [benm@omega benm]$ mono t.exe -1 On MSFT: C:\Inetpub\ftproot>t 1 C:\Inetpub\ftproot> ---- Additional Comments From mdevine@cs.stanford.edu 2005-05-12 22:18:15 MST ---- I hunted this down through several layers of code, until I found string_invariant_compare_char in mono/mono/metadata/locales.c. Here's an excerpt: if (options & CompareOptions_IgnoreCase) { ... } else { /* * No options. Kana, symbol and spacing options don't * apply to the invariant culture. */ /* * FIXME: here we must use the information from c1type and c2type * to find out the proper collation, even on the InvariantCulture, the * sorting is not done by computing the unicode values, but their * actual sort order. */ result = (gint32) c1 - c2; } I believe that this FIXME is the source of this problem. I'm not sure about unicode, but in ANSI, lowercase letters are numerically lower than uppercase. In this code then, if we are not ignoring case while comparing, we simply subtract the bit patterns. ---- Additional Comments From atsushi@ximian.com 2005-05-12 23:30:23 MST ---- Anyways I am going to "fix" those collation bugs by replacing icu with another implementation. ---- Additional Comments From atsushi@ximian.com 2005-09-27 07:03:28 MST ---- Now managed collation is default, so this is fixed in svn. Unknown operating system unknown. Setting to default OS "Other".