Browse Source

String. substr fixed according to Haxe spec and tests

PeyTy 10 years ago
parent
commit
b45a934628
1 changed files with 3 additions and 0 deletions
  1. 3 0
      std/lua/_std/String.hx

+ 3 - 0
std/lua/_std/String.hx

@@ -85,6 +85,9 @@ class String {
 
 
 	public function substr( pos : Int, ?len : Int ) : String {
 	public function substr( pos : Int, ?len : Int ) : String {
 		if (len == null || len > pos + this.length) len = this.length;
 		if (len == null || len > pos + this.length) len = this.length;
+		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 lua.StringTools.sub(this, pos + 1, pos+len);
 	}
 	}