* parser.cs (ResolveReferences): Handle some cases of explicitly-named numeric groups.
authorRaja R Harinath <harinath@hurrynot.org>
Mon, 17 Aug 2009 19:26:18 +0000 (19:26 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Mon, 17 Aug 2009 19:26:18 +0000 (19:26 -0000)
svn path=/trunk/mcs/; revision=140096

mcs/class/System/System.Text.RegularExpressions/ChangeLog
mcs/class/System/System.Text.RegularExpressions/parser.cs
mcs/class/System/Test/System.Text.RegularExpressions/ChangeLog
mcs/class/System/Test/System.Text.RegularExpressions/RegexMatchTests.cs

index 0a83b301b6c2221775d2a7b83ca6078c8db0da30..71b61ddeb704b7d39149a647b3cebf44567b7a71 100644 (file)
@@ -1,3 +1,8 @@
+2009-08-17  Raja R Harinath  <harinath@hurrynot.org>
+
+       * parser.cs (ResolveReferences): Handle some cases of
+       explicitly-named numeric groups.
+
 2009-08-17  Raja R Harinath  <harinath@hurrynot.org>
 
        * parser.cs (ResolveReferences): Rearrange slightly to prepare for
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;
                        }
index 90f7b32ca444ba0abe15450f13d6faca606f6bf2..fa2e8ec119bb0dff6b304bd26be1f5f35c85aa0c 100644 (file)
@@ -1,3 +1,7 @@
+2009-08-17  Raja R Harinath  <harinath@hurrynot.org>
+
+       * RegexMatchTests.cs (RegexTrial0061): New.
+
 2009-08-17  Raja R Harinath  <harinath@hurrynot.org>
 
        * RegexTrial.cs (Execute): Prepare to handle dis-contiguous group numbers.
index e9aeb72b61b244762165c6b639270da9afd8da48..cb725965a9e052a814d913f19d111ec7ae03f163 100644 (file)
@@ -157,6 +157,7 @@ namespace MonoTests.System.Text.RegularExpressions
                        new RegexTrial (@"\4400", RegexOptions.ECMAScript, "asdf 012", "Fail."),//58
                        new RegexTrial (@"\4400", RegexOptions.None, "asdf$0012", "Fail."),//59
                        new RegexTrial (@"\4400", RegexOptions.ECMAScript, "asdf$0012", "Pass. Group[0]=(4,3)"),//60
+                       new RegexTrial (@"(?<2>ab)(?<c>c)(?<d>d)", RegexOptions.None, "abcd", "Pass. Group[0]=(0,4) Group[1]=(2,1) Group[2]=(0,2) Group[3]=(3,1)"),// 61
                };
 
                [Test]
@@ -336,5 +337,6 @@ namespace MonoTests.System.Text.RegularExpressions
                [Test]  public void RegexTrial0058 () { trials [58].Execute (); }
                [Test]  public void RegexTrial0059 () { trials [59].Execute (); }
                [Test]  public void RegexTrial0060 () { trials [60].Execute (); }
+               [Test]  public void RegexTrial0061 () { trials [61].Execute (); }
        }
 }