Author: raja
Date: 2007-01-02 12:52:33 -0500 (Tue, 02 Jan 2007)
New Revision: 70374
Modified:
trunk/mcs/class/System/System.Text.RegularExpressions/ChangeLog
trunk/mcs/class/System/System.Text.RegularExpressions/parser.cs
trunk/mcs/class/System/Test/System.Text.RegularExpressions/ChangeLog
trunk/mcs/class/System/Test/System.Text.RegularExpressions/RegexBugs.cs
Log:
In System.Text.RegularExpressions:
Fix #79472
* parser.cs (Parser.GetMapping): Use the actual group numbers to
build the mapping.
In Test/System.Text.RegularExpressions:
* RegexBugs.cs (GroupNumbers): New test based on #79472.
Modified: trunk/mcs/class/System/System.Text.RegularExpressions/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.Text.RegularExpressions/ChangeLog
2007-01-02 17:45:09 UTC (rev 70373)
+++ trunk/mcs/class/System/System.Text.RegularExpressions/ChangeLog
2007-01-02 17:52:33 UTC (rev 70374)
@@ -1,3 +1,9 @@
+2007-01-02 Raja R Harinath <[EMAIL PROTECTED]>
+
+ Fix #79472
+ * parser.cs (Parser.GetMapping): Use the actual group numbers to
+ build the mapping.
+
2006-09-28 Andrew Skiba <[EMAIL PROTECTED]>
* Regex.cs: TARGET_JVM
Modified: trunk/mcs/class/System/System.Text.RegularExpressions/parser.cs
===================================================================
--- trunk/mcs/class/System/System.Text.RegularExpressions/parser.cs
2007-01-02 17:45:09 UTC (rev 70373)
+++ trunk/mcs/class/System/System.Text.RegularExpressions/parser.cs
2007-01-02 17:52:33 UTC (rev 70374)
@@ -149,24 +149,25 @@
}
}
- public IDictionary GetMapping () {
+ public IDictionary GetMapping ()
+ {
Hashtable mapping = new Hashtable ();
- Hashtable numbers = new Hashtable ();
int end = caps.Count;
mapping.Add ("0", 0);
for (int i = 0; i < end; i++) {
CapturingGroup group = (CapturingGroup) caps
[i];
- if (group.Name != null && !mapping.Contains
(group.Name)) {
+ if (group.Name != null) {
+ if (mapping.Contains (group.Name)) {
+ if ((int) mapping [group.Name]
!= group.Number)
+ throw new
SystemException ("invalid state");
+ continue;
+ }
mapping.Add (group.Name, group.Number);
- numbers.Add (group.Number,
group.Number);
+ } else {
+ mapping.Add (group.Number.ToString (),
group.Number);
}
}
- for (int i = 1; i < end; i++) {
- if (numbers [i] == null)
- mapping.Add (i.ToString (), i);
- }
-
return mapping;
}
Modified: trunk/mcs/class/System/Test/System.Text.RegularExpressions/ChangeLog
===================================================================
--- trunk/mcs/class/System/Test/System.Text.RegularExpressions/ChangeLog
2007-01-02 17:45:09 UTC (rev 70373)
+++ trunk/mcs/class/System/Test/System.Text.RegularExpressions/ChangeLog
2007-01-02 17:52:33 UTC (rev 70374)
@@ -1,3 +1,7 @@
+2007-01-02 Raja R Harinath <[EMAIL PROTECTED]>
+
+ * RegexBugs.cs (GroupNumbers): New test based on #79472.
+
2006-05-08 Raja R Harinath <[EMAIL PROTECTED]>
* RegexBugs.cs (Kill65535_1, Kill65535_2, No65535Limit): New tests
Modified:
trunk/mcs/class/System/Test/System.Text.RegularExpressions/RegexBugs.cs
===================================================================
--- trunk/mcs/class/System/Test/System.Text.RegularExpressions/RegexBugs.cs
2007-01-02 17:45:09 UTC (rev 70373)
+++ trunk/mcs/class/System/Test/System.Text.RegularExpressions/RegexBugs.cs
2007-01-02 17:52:33 UTC (rev 70374)
@@ -418,6 +418,33 @@
Kill65535_2 (65531);
Kill65535_2 (131066);
Kill65535_2 (131067);
- }
+ }
+
+ void GroupNumbers_1 (string s, int n)
+ {
+ Regex r = new Regex (s);
+ int [] grps = r.GetGroupNumbers ();
+ AssertEquals (r+" #01", n, grps.Length);
+
+ int sum = 0;
+ for (int i = 0; i < grps.Length; ++i) {
+ sum += grps [i];
+ // group numbers are unique
+ for (int j = 0; j < i; ++j)
+ Assert (r+" #02 ("+i+","+j+")", grps
[i] != grps [j]);
+ }
+ // no gaps in group numbering
+ AssertEquals (r+" #03", (n*(n-1))/2, sum);
+ }
+
+ [Test]
+ public void GroupNumbers ()
+ {
+ GroupNumbers_1 ("a", 1);
+ GroupNumbers_1 ("(a)", 2);
+ GroupNumbers_1 ("(a)(b)", 3);
+ GroupNumbers_1 ("(a)|(b)", 3);
+ GroupNumbers_1 ("((a)(b))(c)", 5);
+ }
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches