Merge pull request #495 from nicolas-raoul/fix-for-issue2907-with-no-formatting-changes
[mono.git] / mcs / tools / monodoc / Monodoc / provider.cs
index 9d33338ad8ea340692caca9eedf98ee5e3315410..180ae0d1f4eb2c6b158cba2780a5221680099aca 100644 (file)
@@ -24,7 +24,6 @@ using System.Collections;
 using System.Diagnostics;
 using System.Configuration;
 using System.Reflection;
-using System.Text.RegularExpressions;
 using System.Xml;
 using System.Xml.XPath;
 using ICSharpCode.SharpZipLib.Zip;
@@ -395,13 +394,24 @@ public class Node : IComparable {
                if (other.position < 0)
                        other.LoadNode ();
 
-               Regex digits = new Regex (@"([\d]+)|([^\d]+)");
-               MatchEvaluator eval = delegate (Match m) {
-                       return (m.Value.Length > 0 && char.IsDigit (m.Value [0])) 
-                               ? m.Value.PadLeft (System.Math.Max (caption.Length, other.caption.Length)) 
-                               : m.Value;
-               };
-               return digits.Replace (caption, eval).CompareTo (digits.Replace (other.caption, eval));
+               var cap1 = caption;
+               var cap2 = other.caption;
+
+               /* Some node (notably from ecmaspec) have number prepended to them
+                * which we need to sort better by padding them to the same number
+                * of digits
+                */
+               if (char.IsDigit (cap1[0]) && char.IsDigit (cap2[0])) {
+                       int c1 = cap1.TakeWhile (char.IsDigit).Count ();
+                       int c2 = cap2.TakeWhile (char.IsDigit).Count ();
+
+                       if (c1 != c2) {
+                               cap1 = cap1.PadLeft (cap1.Length + Math.Max (0, c2 - c1), '0');
+                               cap2 = cap2.PadLeft (cap2.Length + Math.Max (0, c1 - c2), '0');
+                       }
+               }
+
+               return string.Compare (cap1, cap2, StringComparison.OrdinalIgnoreCase);
        }
 }