Explorar o código

STD: Add length property to StringBuf

Mike Welsh %!s(int64=12) %!d(string=hai) anos
pai
achega
c1cb7ce8ab

+ 9 - 0
std/StringBuf.hx

@@ -34,6 +34,11 @@ class StringBuf {
 
 	var b:String = "";
 	
+	/**
+		The length of [this] StringBuf in characters.
+	**/
+	public var length(get,never) : Int;
+
 	/**
 		Creates a new StringBuf instance.
 		
@@ -41,6 +46,10 @@ class StringBuf {
 	**/
 	public function new() {}
 
+	inline function get_length() : Int {
+		return b.length;
+	}
+
 	/**
 		Appends the representation of [x] to [this] StringBuf.
 		

+ 8 - 0
std/cpp/_std/StringBuf.hx

@@ -24,10 +24,18 @@ class StringBuf {
 
 	private var b : Array<String>;
 
+	public var length(get,never) : Int;
+
 	public function new() : Void {
 		b = new Array();
 	}
 
+	function get_length() : Int {
+		var len = 0;
+		for(s in b) len += s.length;
+		return len;
+	}
+
 	public function add( x : Dynamic ) : Void {
 		b.push(x);
 	}

+ 1 - 0
std/cs/StringBuilder.hx

@@ -25,6 +25,7 @@ package cs;
 //Once this bug is fixed, it will be moved back to the cs.system.text package
 @:native('System.Text.StringBuilder') extern class StringBuilder 
 {
+	var Length(default,never):Int;
 
 	function new():Void;
 	

+ 6 - 0
std/cs/_std/StringBuf.hx

@@ -24,10 +24,16 @@ class StringBuf {
 
 	private var b : cs.StringBuilder;
 
+	public var length(get,never) : Int;
+
 	public function new() : Void {
 		b = new cs.StringBuilder();
 	}
 
+	inline function get_length() : Int {
+		return b.Length;
+	}
+
 	public inline function add( x : Dynamic ) : Void {
 		b.Append(Std.string(x));
 	}

+ 6 - 0
std/java/_std/StringBuf.hx

@@ -24,10 +24,16 @@ class StringBuf {
 
 	private var b : java.lang.StringBuilder;
 
+	public var length(get,never) : Int;
+
 	public function new() : Void {
 		b = new java.lang.StringBuilder();
 	}
 
+	inline function get_length() : Int {
+		return b.length();
+	}
+
 	public function add( x : Dynamic ) : Void {
 		if (Std.is(x, Int))
 		{

+ 6 - 0
std/neko/_std/StringBuf.hx

@@ -23,10 +23,16 @@
 
 	private var b : Dynamic;
 
+	public var length(get,never) : Int;
+
 	public function new() : Void {
 		b = __make();
 	}
 
+	inline function get_length() : Int {
+		return untyped __dollar__ssize( __to_string(b) );
+	}
+
 	public inline function add( x : Dynamic ) : Void {
 		__add(b,x);
 	}

+ 6 - 0
std/php/_std/StringBuf.hx

@@ -22,10 +22,16 @@
 @:coreApi class StringBuf {
 	private var b : String;
 
+	public var length(get,never) : Int;
+
 	public function new() : Void {
 		b = "";
 	}
 
+	inline function get_length() : Int {
+		return b.length;
+	}
+
 	public function add( x : Dynamic ) : Void {
 		untyped if( __call__('is_null',x) ) x = 'null' else if( __call__('is_bool',x) ) x = x?'true':'false';
 		b += x;