2006-01-24 Chris Toshok <toshok@ximian.com>
[mono.git] / mcs / class / corlib / System.Globalization / CompareInfo.cs
index b2a395b5c1d090a2da921b1612c18922cd612e19..3f589ca124d78c0598ecfccd80604783bc5af9c0 100644 (file)
@@ -42,11 +42,11 @@ namespace System.Globalization
        public class CompareInfo : IDeserializationCallback
        {
                static readonly bool useManagedCollation =
-                       Environment.GetEnvironmentVariable ("MONO_USE_MANAGED_COLLATION")
-                       == "yes";
+                       Environment.internalGetEnvironmentVariable ("MONO_DISABLE_MANAGED_COLLATION")
+                       != "yes" && MSCompatUnicodeTable.IsReady;
 
-               public static bool UseManagedCollation {
-                       get { return useManagedCollation && MSCompatUnicodeTable.IsReady; }
+               internal static bool UseManagedCollation {
+                       get { return useManagedCollation; }
                }
 
                // Keep in synch with MonoCompareInfo in the runtime. 
@@ -56,6 +56,9 @@ namespace System.Globalization
                [NonSerialized]
                private IntPtr ICU_collator;
                private int win32LCID;  // Unused, but MS.NET serializes this
+#if NET_2_0
+               private string m_name; // Unused, but MS.NET serializes this
+#endif
 
                [NonSerialized]
                SimpleCollator collator;
@@ -360,6 +363,13 @@ namespace System.Globalization
                public virtual SortKey GetSortKey(string source,
                                                  CompareOptions options)
                {
+#if NET_2_0
+                       switch (options) {
+                       case CompareOptions.Ordinal:
+                       case CompareOptions.OrdinalIgnoreCase:
+                               throw new ArgumentException ("Now allowed CompareOptions.", "options");
+                       }
+#endif
                        if (UseManagedCollation)
                                return collator.GetSortKey (source, options);
                        SortKey key=new SortKey (culture, source, options);
@@ -464,8 +474,11 @@ namespace System.Globalization
                        int count, char c, CompareOptions opt,
                        bool first)
                {
-                       return UseManagedCollation &&
-                               (CompareOptions.Ordinal & opt) == 0 ?
+                       // - forward IndexOf() icall is much faster than
+                       //   manged version, so always use icall. However,
+                       //   it does not work for OrdinalIgnoreCase, so
+                       //   do not avoid managed collator for that option.
+                       return UseManagedCollation && ! (first && opt == CompareOptions.Ordinal) ?
                                internal_index_managed (s, sindex, count, c, opt, first) :
                                internal_index (s, sindex, count, c, opt, first);
                }
@@ -526,8 +539,11 @@ namespace System.Globalization
                        int count, string s2, CompareOptions opt,
                        bool first)
                {
-                       return UseManagedCollation &&
-                               (CompareOptions.Ordinal & opt) == 0 ?
+                       // - forward IndexOf() icall is much faster than
+                       //   manged version, so always use icall. However,
+                       //   it does not work for OrdinalIgnoreCase, so
+                       //   do not avoid managed collator for that option.
+                       return UseManagedCollation && ! (first && opt == CompareOptions.Ordinal) ?
                                internal_index_managed (s1, sindex, count, s2, opt, first) :
                                internal_index (s1, sindex, count, s2, opt, first);
                }
@@ -751,6 +767,18 @@ namespace System.Globalization
                                               value, options, false));
                }
 
+#if NET_2_0
+               public static bool IsSortable (char c)
+               {
+                       return MSCompatUnicodeTable.IsSortable (c);
+               }
+
+               public static bool IsSortable (string s)
+               {
+                       return MSCompatUnicodeTable.IsSortable (s);
+               }
+#endif
+
                public override string ToString()
                {
                        return("CompareInfo - "+culture);