on master help sign in
Hoist escapeAscii to top level
commit97bef5292dc7f211956da9271725bb183c05aade authorBryan O'Sullivan <bos@serpentine.com> dateMon 6 Jul 2015, 17:00 (11 years ago) parent6b4f7a9
1 file changed+13−12
Data/Aeson/Encode/Builder.hs+13−12
Data/Aeson/Encode/Builder.hs+13−12
@@ -88,23 +88,24 @@ text t = B.char8 '"' <> unquoted t <> B.char8 '"'
8888-- | Encode a JSON string, without enclosing quotes.
8989unquoted :: T.Text -> Builder
9090unquoted 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
10391
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
104102 hexEscape :: BP.FixedPrim Word8
105103 hexEscape = (\c -> ('\\', ('u', fromIntegral c))) BP.>$<
106104 BP.char8 >*< BP.char8 >*< BP.word16HexFixed
107105
106+c2w :: Char -> Word8
107+c2w c = fromIntegral (ord c)
108+
108109-- | Encode a JSON number.
109110number :: Scientific -> Builder
110111number s