浏览代码

[eval] fix ofString with RawNative

Simon Krajewski 7 年之前
父节点
当前提交
47b3f88158
共有 2 个文件被更改,包括 10 次插入4 次删除
  1. 6 4
      src/macro/eval/evalStdLib.ml
  2. 4 0
      tests/unit/src/unitstd/Unicode.unit.hx

+ 6 - 4
src/macro/eval/evalStdLib.ml

@@ -349,10 +349,12 @@ module StdBytes = struct
 
 
 	let ofString = vfun2 (fun v encoding ->
 	let ofString = vfun2 (fun v encoding ->
 		let s = decode_vstring v in
 		let s = decode_vstring v in
-		if s.sascii || encode_native encoding then
-			encode_bytes (Bytes.of_string (Lazy.force s.sstring))
-		else begin
-			let s = utf16_to_utf8 (Lazy.force s.sstring) in
+		if encode_native encoding then begin
+			let s = maybe_extend_ascii s in
+			encode_bytes (Bytes.of_string s)
+		end else begin
+			let s' = Lazy.force s.sstring in
+			let s = if s.sascii then s' else utf16_to_utf8 s' in
 			encode_bytes (Bytes.of_string s)
 			encode_bytes (Bytes.of_string s)
 		end
 		end
 	)
 	)

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

@@ -223,4 +223,8 @@ s.length == 12;
 
 
 "äabc:def".substr(1).split(":") == ["abc","def"];
 "äabc:def".substr(1).split(":") == ["abc","def"];
 
 
+var s1 = "abc";
+var b1 = haxe.io.Bytes.ofString(s1, RawNative);
+var s2 = b1.getString(0, b1.length, RawNative);
+s1 == s2;
 #end
 #end