Browse Source

[eval] fix StringBuf.addSub

Simon Krajewski 7 years ago
parent
commit
28f7394083
2 changed files with 9 additions and 2 deletions
  1. 2 2
      src/macro/eval/evalStdLib.ml
  2. 7 0
      tests/unit/src/unitstd/Unicode.unit.hx

+ 2 - 2
src/macro/eval/evalStdLib.ml

@@ -356,7 +356,7 @@ module StdBytes = struct
 			encode_bytes (Bytes.of_string s)
 		end
 	)
-	
+
 	let ofHex = vfun1 (fun v ->
 		let s = decode_string v in
 		let len = String.length s in
@@ -2178,7 +2178,7 @@ module StdStringBuf = struct
 		in
 		let s' = Rope.sub s.srope i len in
 		let s' = if s.sascii then create_ascii_of_rope s'
-		else create_ucs2_of_rope s' len in
+		else create_ucs2_of_rope s' (len lsr 1) in
 		AwareBuffer.add_string this s';
 		vnull
 	)

+ 7 - 0
tests/unit/src/unitstd/Unicode.unit.hx

@@ -214,4 +214,11 @@ var map = new haxe.ds.StringMap();
 map.set("path", 1);
 map.get("äpath".substr(1)) == 1;
 
+var data =  "<haxe><s>Hello World!</s><s2>π</s2></haxe>";
+var buf = new StringBuf();
+buf.addSub(data, 9, 12);
+var s = buf.toString();
+s == "Hello World!";
+s.length == 12;
+
 #end