[Mono-dev] [PATCH] Case-insensitive comparison in HybridDictionary
Konstantin Triger
kostat at mainsoft.com
Sun Nov 25 07:16:35 EST 2007
Please review the patch for default case insensitive comparison in HybridDictionary. (Should be ordinal and not invariant).
Index: Test/System.Collections.Specialized/HybridDictionaryTest.cs
===================================================================
--- Test/System.Collections.Specialized/HybridDictionaryTest.cs (revision 90126)
+++ Test/System.Collections.Specialized/HybridDictionaryTest.cs (working copy)
@@ -94,5 +94,20 @@
// ArgumentNullException under all fx versions
Assert.IsFalse (hd.Contains (null), "Contains(null)");
}
+
+#if NET_2_0
+ [Test]
+ public void Comparer ()
+ {
+ string separated = "\u0061\u030a";
+ string combined = "\u00e5";
+
+ HybridDictionary hd = new HybridDictionary (true);
+ hd.Add (separated, "val1");
+ hd.Add (combined, "val2");
+
+ Assert.AreEqual (2, hd.Count, "Count");
+ }
+#endif
}
}
Index: System.Collections.Specialized/HybridDictionary.cs
===================================================================
--- System.Collections.Specialized/HybridDictionary.cs (revision 90126)
+++ System.Collections.Specialized/HybridDictionary.cs (working copy)
@@ -55,14 +55,21 @@
public HybridDictionary (int initialSize, bool caseInsensitive)
{
this.caseInsensitive = caseInsensitive;
-
+#if NET_2_0
+ StringComparer comparer = caseInsensitive ? StringComparer.OrdinalIgnoreCase : null;
+#else
IComparer comparer = caseInsensitive ? CaseInsensitiveComparer.DefaultInvariant : null;
IHashCodeProvider hcp = caseInsensitive ? CaseInsensitiveHashCodeProvider.DefaultInvariant : null;
+#endif
if (initialSize <= switchAfter)
list = new ListDictionary (comparer);
else
+#if NET_2_0
+ hashtable = new Hashtable (initialSize, comparer);
+#else
hashtable = new Hashtable (initialSize, hcp, comparer);
+#endif
}
// Properties
@@ -155,10 +162,15 @@
private void Switch ()
{
+#if NET_2_0
+ StringComparer comparer = caseInsensitive ? StringComparer.OrdinalIgnoreCase : null;
+ hashtable = new Hashtable (list, comparer);
+#else
IComparer comparer = caseInsensitive ? CaseInsensitiveComparer.DefaultInvariant : null;
IHashCodeProvider hcp = caseInsensitive ? CaseInsensitiveHashCodeProvider.DefaultInvariant : null;
hashtable = new Hashtable (list, hcp, comparer);
+#endif
list.Clear ();
list = null;
}
Regards,
Konstantin Triger
More information about the Mono-devel-list
mailing list