Explorar el Código

2004-02-01 Miguel de Icaza <[email protected]>

	* syntax.cs, interval.cs: Applied patch from Marco Cravairo
	through Francois Beauchemin who reviewed on the mailing list.
	This fixes bug #45976

svn path=/trunk/mcs/; revision=22684
Miguel de Icaza hace 22 años
padre
commit
fc5d02f8bc

+ 6 - 0
mcs/class/System/System.Text.RegularExpressions/ChangeLog

@@ -1,3 +1,9 @@
+2004-02-01  Miguel de Icaza  <[email protected]>
+
+	* syntax.cs, interval.cs: Applied patch from Marco Cravairo
+	through Francois Beauchemin who reviewed on the mailing list.
+	This fixes bug #45976
+
 2004-01-16  Gonzalo Paniagua Javier <[email protected]>
 
 	* parser.cs: an opening brace without a

+ 8 - 0
mcs/class/System/System.Text.RegularExpressions/interval.cs

@@ -95,6 +95,14 @@ namespace System.Text.RegularExpressions {
 			return low <= i && i <= high;
 		}
 
+		public bool Intersects (Interval i) {
+ 			if (IsEmpty || i.IsEmpty)
+ 				return false;
+ 			
+ 			return ((Contains (i.low) && !Contains (i.high)) ||
+				(Contains (i.high) && !Contains (i.low)));
+ 		}	
+
 		public void Merge (Interval i) {
 			if (i.IsEmpty)
 				return;

+ 32 - 2
mcs/class/System/System.Text.RegularExpressions/syntax.cs

@@ -779,11 +779,39 @@ namespace System.Text.RegularExpressions.Syntax {
 		}
 
 		public void AddCharacter (char c) {
-			intervals.Add (new Interval (c, c));
+			// TODO: this is certainly not the most efficient way of doing things 
+ 			// TODO: but at least it produces correct results. 
+ 			AddRange (c, c);
 		}
 
 		public void AddRange (char lo, char hi) {
-			intervals.Add (new Interval (lo, hi));
+			Interval new_interval = new Interval (lo, hi);
+ 
+ 			// ignore case is on. we must make sure our interval does not
+ 			// use upper case. if it does, we must normalize the upper case
+ 			// characters into lower case. 
+ 			if (ignore) {
+ 				if (upper_case_characters.Intersects (new_interval)) {
+ 					Interval partial_new_interval;
+ 
+ 					if (new_interval.low < upper_case_characters.low) {
+ 						partial_new_interval = new Interval (upper_case_characters.low + distance_between_upper_and_lower_case, 
+ 										     new_interval.high +  distance_between_upper_and_lower_case);
+ 						new_interval.high = upper_case_characters.low - 1;
+ 					}
+ 					else {
+ 						partial_new_interval = new Interval (new_interval.low + distance_between_upper_and_lower_case, 
+ 										     upper_case_characters.high + distance_between_upper_and_lower_case);
+ 						new_interval.low = upper_case_characters.high + 1;
+ 					}
+ 					intervals.Add (partial_new_interval);
+ 				}
+ 				else if (upper_case_characters.Contains (new_interval)) {
+ 					new_interval.high += distance_between_upper_and_lower_case;
+ 					new_interval.low += distance_between_upper_and_lower_case;
+ 				}
+ 			}
+ 			intervals.Add (new_interval);
 		}
 
 		public override void Compile (ICompiler cmp, bool reverse) {
@@ -871,6 +899,8 @@ namespace System.Text.RegularExpressions.Syntax {
 				return 3;					// Range
 		}
 
+		private static Interval upper_case_characters = new Interval ((char)65, (char)90);
+ 		private const int distance_between_upper_and_lower_case = 32;
 		private bool negate, ignore;
 		private bool[] pos_cats, neg_cats;
 		private IntervalCollection intervals;