git.iko.soy/typeable/bytestring-conversion
on master help sign in
Merge branch 'kantp-blaze-textual'
commitc8a75f30f3e44a20cbcef4c18c04f971b54e7980 authorToralf Wittner <tw@dtex.org> dateWed 1 Jul 2015, 00:12 (11 years ago) parent5ededa3e8751a5
2 files changed+21−6
bytestring-conversion.cabal+9−5 src/Data/ByteString/Conversion/To.hs+12−1
bytestring-conversion.cabal+9−5
@@ -1,11 +1,11 @@
11name: bytestring-conversion
2−version: 0.3.0
2+version: 0.3.1
33synopsis: Type-classes to convert values to and from ByteString.
4−license: OtherLicense
4+license: MPL-2.0
55license-file: LICENSE
66author: Toralf Wittner
77maintainer: Toralf Wittner <tw@dtex.org>
8−copyright: (c) 2014 Toralf Wittner
8+copyright: (C) 2014-2015 Toralf Wittner
99homepage: https://github.com/twittner/bytestring-conversion/
1010bug-reports: https://github.com/twittner/bytestring-conversion/issues
1111stability: experimental
@@ -26,7 +26,6 @@ library
2626 default-language: Haskell2010
2727 hs-source-dirs: src
2828 ghc-options: -Wall -O2 -fwarn-tabs -funbox-strict-fields
29− ghc-prof-options: -prof -auto-all
3029
3130 exposed-modules:
3231 Data.ByteString.Conversion
@@ -41,9 +40,14 @@ library
4140 , attoparsec >= 0.10 && < 1.0
4241 , bytestring >= 0.10.4 && < 1.0
4342 , case-insensitive >= 1.2 && < 2.0
44− , double-conversion >= 2.0 && < 3.0
4543 , text >= 0.11 && < 2.0
4644
45+ if os(windows)
46+ cpp-options: -DWINDOWS
47+ build-depends: blaze-textual >= 0.2 && < 0.3
48+ else
49+ build-depends: double-conversion >= 2.0 && < 3.0
50+
4751test-suite bytestring-conversion-tests
4852 type: exitcode-stdio-1.0
4953 default-language: Haskell2010
src/Data/ByteString/Conversion/To.hs+12−1
@@ -3,6 +3,7 @@
33-- file, You can obtain one at http://mozilla.org/MPL/2.0/.
44
55{-# LANGUAGE BangPatterns #-}
6+{-# LANGUAGE CPP #-}
67{-# LANGUAGE OverloadedStrings #-}
78{-# LANGUAGE FlexibleInstances #-}
89
@@ -18,7 +19,6 @@ import Data.ByteString.Conversion.Internal
1819import Data.ByteString.Lazy.Builder
1920import Data.ByteString.Lazy.Builder.Extras hiding (runBuilder)
2021import Data.CaseInsensitive (CI, original)
21−import Data.Double.Conversion.Text
2222import Data.Int
2323import Data.List (intersperse)
2424import Data.Monoid
@@ -32,6 +32,12 @@ import qualified Data.Text as T
3232import qualified Data.Text.Lazy as TL
3333import qualified Data.Text.Lazy.Encoding as TL
3434
35+#ifdef WINDOWS
36+import Blaze.Text.Double
37+#else
38+import Data.Double.Conversion.Text
39+#endif
40+
3541class ToByteString a where
3642 builder :: a -> Builder
3743
@@ -42,8 +48,13 @@ instance ToByteString Text where builder x = byteString $ encodeUtf8 x
4248instance ToByteString TL.Text where builder x = lazyByteString $ TL.encodeUtf8 x
4349instance ToByteString Char where builder x = builder $ T.singleton x
4450instance ToByteString [Char] where builder x = builder $ TL.pack x
51+#ifdef WINDOWS
52+instance ToByteString Float where builder x = double $ float2Double x
53+instance ToByteString Double where builder x = double x
54+#else
4555instance ToByteString Float where builder x = builder $ toShortest $ float2Double x
4656instance ToByteString Double where builder x = builder $ toShortest x
57+#endif
4758
4859instance ToByteString Int where builder x = intDec x
4960instance ToByteString Int8 where builder x = int8Dec x