on fcb9617 help sign in
3 files changed+35−31
since splitsnapshots
unifiedsplit
Data/Aeson/Encode/Builder.hs+26−23 aeson.cabal+4−5 tests/Instances.hs+5−3
Data/Aeson/Encode/Builder.hs+26−23
@@ -1,4 +1,5 @@
1−{-# LANGUAGE BangPatterns, OverloadedStrings #-}
1+{-# LANGUAGE BangPatterns #-}
2+{-# LANGUAGE OverloadedStrings #-}
23
34-- |
45-- Module: Data.Aeson.Encode.Builder
@@ -35,22 +36,23 @@ module Data.Aeson.Encode.Builder
3536 , ascii5
3637 ) where
3738
38−import Data.Aeson.Internal.Time
39−import Data.Aeson.Types.Internal (Encoding(..), Value(..))
40−import Data.ByteString.Builder as B
41−import Data.ByteString.Builder.Prim as BP
42−import Data.ByteString.Builder.Scientific (scientificBuilder)
43−import Data.Char (chr, ord)
44−import Data.Monoid ((<>))
45−import Data.Scientific (Scientific, base10Exponent, coefficient)
46−import Data.Time (UTCTime(..))
47−import Data.Time.Calendar (Day(..), toGregorian)
48−import Data.Time.LocalTime
49−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
39+import Data.Aeson.Internal.Time
40+import Data.Aeson.Types.Internal (Encoding (..), Value (..))
41+import Data.ByteString.Builder as B
42+import Data.ByteString.Builder.Prim as BP
43+import Data.ByteString.Builder.Scientific (scientificBuilder)
44+import Data.Char (chr, ord)
45+import qualified Data.HashMap.Strict as HMS
46+import Data.Monoid ((<>))
47+import Data.Scientific (Scientific, base10Exponent,
48+ coefficient)
49+import qualified Data.Text as T
50+import qualified Data.Text.Encoding as TE
51+import Data.Time (UTCTime (..))
52+import Data.Time.Calendar (Day (..), toGregorian)
53+import Data.Time.LocalTime
54+import qualified Data.Vector as V
55+import Data.Word (Word8)
5456
5557-- | Encode a JSON value to a "Data.ByteString" 'B.Builder'.
5658--
@@ -181,12 +183,13 @@ day dd = encodeYear yr <>
181183 !(T dh dl) = twoDigits d
182184 encodeYear y
183185 | y >= 1000 = B.integerDec y
184− | y > 0 =
185− let (ab,c) = fromIntegral y `quotRem` 10
186− (a,b) = ab `quotRem` 10
187− in BP.primBounded (ascii4 ('0',(digit a,(digit b,digit c)))) ()
188− | otherwise =
189− error "Data.Aeson.Encode.Builder.day: years BCE not supported"
186+ | y >= 0 = BP.primBounded (ascii4 (padYear y)) ()
187+ | y >= -999 = BP.primBounded (ascii5 ('-',padYear (- y))) ()
188+ | otherwise = B.integerDec y
189+ padYear y =
190+ let (ab,c) = fromIntegral y `quotRem` 10
191+ (a,b) = ab `quotRem` 10
192+ in ('0',(digit a,(digit b,digit c)))
190193{-# INLINE day #-}
191194
192195timeOfDay :: TimeOfDay -> Builder
aeson.cabal+4−5
@@ -1,5 +1,5 @@
11name: aeson
2−version: 0.11.2.0
2+version: 0.11.2.1
33license: BSD3
44license-file: LICENSE
55category: Text, Web, JSON
@@ -113,7 +113,7 @@ library
113113
114114 if !impl(ghc >= 7.10)
115115 -- `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
117117
118118 if flag(old-locale)
119119 build-depends: time < 1.5, old-locale
@@ -121,7 +121,6 @@ library
121121 build-depends: time >= 1.5
122122
123123 if flag(developer)
124− ghc-options: -Werror
125124 ghc-prof-options: -auto-all
126125
127126 ghc-options: -O2 -Wall
@@ -150,7 +149,7 @@ test-suite tests
150149
151150 build-depends:
152151 HUnit,
153− QuickCheck >= 2.7 && <2.8.3,
152+ QuickCheck >= 2.7 && <2.10,
154153 aeson,
155154 attoparsec,
156155 base,
@@ -179,7 +178,7 @@ test-suite tests
179178 build-depends: time >= 1.5
180179
181180 if !impl(ghc >= 7.10)
182− build-depends: nats >=1 && <1.1
181+ build-depends: nats >=1 && <1.2
183182
184183source-repository head
185184 type: git
tests/Instances.hs+5−3
@@ -142,12 +142,17 @@ instance ApproxEq Char where
142142instance (ApproxEq a) => ApproxEq [a] where
143143 a =~ b = length a == length b && all (uncurry (=~)) (zip a b)
144144
145+#if !MIN_VERSION_QuickCheck(2,9,0)
145146instance Arbitrary Version where
146147 arbitrary = makeVersion . fmap getNonNegative <$> resize 4 (listOf1 arbitrary)
147148
148149instance Arbitrary a => Arbitrary (NonEmpty a) where
149150 arbitrary = (:|) <$> arbitrary <*> arbitrary
150151
152+instance Arbitrary a => Arbitrary (Const a b) where
153+ arbitrary = Const <$> arbitrary
154+#endif
155+
151156-- Version tags are deprecated, so we avoid using them in the Arbitrary
152157-- instance. However, the recommended constructor 'makeVersion' is not
153158-- exported by "Data.Version" until base-4.8.0.0. For previous versions,
@@ -168,6 +173,3 @@ instance Arbitrary (Proxy a) where
168173
169174instance Arbitrary b => Arbitrary (Tagged a b) where
170175 arbitrary = Tagged <$> arbitrary
171−
172−instance Arbitrary a => Arbitrary (Const a b) where
173− arbitrary = Const <$> arbitrary