2007-10-22 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System / System.Text.RegularExpressions / Match.cs
index e2ca625d5e47be4e8d108e3aa7f0c398a4df7906..768fca2265e70b88da443bb471f3e686447580f6 100644 (file)
@@ -5,7 +5,7 @@
 //
 // author:     Dan Lewis (dlewis@gmx.co.uk)
 //             (c) 2002
-
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -27,8 +27,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
-
 namespace System.Text.RegularExpressions {
 
        [Serializable]
@@ -36,8 +34,12 @@ namespace System.Text.RegularExpressions {
                public static Match Empty {
                        get { return empty; }
                }
-               
-               public static Match Synchronized (Match inner) {
+
+               [MonoTODO ("not thread-safe")]
+               public static Match Synchronized (Match inner)
+               {
+                       if (inner == null)
+                               throw new ArgumentNullException ("inner");
                        return inner;   // FIXME need to sync on machine access
                }
                
@@ -45,7 +47,8 @@ namespace System.Text.RegularExpressions {
                        get { return groups; }
                }
 
-               public Match NextMatch () {
+               public Match NextMatch ()
+               {
                        if (this == Empty)
                                return Empty;
 
@@ -59,32 +62,38 @@ namespace System.Text.RegularExpressions {
                        return machine.Scan (regex, Text, scan_ptr, text_length);
                }
 
-               public virtual string Result (string replacement) {
+               public virtual string Result (string replacement)
+               {
+                       if (replacement == null)
+                               throw new ArgumentNullException ("replacement");
+                       if (replacement.Length == 0)
+                               throw new NotSupportedException ();
+
                        return ReplacementEvaluator.Evaluate (replacement, this);
                }
 
                // internal
 
-               internal Match () : base (null, null) {
+               private Match ()
+               {
                        this.regex = null;
                        this.machine = null;
                        this.text_length = 0;
-                       this.groups = new GroupCollection ();
 
-                       groups.Add (this);
+                       this.groups = new GroupCollection (1);
+                       groups.SetValue (this, 0);
                }
                
-               internal Match (Regex regex, IMachine machine, string text, int text_length, int[][] grps) :
-                       base (text, grps[0])
+               internal Match (Regex regex, IMachine machine, string text, int text_length, int n_groups, 
+                               int index, int length, int n_caps) :
+                       base (text, index, length, n_caps)
                {
                        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]));
+                       this.groups = new GroupCollection (n_groups);
+                       groups.SetValue (this, 0);
                }
 
                internal Regex Regex {