It works just as fine
[mono.git] / mcs / class / System / System.Text.RegularExpressions / regex.cs
index 3b5e52cbe48d49989e30a59b37c4cac9133f4817..ea91a187c90de3c0f13a40a1631f3c3ef8ab6cff 100644 (file)
@@ -146,21 +146,21 @@ namespace System.Text.RegularExpressions {
                \r
                        this.factory = cache.Lookup (pattern, options);\r
 \r
-                       if (this.factory == null) {\r
-                               // parse and install group mapping\r
+                       // parse and install group mapping\r
 \r
-                               Parser psr = new Parser ();\r
-                               RegularExpression re = psr.ParseRegularExpression (pattern, options);\r
-                               this.group_count = re.GroupCount;\r
-                               this.mapping = psr.GetMapping ();\r
+                       Parser psr = new Parser ();\r
+                       RegularExpression re = psr.ParseRegularExpression (pattern, options);\r
+                       this.group_count = re.GroupCount;\r
+                       this.mapping = psr.GetMapping ();\r
 \r
+                       if (this.factory == null) {\r
                                // compile\r
                                \r
                                ICompiler cmp;\r
-                               if ((options & RegexOptions.Compiled) != 0)\r
-                                       throw new Exception ("Not implemented.");\r
+                               //if ((options & RegexOptions.Compiled) != 0)\r
+                               //      throw new Exception ("Not implemented.");\r
                                        //cmp = new CILCompiler ();\r
-                               else\r
+                               //else\r
                                        cmp = new PatternCompiler ();\r
 \r
                                re.Compile (cmp, RightToLeft);\r
@@ -172,6 +172,12 @@ namespace System.Text.RegularExpressions {
                        }\r
                }\r
 \r
+               protected Regex (SerializationInfo info, StreamingContext context) :\r
+                       this (info.GetString ("pattern"), \r
+                             (RegexOptions) info.GetValue ("options", typeof (RegexOptions))) {                        \r
+               }\r
+\r
+\r
                // public instance properties\r
                \r
                public RegexOptions Options {\r
@@ -311,8 +317,11 @@ namespace System.Text.RegularExpressions {
                                count = Int32.MaxValue;\r
 \r
                        int ptr = startat;\r
-                       Match m = Match (input, startat);\r
-                       while (count -- > 0 && m.Success) {\r
+                       while (count -- > 0) {\r
+                               Match m = Match (input, ptr);\r
+                               if (!m.Success)\r
+                                       break;\r
+                       \r
                                splits.Add (input.Substring (ptr, m.Index - ptr));\r
                                ptr = m.Index + m.Length;\r
                        }\r
@@ -332,9 +341,9 @@ namespace System.Text.RegularExpressions {
                }\r
 \r
                // ISerializable interface\r
-\r
-               public void GetObjectData (SerializationInfo info, StreamingContext context) {\r
-                       throw new Exception ("Not implemented.");\r
+               public virtual void GetObjectData (SerializationInfo info, StreamingContext context) {\r
+                       info.AddValue ("pattern", this.ToString (), typeof (string));\r
+                       info.AddValue ("options", this.Options, typeof (RegexOptions));\r
                }\r
 \r
                // internal\r