on master help sign in
Use the Builder from bytestring >= 0.10

Allow building with blaze-builder and older versions of bytestring if the blaze-builder flag is specified.

commit497f9509a08f87792397eb8fb07e7e7d612e48f9 authorBas van Dijk <v.dijk.bas@gmail.com> dateSun 15 Sep 2013, 20:14 (13 years ago) parentf32f86b
2 files changed+46−8
Data/Aeson/Parser/Internal.hs+36−7 aeson.cabal+10−1
Data/Aeson/Parser/Internal.hs+36−7
@@ -1,4 +1,4 @@
1−{-# LANGUAGE BangPatterns, OverloadedStrings #-}
1+{-# LANGUAGE CPP, BangPatterns, OverloadedStrings #-}
22
33-- |
44-- Module: Data.Aeson.Parser.Internal
@@ -28,9 +28,19 @@ module Data.Aeson.Parser.Internal
2828 , eitherDecodeStrictWith
2929 ) where
3030
31−import Blaze.ByteString.Builder (fromByteString, toByteString)
31+#if defined(USE_BLAZE_BUILDER)
32+import Blaze.ByteString.Builder (Builder, fromByteString, toByteString)
3233import Blaze.ByteString.Builder.Char.Utf8 (fromChar)
3334import Blaze.ByteString.Builder.Word (fromWord8)
35+#else
36+#if MIN_VERSION_bytestring(0,10,2)
37+import Data.ByteString.Builder
38+#else
39+import Data.ByteString.Lazy.Builder
40+#endif
41+ (Builder, byteString, toLazyByteString, charUtf8, word8)
42+#endif
43+
3444import Control.Applicative as A
3545import Data.Aeson.Types (Result(..), Value(..))
3646import Data.Attoparsec.Char8 hiding (Result)
@@ -203,24 +213,24 @@ unescape = toByteString <$> go mempty where
203213 if slash /= backslash || escape == 255
204214 then fail "invalid JSON escape sequence"
205215 else do
206− let cont m = go (acc `mappend` fromByteString h `mappend` m)
216+ let cont m = go (acc `mappend` byteString h `mappend` m)
207217 {-# INLINE cont #-}
208218 if t /= 117 -- 'u'
209− then cont (fromWord8 (B.unsafeIndex mapping escape))
219+ then cont (word8 (B.unsafeIndex mapping escape))
210220 else do
211221 a <- hexQuad
212222 if a < 0xd800 || a > 0xdfff
213− then cont (fromChar (chr a))
223+ then cont (charUtf8 (chr a))
214224 else do
215225 b <- Z.string "\\u" *> hexQuad
216226 if a <= 0xdbff && b >= 0xdc00 && b <= 0xdfff
217227 then let !c = ((a - 0xd800) `shiftL` 10) +
218228 (b - 0xdc00) + 0x10000
219− in cont (fromChar (chr c))
229+ in cont (charUtf8 (chr c))
220230 else fail "invalid UTF-16 surrogates"
221231 done <- Z.atEnd
222232 if done
223− then return (acc `mappend` fromByteString h)
233+ then return (acc `mappend` byteString h)
224234 else rest
225235 mapping = "\"\\/\n\t\b\r\f"
226236
@@ -305,3 +315,22 @@ jsonEOF = json <* skipSpace <* endOfInput
305315-- end-of-input. See also: 'json''.
306316jsonEOF' :: Parser Value
307317jsonEOF' = json' <* skipSpace <* endOfInput
318+
319+#if defined(USE_BLAZE_BUILDER)
320+byteString :: ByteString -> Builder
321+byteString = fromByteString
322+{-# INLINE byteString #-}
323+
324+charUtf8 :: Char -> Builder
325+charUtf8 = fromChar
326+{-# INLINE charUtf8 #-}
327+
328+word8 :: Word8 -> Builder
329+word8 = fromWord8
330+{-# INLINE word8 #-}
331+
332+#else
333+toByteString :: Builder -> ByteString
334+toByteString = L.toStrict . toLazyByteString
335+{-# INLINE toByteString #-}
336+#endif
aeson.cabal+10−1
@@ -91,6 +91,10 @@ flag developer
9191 description: operate in developer mode
9292 default: False
9393
94+flag blaze-builder
95+ description: Use blaze-builder instead of bytestring >= 0.10
96+ default: False
97+
9498library
9599 exposed-modules:
96100 Data.Aeson
@@ -115,7 +119,6 @@ library
115119 build-depends:
116120 attoparsec >= 0.8.6.1,
117121 base == 4.*,
118− blaze-builder >= 0.2.1.4,
119122 bytestring,
120123 containers,
121124 deepseq,
@@ -129,6 +132,12 @@ library
129132 unordered-containers >= 0.1.3.0,
130133 vector >= 0.7.1
131134
135+ if flag(blaze-builder)
136+ build-depends: blaze-builder >= 0.2.1.4
137+ cpp-options: -DUSE_BLAZE_BUILDER
138+ else
139+ build-depends: bytestring >= 0.10
140+
132141 if flag(developer)
133142 ghc-options: -Werror
134143 ghc-prof-options: -auto-all