2
0
Эх сурвалжийг харах

Merge pull request #2759 from mandel59/unicode-escape

implement Unicode code point escapes
Nicolas Cannasse 11 жил өмнө
parent
commit
9f22c72c70
1 өөрчлөгдсөн 16 нэмэгдсэн , 0 устгасан
  1. 16 0
      ast.ml

+ 16 - 0
ast.ml

@@ -617,6 +617,22 @@ 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
+						let u = int_of_string ("0x" ^ String.sub s (i+2) l) in
+						assert (u <= 0x10FFFF);
+						(u, 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;