* parser.cs (ResolveReferences): Handle some cases of explicitly-named numeric groups.
[mono.git] / mcs / class / System / System.Text.RegularExpressions / parser.cs
index 3991d8244f699a3906620e225af229614c5daeee..f6df03d17632574cc0bd6e47b7d9b0858e35e19a 100644 (file)
@@ -1081,15 +1081,31 @@ namespace System.Text.RegularExpressions.Syntax {
                        foreach (CapturingGroup group in caps) {
                                if (group.Name == null)
                                        continue;
+
                                if (dict.Contains (group.Name)) {
                                        CapturingGroup prev = (CapturingGroup) dict [group.Name];
                                        group.Number = prev.Number;
                                        continue;
                                }
+
+                               if (Char.IsDigit (group.Name [0])) {
+                                       int ptr = 0;
+                                       int group_gid = ParseDecimal (group.Name, ref ptr);
+                                       if (ptr == group.Name.Length) {
+                                               // FIXME: Handle non-contiguous groups
+                                               group.Number = group_gid;
+                                               dict.Add (group.Name, group);
+                                               ++ num_groups;
+                                               continue;
+                                       }
+                               }
+
                                string gid_s = gid.ToString ();
+                               while (dict.Contains (gid_s))
+                                       gid_s = (++gid).ToString ();
+
+                               dict.Add (gid_s, group);
                                dict.Add (group.Name, group);
-                               if (!dict.Contains (gid_s))
-                                       dict.Add (gid_s, group);
                                group.Number = gid ++;
                                ++ num_groups;
                        }