Browse Source

optional substr length.

Nicolas Cannasse 19 years ago
parent
commit
ea258995c6
2 changed files with 5 additions and 6 deletions
  1. 1 1
      std/String.hx
  2. 4 5
      std/neko/NekoString__.hx

+ 1 - 1
std/String.hx

@@ -60,7 +60,7 @@ extern class String {
 	function indexOf( value : String, ?startIndex : Int ) : Int;
 	function lastIndexOf( value : String, startIndex : Int ) : Int;
 	function split( delimiter : String ) : Array<String>;
-	function substr( pos : Int, len : Int ) : String;
+	function substr( pos : Int, ?len : Int ) : String;
 
 	function toString() : String;
 

+ 4 - 5
std/neko/NekoString__.hx

@@ -94,11 +94,10 @@ class NekoString__ implements String {
 		}
 	}
 
-	public function substr( pos, len ) {
-		if( len == null || len == 0 ) return "";
-
-		var sl = untyped __dollar__ssize(this.__s);
-
+	public function substr( pos, ?len ) {
+		var sl = length;		
+		if( len == 0 ) return "";
+		if( len == null ) len = sl - pos;
 		if( pos == null ) pos = 0;
 		if( pos != 0 && len < 0 ){
 			return "";