ソースを参照

implement \u escape sequences in strings

Ryusei Yamaguchi 11 年 前
コミット
0273b7178a
1 ファイル変更14 行追加0 行削除
  1. 14 0
      ast.ml

+ 14 - 0
ast.ml

@@ -617,6 +617,20 @@ let unescape s =
 					let c = (try char_of_int (int_of_string ("0x" ^ String.sub s (i+1) 2)) with _ -> raise Exit) in
 					Buffer.add_char b c;
 					inext := !inext + 2;
+				| 'u' ->
+					let (u, a) =
+					  (try
+					      (int_of_string ("0x" ^ String.sub s (i+1) 4), 4)
+					    with
+					      _ -> try
+						assert (s.[i+1] = '{');
+						let l = String.index_from s (i+3) '}' - (i+2) in
+						(int_of_string ("0x" ^ String.sub s (i+2) l), l+2)
+					      with _ -> raise Exit) in
+					let ub = UTF8.Buf.create 0 in
+					UTF8.Buf.add_char ub (UChar.uchar_of_int u);
+					Buffer.add_string b (UTF8.Buf.contents ub);
+					inext := !inext + a;
 				| _ ->
 					raise Exit);
 				loop false !inext;