2005-08-02 Rafael Teixeira <rafaelteixeirabr@hotmail.com>
authorRafael Teixeira <monoman@gmail.com>
Tue, 2 Aug 2005 19:52:03 +0000 (19:52 -0000)
committerRafael Teixeira <monoman@gmail.com>
Tue, 2 Aug 2005 19:52:03 +0000 (19:52 -0000)
* Strigns.cs: Correcting InStrRev function
- parameter name in message for first exception
- use LastIndexOf (FIXME pending managed collation(corlib) working)

svn path=/trunk/mcs/; revision=47932

mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic/ChangeLog
mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic/Strings.cs

index 1b9d9dbd993ede5b6dd5bd6831677924d3ddc266..cb941ce568363dfbfc8f8a70c3f86f60c7683878 100644 (file)
@@ -1,3 +1,8 @@
+2005-08-02  Rafael Teixeira <rafaelteixeirabr@hotmail.com>
+       * Strigns.cs: Correcting InStrRev function
+               - parameter name in message for first exception
+               - use LastIndexOf (FIXME pending managed collation(corlib) working)
+               
 2005-06-10  Atsushi Enomoto  <atsushi@ximian.com>
 
        * Collection.cs : csc build fix.
index 73be728e6f47844a846318abdc69d819949c0fe8..0a5f3d4e06b3310b4912fab953fe28c754f26e14 100644 (file)
@@ -638,7 +638,7 @@ namespace Microsoft.VisualBasic
                                           CompareMethod Compare)
                {
                        if ((Start == 0) || (Start < -1))
-                               throw new ArgumentException("Argument 'StringCheck' must be greater than 0 or equal to -1", "StringCheck");
+                               throw new ArgumentException("Argument 'Start' must be greater than 0 or equal to -1", "Start");
 
                        if (StringCheck == null)
                                return 0;
@@ -646,41 +646,20 @@ namespace Microsoft.VisualBasic
                        if (Start == -1)
                                Start = StringCheck.Length;
                                                                                
-                       if (Start > StringCheck.Length || StringCheck.Length == 0)
-                               return 0;
-                                                                                                                                                 
                        if (StringMatch == null || StringMatch.Length == 0)
                                return Start;
 
-                       int retindex = -1;
-                       int index = -1;
-                       while (index == 0){
-                               switch (Compare)
-                               {
-                               case CompareMethod.Text:
-                                       index = System.Globalization.CultureInfo.CurrentCulture.CompareInfo.IndexOf(
-                                                                                                                   StringCheck.ToLower(System.Globalization.CultureInfo.CurrentCulture), 
-                                                                                                                   StringMatch.ToLower(System.Globalization.CultureInfo.CurrentCulture), 
-                                                                                                                   Start - 1) + 1;
-                                       break;
-                               case CompareMethod.Binary:
-                                       index = StringCheck.IndexOf(StringMatch, Start - 1) + 1;
-                                       break;
-                               default:
-                                       throw new System.ArgumentException("Argument 'Compare' must be CompareMethod.Binary or CompareMethod.Text.", "Compare");
-                               }
-                               if (index == 0){
-                                       if (retindex == -1)
-                                               return index;
-                                       else
-                                               return retindex;
-                               }
-                               else {
-                                       retindex = index;
-                                       Start = index;
-                               }
+                       if (Start > StringCheck.Length || StringCheck.Length == 0)
+                               return 0;                                                                                                                                                 
+
+                       if (Compare == CompareMethod.Text) {
+                               // FIXME: this wastes memory and time, remove when CompareInfo.LastIndexOf works correctly 
+                               StringCheck = StringCheck.ToLower();
+                               StringMatch = StringMatch.ToLower();
+                               // FIXME: depends on Managed Collation being ready to be able to use with CompareOptions.IgnoreCase
+                               // return CultureInfo.CurrentCulture.CompareInfo.LastIndexOf(StringCheck, StringMatch, Start - 1, CompareOptions.IgnoreCase) + 1; 
                        }
-                       return retindex;
+                       return StringCheck.LastIndexOf(StringMatch, Start - 1) + 1;
                }
 
                public static string Join(string[] SourceArray,