Browse Source

Modify substr, now behaves as AS2

Pascal Peridont 19 years ago
parent
commit
5cee774a39
1 changed files with 17 additions and 0 deletions
  1. 17 0
      std/neko/NekoString__.hx

+ 17 - 0
std/neko/NekoString__.hx

@@ -88,6 +88,23 @@ class NekoString__ implements String {
 	}
 
 	public function substr( pos, len ) {
+		if( len == null ) return "";
+		
+		var sl = untyped __dollar__ssize(this.__s);
+
+		if( pos == null ) pos = 0;
+		
+		if( pos < 0 ){
+			pos = sl + pos;
+			if( pos < 0 ) pos = 0;
+		}else if( len < 0 ){
+			len = sl + len - pos;
+		}
+
+		if( pos + len > sl ){
+			len = sl - pos;
+		}
+
 		return untyped new String(__dollar__ssub(this.__s,pos,len));
 	}