ソースを参照

In System.Text.RegularExpressions:
* Capture.cs, Group.cs, Match.cs: New files split out of ...
* match.cs: ... this. Remove.

In .:
* System.dll.sources: Update to reflect split-up of
System.Text.RegularExpressions/match.cs.

svn path=/trunk/mcs/; revision=44793

Raja R Harinath 20 年 前
コミット
0db5645ea7

+ 5 - 0
mcs/class/System/ChangeLog

@@ -1,3 +1,8 @@
+2005-05-20  Raja R Harinath  <[email protected]>
+
+	* System.dll.sources: Update to reflect split-up of
+	System.Text.RegularExpressions/match.cs.
+
 2005-05-19  Sebastien Pouliot  <[email protected]>
 
 	* Makefile: Do not report Obsolete warnings when compiling unit tests.

+ 76 - 0
mcs/class/System/System.Text.RegularExpressions/Capture.cs

@@ -0,0 +1,76 @@
+//
+// assembly:	System
+// namespace:	System.Text.RegularExpressions
+// file:	Capture.cs
+//
+// author:	Dan Lewis ([email protected])
+// 		(c) 2002
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace System.Text.RegularExpressions {
+
+	[Serializable]
+	public class Capture {
+		public int Index {
+			get { return index; }
+		}
+
+		public int Length {
+			get { return length; }
+		}
+
+		public string Value {
+			get { 
+				if (text!= null)
+					return text.Substring (index, length); 
+				else
+					return String.Empty;
+			}
+		}
+
+		public override string ToString () {
+			return Value;
+		}
+
+		// internal members
+
+		internal Capture (string text) : this (text, 0, 0) { }
+
+		internal Capture (string text, int index, int length) {
+			this.text = text;
+			this.index = index;
+			this.length = length;
+		}
+		
+		internal string Text {
+			get { return text; }
+		}
+
+		// private
+
+		internal int index, length;
+		internal string text;
+	}
+}

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

@@ -1,3 +1,8 @@
+2005-05-20  Raja R Harinath  <[email protected]>
+
+	* Capture.cs, Group.cs, Match.cs: New files split out of ...
+	* match.cs: ... this.  Remove.
+
 2005-02-27 Gonzalo Paniagua Javier <[email protected]>
 
 	* parser.cs: stuff inside {} might not be a quantifier. Fixes

+ 75 - 0
mcs/class/System/System.Text.RegularExpressions/Group.cs

@@ -0,0 +1,75 @@
+//
+// assembly:	System
+// namespace:	System.Text.RegularExpressions
+// file:	Group.cs
+//
+// author:	Dan Lewis ([email protected])
+// 		(c) 2002
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace System.Text.RegularExpressions {
+
+	[Serializable]
+	public class Group : Capture {
+		public static Group Synchronized (Group inner) {
+			return inner;	// is this enough?
+		}
+
+		public CaptureCollection Captures {
+			get { return captures; }
+		}
+
+		public bool Success {
+			get { return success; }
+		}
+
+		// internal
+
+		internal Group (string text, int[] caps) : base (text) {
+			this.captures = new CaptureCollection ();
+
+			if (caps == null || caps.Length == 0) {
+				this.success = false;
+				return;
+			}
+
+			this.success = true;
+			this.index = caps[0];
+			this.length = caps[1];
+			captures.Add (this);
+			for (int i = 2; i < caps.Length; i += 2)
+				captures.Add (new Capture (text, caps[i], caps[i + 1]));
+			captures.Reverse ();
+		}
+		
+		internal Group (): base ("")
+		{
+			captures = new CaptureCollection ();
+		}
+
+		private bool success;
+		private CaptureCollection captures;
+	}
+}

+ 82 - 167
mcs/class/System/System.Text.RegularExpressions/match.cs → mcs/class/System/System.Text.RegularExpressions/Match.cs

@@ -1,10 +1,10 @@
-//
-// assembly:	System
-// namespace:	System.Text.RegularExpressions
-// file:	match.cs
-//
-// author:	Dan Lewis ([email protected])
-// 		(c) 2002
+//
+// assembly:	System
+// namespace:	System.Text.RegularExpressions
+// file:	Match.cs
+//
+// author:	Dan Lewis ([email protected])
+// 		(c) 2002
 
 //
 // Permission is hereby granted, free of charge, to any person obtaining
@@ -26,163 +26,78 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-
-using System;
-
-namespace System.Text.RegularExpressions {
-
-	[Serializable]
-	public class Capture {
-		public int Index {
-			get { return index; }
-		}
-
-		public int Length {
-			get { return length; }
-		}
-
-		public string Value {
-			get { 
-				if (text!= null)
-					return text.Substring (index, length); 
-				else
-					return String.Empty;
-			}
-		}
-
-		public override string ToString () {
-			return Value;
-		}
-
-		// internal members
-
-		internal Capture (string text) : this (text, 0, 0) { }
-
-		internal Capture (string text, int index, int length) {
-			this.text = text;
-			this.index = index;
-			this.length = length;
-		}
-		
-		internal string Text {
-			get { return text; }
-		}
-
-		// private
-
-		internal int index, length;
-		internal string text;
-	}
-
-	[Serializable]
-	public class Group : Capture {
-		public static Group Synchronized (Group inner) {
-			return inner;	// is this enough?
-		}
-
-		public CaptureCollection Captures {
-			get { return captures; }
-		}
-
-		public bool Success {
-			get { return success; }
-		}
-
-		// internal
-
-		internal Group (string text, int[] caps) : base (text) {
-			this.captures = new CaptureCollection ();
-
-			if (caps == null || caps.Length == 0) {
-				this.success = false;
-				return;
-			}
-
-			this.success = true;
-			this.index = caps[0];
-			this.length = caps[1];
-			captures.Add (this);
-			for (int i = 2; i < caps.Length; i += 2)
-				captures.Add (new Capture (text, caps[i], caps[i + 1]));
-			captures.Reverse ();
-		}
-		
-		internal Group (): base ("")
-		{
-			captures = new CaptureCollection ();
-		}
-
-		private bool success;
-		private CaptureCollection captures;
-	}
-
-	[Serializable]
-	public class Match : Group {
-		public static Match Empty {
-			get { return empty; }
-		}
-		
-		public static Match Synchronized (Match inner) {
-			return inner;	// FIXME need to sync on machine access
-		}
-		
-		public virtual GroupCollection Groups {
-			get { return groups; }
-		}
-
-		public Match NextMatch () {
-			if (this == Empty)
-				return Empty;
-
-			int scan_ptr = regex.RightToLeft ? Index : Index + Length;
-
-			// next match after an empty match: make sure scan ptr makes progress
-			
-			if (Length == 0)
-				scan_ptr += regex.RightToLeft ? -1 : +1;
-
-			return machine.Scan (regex, Text, scan_ptr, text_length);
-		}
-
-		public virtual string Result (string replacement) {
-			return ReplacementEvaluator.Evaluate (replacement, this);
-		}
-
-		// internal
-
-		internal Match () : base (null, null) {
-			this.regex = null;
-			this.machine = null;
-			this.text_length = 0;
-			this.groups = new GroupCollection ();
-
-			groups.Add (this);
-		}
-		
-		internal Match (Regex regex, IMachine machine, string text, int text_length, int[][] grps) :
-			base (text, grps[0])
-		{
-			this.regex = regex;
-			this.machine = machine;
-			this.text_length = text_length;
-
-			this.groups = new GroupCollection ();
-			groups.Add (this);
-			for (int i = 1; i < grps.Length; ++ i)
-				groups.Add (new Group (text, grps[i]));
-		}
-
-		internal Regex Regex {
-			get { return regex; }
-		}
-
-		// private
-
-		private Regex regex;
-		private IMachine machine;
-		private int text_length;
-		private GroupCollection groups;
-
-		private static Match empty = new Match ();
-	}
-}
+
+using System;
+
+namespace System.Text.RegularExpressions {
+
+	[Serializable]
+	public class Match : Group {
+		public static Match Empty {
+			get { return empty; }
+		}
+		
+		public static Match Synchronized (Match inner) {
+			return inner;	// FIXME need to sync on machine access
+		}
+		
+		public virtual GroupCollection Groups {
+			get { return groups; }
+		}
+
+		public Match NextMatch () {
+			if (this == Empty)
+				return Empty;
+
+			int scan_ptr = regex.RightToLeft ? Index : Index + Length;
+
+			// next match after an empty match: make sure scan ptr makes progress
+			
+			if (Length == 0)
+				scan_ptr += regex.RightToLeft ? -1 : +1;
+
+			return machine.Scan (regex, Text, scan_ptr, text_length);
+		}
+
+		public virtual string Result (string replacement) {
+			return ReplacementEvaluator.Evaluate (replacement, this);
+		}
+
+		// internal
+
+		internal Match () : base (null, null) {
+			this.regex = null;
+			this.machine = null;
+			this.text_length = 0;
+			this.groups = new GroupCollection ();
+
+			groups.Add (this);
+		}
+		
+		internal Match (Regex regex, IMachine machine, string text, int text_length, int[][] grps) :
+			base (text, grps[0])
+		{
+			this.regex = regex;
+			this.machine = machine;
+			this.text_length = text_length;
+
+			this.groups = new GroupCollection ();
+			groups.Add (this);
+			for (int i = 1; i < grps.Length; ++ i)
+				groups.Add (new Group (text, grps[i]));
+		}
+
+		internal Regex Regex {
+			get { return regex; }
+		}
+
+		// private
+
+		private Regex regex;
+		private IMachine machine;
+		private int text_length;
+		private GroupCollection groups;
+
+		private static Match empty = new Match ();
+	}
+}

+ 179 - 179
mcs/class/System/System.Text.RegularExpressions/replace.cs

@@ -1,10 +1,10 @@
-//
-// assembly:	System
-// namespace:	System.Text.RegularExpressions
-// file:	replace.cs
-//
-// author:	Dan Lewis ([email protected])
-// 		(c) 2002
+//
+// assembly:	System
+// namespace:	System.Text.RegularExpressions
+// file:	replace.cs
+//
+// author:	Dan Lewis ([email protected])
+// 		(c) 2002
 
 //
 // Permission is hereby granted, free of charge, to any person obtaining
@@ -26,175 +26,175 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-
-using System;
-using System.Text;
-using System.Collections;
-
-using Parser = System.Text.RegularExpressions.Syntax.Parser;
-
-namespace System.Text.RegularExpressions {
-
-	class ReplacementEvaluator {
-		public static string Evaluate (string replacement, Match match) {
-			ReplacementEvaluator ev = new ReplacementEvaluator (match.Regex, replacement);
-			return ev.Evaluate (match);
-		}
-
-		public ReplacementEvaluator (Regex regex, string replacement) {
-			this.regex = regex;
-			terms = new ArrayList ();
-			Compile (replacement);
-		}
-
-		public string Evaluate (Match match) {
-			StringBuilder result = new StringBuilder ();
-			foreach (Term term in terms)
-				result.Append (term.GetResult (match));
-
-			return result.ToString ();
-		}
-
-		// private
-
-		private void Compile (string replacement) {
-			replacement = Parser.Unescape (replacement);
-			StringBuilder literal = new StringBuilder ();
-
-			int ptr = 0;
-			char c;
-			Term term = null;
-			while (ptr < replacement.Length) {
-				c = replacement[ptr ++];
-
-				if (c == '$') {
-					if (replacement[ptr] != '$') 
-						term = CompileTerm (replacement, ref ptr);
-					else
-						++ ptr;
-				}
-
-				if (term != null) {
-					term.Literal = literal.ToString ();
-					terms.Add (term);
-
-					term = null;
-					literal.Length = 0;
-				}
-				else
-					literal.Append (c);
-			}
-
-			if (term == null && literal.Length > 0) {
-				terms.Add (new Term (literal.ToString ()));
-			}
-		}
-
-		private Term CompileTerm (string str, ref int ptr) {
-			char c = str[ptr];
-
-			if (Char.IsDigit (c)) {		// numbered group
-				int n = Parser.ParseDecimal (str, ref ptr);
-				if (n < 0 || n > regex.GroupCount)
-					throw new ArgumentException ("Bad group number.");
-				
-				return new Term (TermOp.Match, n);
-			}
-			
-			++ ptr;
-
-			switch (c) {
-			case '{': {			// named group
-				string name = Parser.ParseName (str, ref ptr);
-				if (str[ptr ++] != '}' || name == null)
-					throw new ArgumentException ("Bad group name.");
-				
-				int n = regex.GroupNumberFromName (name);
-				
-				if (n < 0)
-					throw new ArgumentException ("Bad group name.");
-
-				return new Term (TermOp.Match, n);
-			}
-
-			case '&':			// entire match
-				return new Term (TermOp.Match, 0);
-
-			case '`':			// text before match
-				return new Term (TermOp.PreMatch, 0);
-
-			case '\'':			// text after match
-				return new Term (TermOp.PostMatch, 0);
-
-			case '+':			// last group
-				return new Term (TermOp.Match, regex.GroupCount - 1);
-
-			case '_':			// entire text
-				return new Term (TermOp.All, 0);
-
-			default:
-				throw new ArgumentException ("Bad replacement pattern.");
-			}
-		}
-
-		private Regex regex;
-		private ArrayList terms;
-
-		private enum TermOp {
-			None,				// no action
-			Match,				// input within group
-			PreMatch,			// input before group
-			PostMatch,			// input after group
-			All				// entire input
-		}
-
-		private class Term {
-			public Term (TermOp op, int arg) {
-				this.op = op;
-				this.arg = arg;
-				this.literal = "";
-			}
-
-			public Term (string literal) {
-				this.op = TermOp.None;
-				this.arg = 0;
-				this.literal = literal;
-			}
-
-			public string Literal {
-				set { literal = value; }
-			}
-
-			public string GetResult (Match match) {
-				Group group = match.Groups[arg];
-			
-				switch (op) {
-				case TermOp.None:
-					return literal;
-
-				case TermOp.Match:
-					return literal + group.Value;
-
-				case TermOp.PreMatch:
-					return literal + group.Text.Substring (0, group.Index);
-
-				case TermOp.PostMatch:
-					return literal + group.Text.Substring (group.Index + group.Length);
-
-				case TermOp.All:
-					return literal + group.Text;
-				}
-
-				return "";
-			}
-		
-			public TermOp op;		// term type
-			public int arg;			// group argument
-			public string literal;		// literal to prepend
-
-			public override string ToString () {
-				return op.ToString () + "(" + arg + ") " + literal;
-			}
-		}
-	}
-}
+
+using System;
+using System.Text;
+using System.Collections;
+
+using Parser = System.Text.RegularExpressions.Syntax.Parser;
+
+namespace System.Text.RegularExpressions {
+
+	class ReplacementEvaluator {
+		public static string Evaluate (string replacement, Match match) {
+			ReplacementEvaluator ev = new ReplacementEvaluator (match.Regex, replacement);
+			return ev.Evaluate (match);
+		}
+
+		public ReplacementEvaluator (Regex regex, string replacement) {
+			this.regex = regex;
+			terms = new ArrayList ();
+			Compile (replacement);
+		}
+
+		public string Evaluate (Match match) {
+			StringBuilder result = new StringBuilder ();
+			foreach (Term term in terms)
+				result.Append (term.GetResult (match));
+
+			return result.ToString ();
+		}
+
+		// private
+
+		private void Compile (string replacement) {
+			replacement = Parser.Unescape (replacement);
+			StringBuilder literal = new StringBuilder ();
+
+			int ptr = 0;
+			char c;
+			Term term = null;
+			while (ptr < replacement.Length) {
+				c = replacement[ptr ++];
+
+				if (c == '$') {
+					if (replacement[ptr] != '$') 
+						term = CompileTerm (replacement, ref ptr);
+					else
+						++ ptr;
+				}
+
+				if (term != null) {
+					term.Literal = literal.ToString ();
+					terms.Add (term);
+
+					term = null;
+					literal.Length = 0;
+				}
+				else
+					literal.Append (c);
+			}
+
+			if (term == null && literal.Length > 0) {
+				terms.Add (new Term (literal.ToString ()));
+			}
+		}
+
+		private Term CompileTerm (string str, ref int ptr) {
+			char c = str[ptr];
+
+			if (Char.IsDigit (c)) {		// numbered group
+				int n = Parser.ParseDecimal (str, ref ptr);
+				if (n < 0 || n > regex.GroupCount)
+					throw new ArgumentException ("Bad group number.");
+				
+				return new Term (TermOp.Match, n);
+			}
+			
+			++ ptr;
+
+			switch (c) {
+			case '{': {			// named group
+				string name = Parser.ParseName (str, ref ptr);
+				if (str[ptr ++] != '}' || name == null)
+					throw new ArgumentException ("Bad group name.");
+				
+				int n = regex.GroupNumberFromName (name);
+				
+				if (n < 0)
+					throw new ArgumentException ("Bad group name.");
+
+				return new Term (TermOp.Match, n);
+			}
+
+			case '&':			// entire match
+				return new Term (TermOp.Match, 0);
+
+			case '`':			// text before match
+				return new Term (TermOp.PreMatch, 0);
+
+			case '\'':			// text after match
+				return new Term (TermOp.PostMatch, 0);
+
+			case '+':			// last group
+				return new Term (TermOp.Match, regex.GroupCount - 1);
+
+			case '_':			// entire text
+				return new Term (TermOp.All, 0);
+
+			default:
+				throw new ArgumentException ("Bad replacement pattern.");
+			}
+		}
+
+		private Regex regex;
+		private ArrayList terms;
+
+		private enum TermOp {
+			None,				// no action
+			Match,				// input within group
+			PreMatch,			// input before group
+			PostMatch,			// input after group
+			All				// entire input
+		}
+
+		private class Term {
+			public Term (TermOp op, int arg) {
+				this.op = op;
+				this.arg = arg;
+				this.literal = "";
+			}
+
+			public Term (string literal) {
+				this.op = TermOp.None;
+				this.arg = 0;
+				this.literal = literal;
+			}
+
+			public string Literal {
+				set { literal = value; }
+			}
+
+			public string GetResult (Match match) {
+				Group group = match.Groups[arg];
+			
+				switch (op) {
+				case TermOp.None:
+					return literal;
+
+				case TermOp.Match:
+					return literal + group.Value;
+
+				case TermOp.PreMatch:
+					return literal + group.Text.Substring (0, group.Index);
+
+				case TermOp.PostMatch:
+					return literal + group.Text.Substring (group.Index + group.Length);
+
+				case TermOp.All:
+					return literal + group.Text;
+				}
+
+				return "";
+			}
+		
+			public TermOp op;		// term type
+			public int arg;			// group argument
+			public string literal;		// literal to prepend
+
+			public override string ToString () {
+				return op.ToString () + "(" + arg + ") " + literal;
+			}
+		}
+	}
+}

+ 3 - 1
mcs/class/System/System.dll.sources

@@ -625,14 +625,16 @@ System.Security.Permissions/ResourcePermissionBase.cs
 System.Security.Permissions/ResourcePermissionBaseEntry.cs
 System.Text.RegularExpressions/arch.cs
 System.Text.RegularExpressions/cache.cs
+System.Text.RegularExpressions/Capture.cs
 System.Text.RegularExpressions/CaptureCollection.cs
 System.Text.RegularExpressions/category.cs
 System.Text.RegularExpressions/compiler.cs
 System.Text.RegularExpressions/debug.cs
+System.Text.RegularExpressions/Group.cs
 System.Text.RegularExpressions/GroupCollection.cs
 System.Text.RegularExpressions/interpreter.cs
 System.Text.RegularExpressions/interval.cs
-System.Text.RegularExpressions/match.cs
+System.Text.RegularExpressions/Match.cs
 System.Text.RegularExpressions/MatchCollection.cs
 System.Text.RegularExpressions/parser.cs
 System.Text.RegularExpressions/quicksearch.cs