فهرست منبع

Lua : remove deprecated lua.StringTools in favor of lua.NativeStringTools

Justin Donaldson 9 سال پیش
والد
کامیت
5835bd0f6a
8فایلهای تغییر یافته به همراه47 افزوده شده و 67 حذف شده
  1. 1 1
      std/StringTools.hx
  2. 8 8
      std/lua/Boot.hx
  3. 10 7
      std/lua/Lib.hx
  4. 3 1
      std/lua/NativeStringTools.hx
  5. 0 28
      std/lua/StringTools.hx
  6. 5 4
      std/lua/_std/EReg.hx
  7. 6 5
      std/lua/_std/Std.hx
  8. 14 13
      std/lua/_std/String.hx

+ 1 - 1
std/StringTools.hx

@@ -409,7 +409,7 @@ class StringTools {
 		#elseif hl
 		return @:privateAccess s.bytes.getUI16(index << 1);
 		#elseif lua
-		return lua.StringTools.byte(s,index+1);
+		return lua.NativeStringTools.byte(s,index+1);
 		#else
 		return untyped s.cca(index);
 		#end

+ 8 - 8
std/lua/Boot.hx

@@ -137,19 +137,19 @@ class Boot {
 
 
 	public static function urlDecode(str:String){
-		str = lua.StringTools.gsub (str, "+", " ");
-		str = lua.StringTools.gsub (str, "%%(%x%x)",
-				function(h) {return lua.StringTools.char(lua.Lua.tonumber(h,16));});
-		str = lua.StringTools.gsub (str, "\r\n", "\n");
+		str = NativeStringTools.gsub (str, "+", " ");
+		str = NativeStringTools.gsub (str, "%%(%x%x)",
+				function(h) {return NativeStringTools.char(lua.Lua.tonumber(h,16));});
+		str = NativeStringTools.gsub (str, "\r\n", "\n");
 		return str;
 	}
 
 	public static function urlEncode(str:String){
-		str = lua.StringTools.gsub(str, "\n", "\r\n");
-		str = lua.StringTools.gsub(str, "([^%w %-%_%.%~])", function (c) {
-			return lua.StringTools.format("%%%02X", lua.StringTools.byte(c) + '');
+		str = NativeStringTools.gsub(str, "\n", "\r\n");
+		str = NativeStringTools.gsub(str, "([^%w %-%_%.%~])", function (c) {
+			return NativeStringTools.format("%%%02X", NativeStringTools.byte(c) + '');
 		});
-		str = lua.StringTools.gsub(str, " ", "+");
+		str = NativeStringTools.gsub(str, " ", "+");
 		return str;
 	}
 

+ 10 - 7
std/lua/Lib.hx

@@ -20,32 +20,35 @@
  * DEALINGS IN THE SOFTWARE.
  */
 package lua;
+import lua.Lua;
+import lua.Io;
+import lua.NativeStringTools;
 
 class Lib {
 
 	public static inline function println( v : Dynamic ) : Void {
-		lua.Lua.print(Std.string(v));
+		Lua.print(Std.string(v));
 	}
 
 	public static inline function print(v:Dynamic) : Void {
-		lua.Io.write(Std.string(v));
-		lua.Io.flush();
+		Io.write(Std.string(v));
+		Io.flush();
 	}
 
 	public inline static function tableToArray<T>(t:Table<Int,T>, ?length:Int) : Array<T> {
-		return lua.Boot.tableToArray(t, length);
+		return Boot.tableToArray(t, length);
 	}
 
 	public inline static function tableToObject<T>(t:Table<String,T>) : Dynamic<T> {
-		return lua.Boot.tableToObject(t);
+		return Boot.tableToObject(t);
 	}
 
 	public inline static function patternQuote(str:String) : String {
-		return lua.StringTools.gsub(str, "[%(%)%.%%%+%-%*%?%[%]%^%$]", function(c:String){ return "%" + c; });
+		return NativeStringTools.gsub(str, "[%(%)%.%%%+%-%*%?%[%]%^%$]", function(c:String){ return "%" + c; });
 	}
 
 	public inline static function defArray<T>(tab: Table<Int,T>, length : Int) : Array<T> {
-		return lua.Boot.defArray(tab, length);
+		return Boot.defArray(tab, length);
 	}
 
 	public static function fillArray<T>(itr:Void->T) : Array<T> {

+ 3 - 1
std/lua/NativeStringTools.hx

@@ -20,7 +20,9 @@ extern class NativeStringTools {
 	public static function gsub(str : String, pattern : String, replace : String,		  ?n : Int): String;
 
 	@:overload(   function     (str : String, pattern : String, match : Void->String,   ?n : Int): String->Void {})
-	public static function gmatch(str : String, pattern : String, ?n : Int): Void->String;
+	public static function gmatch(str : String, pattern : String): Void->String;
+
+	public static function match(str : String, pattern : String, ?n : Int): String;
 
 	public static function upper(str:String) : String;
 	public static function lower(str:String) : String;

+ 0 - 28
std/lua/StringTools.hx

@@ -1,28 +0,0 @@
-package lua;
-/**
-  These are all externs for the base Lua "string" class.  Note that all
-  relevant indexes are "1" based.
- **/
-@:native("_G.string")
-extern class StringTools {
-	public static function len(str : String): Int;
-	public static function char(i: Int): String;
-	public static function sub(str : String, start : Int, ?end : Int): String;
-	public static function charCodeAt(str : String, index : Int): Int;
-	public static function find(str : String, target : String, ?start : Int, ?plain : Bool): Int;
-	public static function byte(str : String, ?index : Int) : Int;
-	public static function format(str : String, ?e1 : Dynamic, ?e2 : Dynamic, ?e3 : Dynamic, ?e4 : Dynamic): String;
-
-	@:overload(   function     (str : String, pattern : String, replace : String->Void,   ?n : Int): String {})
-	@:overload(   function     (str : String, pattern : String, replace : String->String, ?n : Int): String {})
-	public static function gsub(str : String, pattern : String, replace : String,		  ?n : Int): String;
-
-	public static function match(str : String, pattern : String, ?idx : Int): String;
-
-	@:overload(   function     (str : String, pattern : String, match : Void->String,   ?n : Int): String->Void {})
-	public static function gmatch(str : String, pattern : String, ?n : Int): Void->String;
-
-	public static function upper(str:String) : String;
-	public static function lower(str:String) : String;
-}
-

+ 5 - 4
std/lua/_std/EReg.hx

@@ -22,6 +22,7 @@
 import lua.lib.lrexlib.Rex;
 import lua.Table;
 import lua.Lib;
+import lua.NativeStringTools;
 
 @:coreApi
 class EReg {
@@ -53,12 +54,12 @@ class EReg {
 	public function matched( n : Int ) : String {
 		if (m[1] == null || n < 0) throw "EReg::matched";
 		else if (n == 0) {
-			var k =  lua.StringTools.sub(s, m[1], m[2]);
+			var k =  NativeStringTools.sub(s, m[1], m[2]);
 			return k;
 		} else if (Std.is(m[3], lua.Table)){
 			var mn = 2 * (n - 1);
 			if (Std.is(untyped m[3][mn+1], Bool)) return null;
-			return lua.StringTools.sub(s, untyped m[3][mn + 1], untyped m[3][mn + 2]);
+			return NativeStringTools.sub(s, untyped m[3][mn + 1], untyped m[3][mn + 2]);
 		} else {
 			throw "EReg:matched";
 		}
@@ -66,12 +67,12 @@ class EReg {
 
 	public function matchedLeft() : String {
 		if( m[1] == null ) throw "No string matched";
-		return lua.StringTools.sub(s, 1, m[1]-1);
+		return NativeStringTools.sub(s, 1, m[1]-1);
 	}
 
 	public function matchedRight() : String {
 		if( m[1] == null ) throw "No string matched";
-		return lua.StringTools.sub(s, m[2]+1);
+		return NativeStringTools.sub(s, m[2]+1);
 	}
 
 	public function matchedPos() : { pos : Int, len : Int } {

+ 6 - 5
std/lua/_std/Std.hx

@@ -20,6 +20,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 import lua.Boot;
+import lua.NativeStringTools;
 
 @:keepInit
 @:coreApi class Std {
@@ -43,11 +44,11 @@ import lua.Boot;
 
 	public static function parseInt( x : String ) : Null<Int> {
 		if (x == null) return null;
-		var hexMatch = lua.StringTools.match(x, "^ *[%-+]*0[xX][%da-FA-F]*");
+		var hexMatch = NativeStringTools.match(x, "^ *[%-+]*0[xX][%da-FA-F]*");
 		if (hexMatch != null){
 			return lua.Lua.tonumber(hexMatch.substr(2), 16);
 		} else {
-			var intMatch = lua.StringTools.match(x, "^ *[%-+]?%d*");
+			var intMatch = NativeStringTools.match(x, "^ *[%-+]?%d*");
 			if (intMatch != null){
 				return lua.Lua.tonumber(intMatch);
 			} else {
@@ -58,17 +59,17 @@ import lua.Boot;
 
 	public static function parseFloat( x : String ) : Float {
 		if (x == null || x == "") return Math.NaN;
-		var digitMatch = lua.StringTools.match(x,  "^ *[%.%-+]?[0-9]%d*");
+		var digitMatch = NativeStringTools.match(x,  "^ *[%.%-+]?[0-9]%d*");
 		if (digitMatch == null){
 			return Math.NaN;
 		}
 		x = x.substr(digitMatch.length);
 
-		var decimalMatch = lua.StringTools.match(x, "^%.%d*");
+		var decimalMatch = NativeStringTools.match(x, "^%.%d*");
 		if (decimalMatch == null) decimalMatch = "";
 		x = x.substr(decimalMatch.length);
 
-		var eMatch =lua.StringTools.match(x, "^[eE][+%-]?%d+");
+		var eMatch = NativeStringTools.match(x, "^[eE][+%-]?%d+");
 		if (eMatch == null) eMatch = "";
 		var result =  lua.Lua.tonumber(digitMatch + decimalMatch + eMatch);
 		return result != null ? result : Math.NaN;

+ 14 - 13
std/lua/_std/String.hx

@@ -23,6 +23,7 @@
 import lua.Lua;
 import lua.Table;
 import lua.Boot;
+import lua.NativeStringTools;
 
 @:coreApi
 class String {
@@ -44,12 +45,12 @@ class String {
 	}
 
 
-	public function toUpperCase() : String return lua.StringTools.upper(this);
-	public function toLowerCase() : String return lua.StringTools.lower(this);
+	public function toUpperCase() : String return NativeStringTools.upper(this);
+	public function toLowerCase() : String return NativeStringTools.lower(this);
 	public function indexOf( str : String, ?startIndex : Int ) : Int {
 		if (startIndex == null) startIndex = 1;
 		else startIndex += 1;
-		var r = lua.StringTools.find(this, str, startIndex, true);
+		var r = NativeStringTools.find(this, str, startIndex, true);
 		if (r != null && r > 0) return r-1;
 		else return -1;
 	}
@@ -72,7 +73,7 @@ class String {
 		while (idx != null){
 			var newidx = 0;
 			if (delimiter.length > 0){
-				newidx = lua.StringTools.find(this, delimiter, idx, true);
+				newidx = NativeStringTools.find(this, delimiter, idx, true);
 			} else if (idx >= this.length){
 				newidx = null;
 			} else {
@@ -80,11 +81,11 @@ class String {
 			}
 
 			if (newidx != null){
-				var match = lua.StringTools.sub(this, idx, newidx-1);
+				var match = NativeStringTools.sub(this, idx, newidx-1);
 				ret.push(match);
 				idx = newidx + delimiter.length;
 			} else {
-				ret.push(lua.StringTools.sub(this,idx,lua.StringTools.len(this)));
+				ret.push(NativeStringTools.sub(this,idx,NativeStringTools.len(this)));
 				idx = null;
 			}
 		}
@@ -100,20 +101,20 @@ class String {
 		if (startIndex < 0) startIndex = 0;
 		if (endIndex == 0) {
 			// swap the index positions
-			return untyped lua.StringTools.sub(this, endIndex+1, startIndex);
+			return NativeStringTools.sub(this, endIndex+1, startIndex);
 		} else {
-			return untyped lua.StringTools.sub(this, startIndex+1, endIndex);
+			return NativeStringTools.sub(this, startIndex+1, endIndex);
 		}
 	}
 
 	function get_length() : Int {
-		return lua.StringTools.len(this);
+		return NativeStringTools.len(this);
 	}
 	public function charAt( index : Int) : String {
-		return lua.StringTools.sub(this,index+1, index+1);
+		return NativeStringTools.sub(this,index+1, index+1);
 	}
 	public function charCodeAt( index : Int) : Null<Int> {
-		return lua.StringTools.byte(this,index+1);
+		return NativeStringTools.byte(this,index+1);
 	}
 
 	public function substr( pos : Int, ?len : Int ) : String {
@@ -121,11 +122,11 @@ class String {
 		else if (len < 0) len = length + len;
 		if (pos < 0) pos = length + pos;
 		if (pos < 0) pos = 0;
-		return lua.StringTools.sub(this, pos + 1, pos+len);
+		return NativeStringTools.sub(this, pos + 1, pos+len);
 	}
 
 	public inline static function fromCharCode( code : Int ) : String {
-		return lua.StringTools.char(code);
+		return NativeStringTools.char(code);
 	}
 }