Explorar el Código

added addString, addFloat, addDouble on haxe.io.BytesBuffer

Nicolas Cannasse hace 11 años
padre
commit
2d45e2d7c6
Se han modificado 1 ficheros con 34 adiciones y 0 borrados
  1. 34 0
      std/haxe/io/BytesBuffer.hx

+ 34 - 0
std/haxe/io/BytesBuffer.hx

@@ -109,6 +109,40 @@ class BytesBuffer {
 		#end
 		#end
 	}
 	}
 
 
+	public inline function addString( v : String ) {
+		#if neko
+		untyped StringBuf.__add(b, v.__s);
+		#elseif flash9
+		b.writeUTFBytes(v);
+		#else
+		add(Bytes.ofString(v));
+		#end
+	}
+
+	public inline function addFloat( v : Float ) {
+		#if neko
+		untyped StringBuf.__add(b, Output._float_bytes(v, false));
+		#elseif flash9
+		b.writeFloat(v);
+		#else
+		var b = new BytesOutput();
+		b.writeFloat(v);
+		add(b.getBytes());
+		#end
+	}
+	
+	public inline function addDouble( v : Float ) {
+		#if neko
+		untyped StringBuf.__add(b, Output._double_bytes(v, false));
+		#elseif flash9
+		b.writeDouble(v);
+		#else
+		var b = new BytesOutput();
+		b.writeDouble(v);
+		add(b.getBytes());
+		#end
+	}
+	
 	public inline function addBytes( src : Bytes, pos : Int, len : Int ) {
 	public inline function addBytes( src : Bytes, pos : Int, len : Int ) {
 		#if !neko
 		#if !neko
 		if( pos < 0 || len < 0 || pos + len > src.length ) throw Error.OutsideBounds;
 		if( pos < 0 || len < 0 || pos + len > src.length ) throw Error.OutsideBounds;