Преглед на файлове

added support for "g" modifier in EReg for PHP

Franco Ponticelli преди 17 години
родител
ревизия
e3767f51ca
променени са 2 файла, в които са добавени 8 реда и са изтрити 4 реда
  1. 1 0
      doc/CHANGES.txt
  2. 7 4
      std/EReg.hx

+ 1 - 0
doc/CHANGES.txt

@@ -34,6 +34,7 @@ TODO inlining : substitute class+function type parameters in order to have fully
 	php.db.Mysql now throws an exception when tries to connect to an unexistant DB
 	php.db.Mysql now throws an exception when tries to connect to an unexistant DB
 	fixed blocks in if statements for haXe/PHP
 	fixed blocks in if statements for haXe/PHP
 	added php check on the full hierarchy for colliding names
 	added php check on the full hierarchy for colliding names
+	added support for "g" modifier in EReg for PHP
 
 
 2008-07-28: 2.0
 2008-07-28: 2.0
 	fixed current package bug in inherited constructor type
 	fixed current package bug in inherited constructor type

+ 7 - 4
std/EReg.hx

@@ -34,7 +34,7 @@ class EReg {
 	#if flash9
 	#if flash9
 	var result : {> Array<String>, index : Int, input : String };
 	var result : {> Array<String>, index : Int, input : String };
 	#end
 	#end
-	#if neko
+	#if (neko || php)
 	var last : String;
 	var last : String;
 	var global : Bool;
 	var global : Bool;
 	#end
 	#end
@@ -42,7 +42,6 @@ class EReg {
 	var pattern : String;
 	var pattern : String;
 	var options : String;
 	var options : String;
 	var re : String;
 	var re : String;
-	var last : String;
 	var matches : Array<Dynamic>;
 	var matches : Array<Dynamic>;
 	#end
 	#end
 
 
@@ -64,6 +63,10 @@ class EReg {
 			this.r = untyped __new__(__global__["RegExp"],r,opt);
 			this.r = untyped __new__(__global__["RegExp"],r,opt);
 		#elseif php
 		#elseif php
 			this.pattern = r;
 			this.pattern = r;
+			var a = opt.split("g");
+			global = a.length > 1;
+			if( global )
+				opt = a.join("");
 			this.options = opt;
 			this.options = opt;
 			this.re = "/" + untyped __php__("str_replace")("/", "\\/", r) + "/" + opt;
 			this.re = "/" + untyped __php__("str_replace")("/", "\\/", r) + "/" + opt;
 		#else
 		#else
@@ -240,7 +243,7 @@ class EReg {
 			var d = "#__delim__#";
 			var d = "#__delim__#";
 			return untyped s.replace(r,d).split(d);
 			return untyped s.replace(r,d).split(d);
 		#elseif php
 		#elseif php
-			return untyped __php__("preg_split")(re, s);
+			return untyped __php__("preg_split")(re, s, global ? -1 : 2);
 		#else
 		#else
 			return null;
 			return null;
 		#end
 		#end
@@ -306,7 +309,7 @@ class EReg {
 		#elseif php
 		#elseif php
 			by = untyped __call__("str_replace", "$$", "\\$", by);
 			by = untyped __call__("str_replace", "$$", "\\$", by);
 			untyped __php__("if(!preg_match('/\\\\([^?].+?\\\\)/', $this->re)) $by = preg_replace('/\\$(\\d+)/', '\\\\\\$\\1', $by)");
 			untyped __php__("if(!preg_match('/\\\\([^?].+?\\\\)/', $this->re)) $by = preg_replace('/\\$(\\d+)/', '\\\\\\$\\1', $by)");
-			return untyped __php__("preg_replace")(re, by, s);
+			return untyped __php__("preg_replace")(re, by, s, global ? -1 : 1);
 		#else
 		#else
 			return null;
 			return null;
 		#end
 		#end