Browse Source

added support for "g" modifier in EReg for PHP

Franco Ponticelli 17 năm trước cách đây
mục cha
commit
e3767f51ca
2 tập tin đã thay đổi với 8 bổ sung4 xóa
  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
 	fixed blocks in if statements for haXe/PHP
 	added php check on the full hierarchy for colliding names
+	added support for "g" modifier in EReg for PHP
 
 2008-07-28: 2.0
 	fixed current package bug in inherited constructor type

+ 7 - 4
std/EReg.hx

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