[Mono-list] Patch for regex

Jackson Harper JRHwork@hotmail.com
Mon, 11 Nov 2002 19:14:39 -0800


This is a multi-part message in MIME format.

------=_NextPart_000_0026_01C289B6.94CB9BA0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_001_0027_01C289B6.94CB9BA0"


------=_NextPart_001_0027_01C289B6.94CB9BA0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Attached is a test case that fails with the current regex code (at least =
on my machine) and a few small patches to fix this problem.

The problem was that the mapping variable was not being set when a =
cached regex was being used, so I added a Mapping property to =
IMachineFactory and added code to set this property when a new factory =
is created and get the property when a cached factory is being used.

As soon as I get heads up I can commit these patches.

Thanks,
Jackson

------=_NextPart_001_0027_01C289B6.94CB9BA0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2719.2200" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Attached is a test case that fails with =
the current=20
regex code (at least on my machine) and a few small patches to fix this=20
problem.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>The problem was that the mapping =
variable was not=20
being set when a cached regex was being used, so I added a Mapping =
property to=20
IMachineFactory and added code to set this property when a new factory =
is=20
created and get the property when a cached factory is being =
used.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>As soon as I get heads up I can commit =
these=20
patches.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Jackson</FONT></DIV></BODY></HTML>

------=_NextPart_001_0027_01C289B6.94CB9BA0--

------=_NextPart_000_0026_01C289B6.94CB9BA0
Content-Type: application/octet-stream;
	name="regex.cs.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="regex.cs.patch"

Index: regex.cs=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: =
/cvs/public/mcs/class/System/System.Text.RegularExpressions/regex.cs,v=0A=
retrieving revision 1.11=0A=
diff -u -u -r1.11 regex.cs=0A=
--- regex.cs	28 Aug 2002 18:46:54 -0000	1.11=0A=
+++ regex.cs	12 Nov 2002 02:56:42 -0000=0A=
@@ -168,9 +168,11 @@=0A=
 				// install machine factory and add to pattern cache
=20
 				this.factory =3D cmp.GetMachineFactory ();
+				this.factory.Mapping =3D mapping;
 				cache.Add (pattern, options, this.factory);
 			} else {
 				this.group_count =3D this.factory.GroupCount;
+				this.mapping =3D this.factory.Mapping;
 			}
 		}
=20

------=_NextPart_000_0026_01C289B6.94CB9BA0
Content-Type: application/octet-stream;
	name="arch.cs.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="arch.cs.patch"

Index: arch.cs=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: =
/cvs/public/mcs/class/System/System.Text.RegularExpressions/arch.cs,v=0A=
retrieving revision 1.2=0A=
diff -u -u -r1.2 arch.cs=0A=
--- arch.cs	28 Aug 2002 18:46:54 -0000	1.2=0A=
+++ arch.cs	12 Nov 2002 02:55:59 -0000=0A=
@@ -7,6 +7,7 @@=0A=
 // 		(c) 2002
=20
 using System;
+using System.Collections;
=20
 namespace System.Text.RegularExpressions {
=20
@@ -81,6 +82,7 @@=0A=
=20
 	interface IMachineFactory {
 		IMachine NewInstance ();
+		IDictionary Mapping { get; set; }
 		int GroupCount { get; }
 	}
=20

------=_NextPart_000_0026_01C289B6.94CB9BA0
Content-Type: application/octet-stream;
	name="compiler.cs.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="compiler.cs.patch"

Index: compiler.cs=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: =
/cvs/public/mcs/class/System/System.Text.RegularExpressions/compiler.cs,v=0A=
retrieving revision 1.2=0A=
diff -u -u -r1.2 compiler.cs=0A=
--- compiler.cs	28 Aug 2002 18:46:54 -0000	1.2=0A=
+++ compiler.cs	12 Nov 2002 02:56:19 -0000=0A=
@@ -70,6 +70,12 @@=0A=
 			get { return pattern[0]; }
 		}
=20
+		public IDictionary Mapping {
+			get { return mapping; }
+			set { mapping =3D value; }
+		}
+
+		private IDictionary mapping;
 		private ushort[] pattern;
 	}
=20

------=_NextPart_000_0026_01C289B6.94CB9BA0
Content-Type: application/octet-stream;
	name="RegExTest.cs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="RegExTest.cs"

=0A=
using System;=0A=
using System.Text.RegularExpressions;=0A=
=0A=
public class RegExTest {=0A=
=0A=
	public static void Main() {=0A=
		string url =3D "http://www.contoso.com:8080/letters/readme.html";=0A=
		PrintPort (url);=0A=
		PrintPort (url);=0A=
		=0A=
		Console.WriteLine ();=0A=
		Console.WriteLine ();=0A=
		=0A=
		PrintProto (url);=0A=
		PrintProto (url);=0A=
=0A=
	}=0A=
=0A=
	private static void PrintPort(String url) =0A=
	{=0A=
		Regex reg =3D new Regex(@"^(?<proto>\w+)://[^/]+?(?<port>:\d+)?/",=0A=
		RegexOptions.Compiled);=0A=
		=0A=
		Match match =3D reg.Match (url);=0A=
		=0A=
		if (!match.Success)=0A=
			return;=0A=
=0A=
		Console.WriteLine ("Port: {0}", match.Result("${port}"));	=0A=
   	}=0A=
=0A=
	private static void PrintProto(String url)=0A=
	{=0A=
		Regex reg =3D new Regex(@"^(?<proto>\w+)://[^/]+?(?<port>:\d+)?/",=0A=
		RegexOptions.Compiled);=0A=
		=0A=
		Match match =3D reg.Match (url);=0A=
		=0A=
		if (!match.Success)=0A=
			return;=0A=
=0A=
		Console.WriteLine ("Protocol: {0}", match.Result("${proto}"));=0A=
	}=0A=
=0A=
}
------=_NextPart_000_0026_01C289B6.94CB9BA0--