def esc.char

cswap-bend-cli@0.1.0.0 · json/quote.bend:25

import cswap-bend-cli@0.1.0.0/json/quote.bend as Quote
import Base
import cswap-bend-cli@0.1.0.0/json/lex.bend as Lex

25# One char as Python's encoder writes it inside quotes. ensure_ascii escapes
26# everything above `~` (U+007F included); otherwise only controls.
27def esc.char(+ascii: Bool, +c: U32) -> String:
28  Lex.sel.s(U32.is_eq(c, 34), "\\\"",
29  Lex.sel.s(U32.is_eq(c, 92), "\\\\",
30  Lex.sel.s(U32.is_eq(c, 10), "\\n",
31  Lex.sel.s(U32.is_eq(c, 13), "\\r",
32  Lex.sel.s(U32.is_eq(c, 9), "\\t",
33  Lex.sel.s(U32.is_eq(c, 8), "\\b",
34  Lex.sel.s(U32.is_eq(c, 12), "\\f",
35  Lex.sel.s(U32.is_eq(c, 127), Lex.sel.s(ascii, uesc(127), SCon{Chr{127}, SNil{}}), esc.rest(ascii, c)))))))))

Uses (8)

Used by (1)