Skip to content

Commit

Permalink
implement \u escape sequences in strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mandel59 committed Mar 14, 2014
1 parent 03da505 commit 0273b71
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0273b71

Please sign in to comment.