Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.
Prev Previous commit
Next Next commit
bugfix: correct escapes printer
  • Loading branch information
butterunderflow committed Oct 28, 2022
commit fb59e249c7c1409a8e5bb236e0092428ba81eeea
17 changes: 16 additions & 1 deletion src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,22 @@ let printConstant ?(templateLiteral = false) c =
]
| Pconst_float (s, _) -> Doc.text s
| Pconst_char c ->
let str = Res_utf8.encodeCodePoint c in
let str =
if c <= 127 then
match Char.chr c with
| '\'' -> "\\'"
| '\\' -> "\\\\"
| '\n' -> "\\n"
| '\t' -> "\\t"
| '\r' -> "\\r"
| '\b' -> "\\b"
| ' ' .. '~' as c ->
let s = (Bytes.create [@doesNotRaise]) 1 in
Bytes.unsafe_set s 0 c;
Bytes.unsafe_to_string s
| _ -> Res_utf8.encodeCodePoint c
else Res_utf8.encodeCodePoint c
in
Doc.text ("'" ^ str ^ "'")

let printOptionalLabel attrs =
Expand Down