Browse Source

[lua] Support UTF-8 mode in EReg : Looks good to me. The appveyor tests are failing due to an unrelated issue.

[lua] Support UTF-8 mode in EReg :  Looks good to me.  The appveyor tests are failing due to an unrelated issue.
Justin Donaldson 9 years ago
parent
commit
e6e1fb5c32
2 changed files with 11 additions and 4 deletions
  1. 9 3
      std/lua/_std/EReg.hx
  2. 2 1
      std/lua/lib/lrexlib/Rex.hx

+ 9 - 3
std/lua/_std/EReg.hx

@@ -32,17 +32,22 @@ class EReg {
 	var s : String; // the last matched string
 	var m : Table<Int,Int>; // the [start:Int, end:Int, and submatches:String (matched groups)] as a single table.
 
+	static var FLAGS: Table<String, Int>; // Available PCRE flags
+
 	public function new( r : String, opt : String ) : Void {
-		var ropt = new StringBuf();
+		var ropt = 0;
 		for (i in 0...opt.length){
 			switch(opt.charAt(i)){
-				case "i", "m", "s" : ropt.add(opt.charAt(i));
+				case "i" : ropt |= FLAGS.CASELESS;
+				case "m" : ropt |= FLAGS.MULTILINE;
+				case "s" : ropt |= FLAGS.DOTALL;
+				case "u" : ropt |= FLAGS.UTF8;
 				case "g" : global = true;
 				default : null;
 			}
 		}
 		if (global == null) global = false;
-		this.r = Rex.create(r, ropt.toString());
+		this.r = Rex.create(r, ropt);
 	}
 
 	public function match( s : String ) : Bool {
@@ -152,6 +157,7 @@ class EReg {
 		if (Rex == null){
 			throw "Rex is missing.  Please install lrexlib-pcre.";
 		}
+		FLAGS = Rex.flags();
 	}
 
 }

+ 2 - 1
std/lua/lib/lrexlib/Rex.hx

@@ -2,6 +2,7 @@ package lua.lib.lrexlib;
 @:luaRequire("rex_pcre")
 extern class Rex {
 
+	@:overload(          function       (expr : String, flag : Int) : Rex{})
 	inline public static function create(expr : String, flag : String) : Rex{
 		return untyped Rex['new'](expr, flag);
 	}
@@ -35,7 +36,7 @@ extern class Rex {
 	  This function counts matches of the pattern `patt` in the string `subj`.
 	**/	
 	public static function count(subj : String, patt : String, cf : Int, ef : Int) : Dynamic;
-	public static function flags(tb:Dynamic) : Dynamic;
+	public static function flags(?tb:Dynamic) : Dynamic;
 
   /**
     The function searches for the first match of the regexp in the string