on master help sign in
Hoist escapeAscii to top level
97bef52Bryan O'Sullivan
Data/Aeson/Encode/Builder.hs+13−12
@@ -88,23 +88,24 @@ text t = B.char8 '"' <> unquoted t <> B.char8 '"'
88-- | Encode a JSON string, without enclosing quotes.
88-- | Encode a JSON string, without enclosing quotes.
89unquoted :: T.Text -> Builder
89unquoted :: T.Text -> Builder
90unquoted t = TE.encodeUtf8BuilderEscaped escapeAscii t
90unquoted t = TE.encodeUtf8BuilderEscaped escapeAscii t
91− where
92− escapeAscii :: BP.BoundedPrim Word8
93− escapeAscii =
94− BP.condB (== c2w '\\' ) (ascii2 ('\\','\\')) $
95− BP.condB (== c2w '\"' ) (ascii2 ('\\','"' )) $
96− BP.condB (>= c2w '\x20') (BP.liftFixedToBounded BP.word8) $
97− BP.condB (== c2w '\n' ) (ascii2 ('\\','n' )) $
98− BP.condB (== c2w '\r' ) (ascii2 ('\\','r' )) $
99− BP.condB (== c2w '\t' ) (ascii2 ('\\','t' )) $
100− (BP.liftFixedToBounded hexEscape) -- fallback for chars < 0x20
101−
102− c2w = fromIntegral . ord
103
91
92+escapeAscii :: BP.BoundedPrim Word8
93+escapeAscii =
94+ BP.condB (== c2w '\\' ) (ascii2 ('\\','\\')) $
95+ BP.condB (== c2w '\"' ) (ascii2 ('\\','"' )) $
96+ BP.condB (>= c2w '\x20') (BP.liftFixedToBounded BP.word8) $
97+ BP.condB (== c2w '\n' ) (ascii2 ('\\','n' )) $
98+ BP.condB (== c2w '\r' ) (ascii2 ('\\','r' )) $
99+ BP.condB (== c2w '\t' ) (ascii2 ('\\','t' )) $
100+ (BP.liftFixedToBounded hexEscape) -- fallback for chars < 0x20
101+ where
104 hexEscape :: BP.FixedPrim Word8
102 hexEscape :: BP.FixedPrim Word8
105 hexEscape = (\c -> ('\\', ('u', fromIntegral c))) BP.>$<
103 hexEscape = (\c -> ('\\', ('u', fromIntegral c))) BP.>$<
106 BP.char8 >*< BP.char8 >*< BP.word16HexFixed
104 BP.char8 >*< BP.char8 >*< BP.word16HexFixed
107
105
106+c2w :: Char -> Word8
107+c2w c = fromIntegral (ord c)
108+
108-- | Encode a JSON number.
109-- | Encode a JSON number.
109number :: Scientific -> Builder
110number :: Scientific -> Builder
110number s
111number s