2 * Copyright (c) 2015, Facebook, Inc.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
10 (* Implementation of string escaping stuff. Ugggggggh.
11 * See http://php.net/manual/en/language.types.string.php *)
19 let is_lit_printable c
=
21 is_printable c
&& c
<> '
\\'
&& c
<> '
\"'
23 let escape_char = function
30 | c when is_lit_printable c -> String.make 1 c
31 | c -> Printf.sprintf "\\%03o
" (Char.to_int c)
33 let escape ?(f = escape_char) s =
34 let buf = Buffer.create (String.length s) in
35 Stdlib.String.iter (fun c -> Buffer.add_string buf @@ f c) s;