on fcb9617 help sign in
Data/Aeson/Encode/Builder.hs+26−23
since splitsnapshots
unifiedsplit
@@ -1,4 +1,5 @@
1−{-# LANGUAGE BangPatterns, OverloadedStrings #-}
1+{-# LANGUAGE BangPatterns #-}
2+{-# LANGUAGE OverloadedStrings #-}
2
3
3-- |
4-- |
4-- Module: Data.Aeson.Encode.Builder
5-- Module: Data.Aeson.Encode.Builder
@@ -35,22 +36,23 @@ module Data.Aeson.Encode.Builder
35 , ascii5
36 , ascii5
36 ) where
37 ) where
37
38
38−import Data.Aeson.Internal.Time
39+import Data.Aeson.Internal.Time
39−import Data.Aeson.Types.Internal (Encoding(..), Value(..))
40+import Data.Aeson.Types.Internal (Encoding (..), Value (..))
40−import Data.ByteString.Builder as B
41+import Data.ByteString.Builder as B
41−import Data.ByteString.Builder.Prim as BP
42+import Data.ByteString.Builder.Prim as BP
42−import Data.ByteString.Builder.Scientific (scientificBuilder)
43+import Data.ByteString.Builder.Scientific (scientificBuilder)
43−import Data.Char (chr, ord)
44+import Data.Char (chr, ord)
45+import qualified Data.HashMap.Strict as HMS
44−import Data.Monoid ((<>))
46+import Data.Monoid ((<>))
45−import Data.Scientific (Scientific, base10Exponent, coefficient)
47+import Data.Scientific (Scientific, base10Exponent,
48+ coefficient)
49+import qualified Data.Text as T
50+import qualified Data.Text.Encoding as TE
46−import Data.Time (UTCTime(..))
51+import Data.Time (UTCTime (..))
47−import Data.Time.Calendar (Day(..), toGregorian)
52+import Data.Time.Calendar (Day (..), toGregorian)
48−import Data.Time.LocalTime
53+import Data.Time.LocalTime
54+import qualified Data.Vector as V
49−import Data.Word (Word8)
55+import Data.Word (Word8)
50−import qualified Data.HashMap.Strict as HMS
51−import qualified Data.Text as T
52−import qualified Data.Text.Encoding as TE
53−import qualified Data.Vector as V
54
56
55-- | Encode a JSON value to a "Data.ByteString" 'B.Builder'.
57-- | Encode a JSON value to a "Data.ByteString" 'B.Builder'.
56--
58--
@@ -181,12 +183,13 @@ day dd = encodeYear yr <>
181 !(T dh dl) = twoDigits d
183 !(T dh dl) = twoDigits d
182 encodeYear y
184 encodeYear y
183 | y >= 1000 = B.integerDec y
185 | y >= 1000 = B.integerDec y
184− | y > 0 =
186+ | y >= 0 = BP.primBounded (ascii4 (padYear y)) ()
187+ | y >= -999 = BP.primBounded (ascii5 ('-',padYear (- y))) ()
188+ | otherwise = B.integerDec y
189+ padYear y =
185− let (ab,c) = fromIntegral y `quotRem` 10
190+ let (ab,c) = fromIntegral y `quotRem` 10
186− (a,b) = ab `quotRem` 10
191+ (a,b) = ab `quotRem` 10
187− in BP.primBounded (ascii4 ('0',(digit a,(digit b,digit c)))) ()
192+ in ('0',(digit a,(digit b,digit c)))
188− | otherwise =
189− error "Data.Aeson.Encode.Builder.day: years BCE not supported"
190{-# INLINE day #-}
193{-# INLINE day #-}
191
194
192timeOfDay :: TimeOfDay -> Builder
195timeOfDay :: TimeOfDay -> Builder
aeson.cabal+4−5
@@ -1,5 +1,5 @@
1name: aeson
1name: aeson
2−version: 0.11.2.0
2+version: 0.11.2.1
3license: BSD3
3license: BSD3
4license-file: LICENSE
4license-file: LICENSE
5category: Text, Web, JSON
5category: Text, Web, JSON
@@ -113,7 +113,7 @@ library
113
113
114 if !impl(ghc >= 7.10)
114 if !impl(ghc >= 7.10)
115 -- `Numeric.Natural` is available in base only since GHC 7.10 / base 4.8
115 -- `Numeric.Natural` is available in base only since GHC 7.10 / base 4.8
116− build-depends: nats >=1 && <1.1
116+ build-depends: nats >=1 && <1.2
117
117
118 if flag(old-locale)
118 if flag(old-locale)
119 build-depends: time < 1.5, old-locale
119 build-depends: time < 1.5, old-locale
@@ -121,7 +121,6 @@ library
121 build-depends: time >= 1.5
121 build-depends: time >= 1.5
122
122
123 if flag(developer)
123 if flag(developer)
124− ghc-options: -Werror
125 ghc-prof-options: -auto-all
124 ghc-prof-options: -auto-all
126
125
127 ghc-options: -O2 -Wall
126 ghc-options: -O2 -Wall
@@ -150,7 +149,7 @@ test-suite tests
150
149
151 build-depends:
150 build-depends:
152 HUnit,
151 HUnit,
153− QuickCheck >= 2.7 && <2.8.3,
152+ QuickCheck >= 2.7 && <2.10,
154 aeson,
153 aeson,
155 attoparsec,
154 attoparsec,
156 base,
155 base,
@@ -179,7 +178,7 @@ test-suite tests
179 build-depends: time >= 1.5
178 build-depends: time >= 1.5
180
179
181 if !impl(ghc >= 7.10)
180 if !impl(ghc >= 7.10)
182− build-depends: nats >=1 && <1.1
181+ build-depends: nats >=1 && <1.2
183
182
184source-repository head
183source-repository head
185 type: git
184 type: git
tests/Instances.hs+5−3
@@ -142,12 +142,17 @@ instance ApproxEq Char where
142instance (ApproxEq a) => ApproxEq [a] where
142instance (ApproxEq a) => ApproxEq [a] where
143 a =~ b = length a == length b && all (uncurry (=~)) (zip a b)
143 a =~ b = length a == length b && all (uncurry (=~)) (zip a b)
144
144
145+#if !MIN_VERSION_QuickCheck(2,9,0)
145instance Arbitrary Version where
146instance Arbitrary Version where
146 arbitrary = makeVersion . fmap getNonNegative <$> resize 4 (listOf1 arbitrary)
147 arbitrary = makeVersion . fmap getNonNegative <$> resize 4 (listOf1 arbitrary)
147
148
148instance Arbitrary a => Arbitrary (NonEmpty a) where
149instance Arbitrary a => Arbitrary (NonEmpty a) where
149 arbitrary = (:|) <$> arbitrary <*> arbitrary
150 arbitrary = (:|) <$> arbitrary <*> arbitrary
150
151
152+instance Arbitrary a => Arbitrary (Const a b) where
153+ arbitrary = Const <$> arbitrary
154+#endif
155+
151-- Version tags are deprecated, so we avoid using them in the Arbitrary
156-- Version tags are deprecated, so we avoid using them in the Arbitrary
152-- instance. However, the recommended constructor 'makeVersion' is not
157-- instance. However, the recommended constructor 'makeVersion' is not
153-- exported by "Data.Version" until base-4.8.0.0. For previous versions,
158-- exported by "Data.Version" until base-4.8.0.0. For previous versions,
@@ -168,6 +173,3 @@ instance Arbitrary (Proxy a) where
168
173
169instance Arbitrary b => Arbitrary (Tagged a b) where
174instance Arbitrary b => Arbitrary (Tagged a b) where
170 arbitrary = Tagged <$> arbitrary
175 arbitrary = Tagged <$> arbitrary
171−
172−instance Arbitrary a => Arbitrary (Const a b) where
173− arbitrary = Const <$> arbitrary