git.iko.soy/typeable/bytestring-conversion
on master help sign in
8 files changed+142−25
since splitsnapshots
unifiedsplit
.travis.yml+84 CHANGELOG.txt+7 README.md+2−1 bytestring-conversion.cabal+22−20 src/Data/ByteString/Conversion/From.hs+11 src/Data/ByteString/Conversion/Internal.hs+1 src/Data/ByteString/Conversion/To.hs+14−4 test/Properties.hs+1
.travis.ymlnew file+84
@@ -0,0 +1,84 @@
1+# This file has been generated -- see https://github.com/hvr/multi-ghc-travis
2+language: c
3+sudo: false
4+
5+cache:
6+ directories:
7+ - $HOME/.cabsnap
8+ - $HOME/.cabal/packages
9+
10+before_cache:
11+ - rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log
12+ - rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.tar
13+
14+matrix:
15+ include:
16+ - env: CABALVER=1.18 GHCVER=7.4.2
17+ compiler: ": #GHC 7.4.2"
18+ addons: {apt: {packages: [cabal-install-1.18,ghc-7.4.2], sources: [hvr-ghc]}}
19+ - env: CABALVER=1.18 GHCVER=7.6.3
20+ compiler: ": #GHC 7.6.3"
21+ addons: {apt: {packages: [cabal-install-1.18,ghc-7.6.3], sources: [hvr-ghc]}}
22+ - env: CABALVER=1.18 GHCVER=7.8.4
23+ compiler: ": #GHC 7.8.4"
24+ addons: {apt: {packages: [cabal-install-1.18,ghc-7.8.4], sources: [hvr-ghc]}}
25+ - env: CABALVER=1.22 GHCVER=7.10.3
26+ compiler: ": #GHC 7.10.3"
27+ addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.3], sources: [hvr-ghc]}}
28+
29+before_install:
30+ - unset CC
31+ - export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
32+
33+install:
34+ - cabal --version
35+ - echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"
36+ - if [ -f $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz ];
37+ then
38+ zcat $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz >
39+ $HOME/.cabal/packages/hackage.haskell.org/00-index.tar;
40+ fi
41+ - travis_retry cabal update -v
42+ - sed -i 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config
43+ - cabal install --only-dependencies --enable-tests --enable-benchmarks --dry -v > installplan.txt
44+ - sed -i -e '1,/^Resolving /d' installplan.txt; cat installplan.txt
45+
46+# check whether current requested install-plan matches cached package-db snapshot
47+ - if diff -u installplan.txt $HOME/.cabsnap/installplan.txt;
48+ then
49+ echo "cabal build-cache HIT";
50+ rm -rfv .ghc;
51+ cp -a $HOME/.cabsnap/ghc $HOME/.ghc;
52+ cp -a $HOME/.cabsnap/lib $HOME/.cabsnap/share $HOME/.cabsnap/bin $HOME/.cabal/;
53+ else
54+ echo "cabal build-cache MISS";
55+ rm -rf $HOME/.cabsnap;
56+ mkdir -p $HOME/.ghc $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin;
57+ cabal install --only-dependencies --enable-tests --enable-benchmarks;
58+ fi
59+
60+# snapshot package-db on cache miss
61+ - if [ ! -d $HOME/.cabsnap ];
62+ then
63+ echo "snapshotting package-db to build-cache";
64+ mkdir $HOME/.cabsnap;
65+ cp -a $HOME/.ghc $HOME/.cabsnap/ghc;
66+ cp -a $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin installplan.txt $HOME/.cabsnap/;
67+ fi
68+
69+# Here starts the actual work to be performed for the package under test;
70+# any command which exits with a non-zero exit code causes the build to fail.
71+script:
72+ - if [ -f configure.ac ]; then autoreconf -i; fi
73+ - cabal configure --enable-tests --enable-benchmarks -v2 # -v2 provides useful information for debugging
74+ - cabal build # this builds all libraries and executables (including tests/benchmarks)
75+ - cabal test
76+ - cabal sdist # tests that a source-distribution can be generated
77+
78+# Check that the resulting source distribution can be built & installed.
79+# If there are no other `.tar.gz` files in `dist`, this can be even simpler:
80+# `cabal install --force-reinstalls dist/*-*.tar.gz`
81+ - SRC_TGZ=$(cabal info . | awk '{print $2;exit}').tar.gz &&
82+ (cd dist && cabal install --force-reinstalls "$SRC_TGZ")
83+
84+# EOF
CHANGELOG.txtnew file+7
@@ -0,0 +1,7 @@
1+0.3.2
2+------
3+- GHC and `bytestring` version compatibility updates.
4+
5+0.3.1
6+------
7+- Use `blaze-textual` on Windows instead of `double-conversion`
README.md+2−1
@@ -1,4 +1,5 @@
11bytestring-conversion
22=====================
33
4−Type-classes to convert values to and from `ByteString`.
4+Type-classes to convert values to and from textual `ByteString` encodings.
5+
bytestring-conversion.cabal+22−20
@@ -1,32 +1,30 @@
11name: bytestring-conversion
2−version: 0.2
2+version: 0.3.2
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
9−homepage: https://github.com/twittner/bytestring-conversion/
10−bug-reports: https://github.com/twittner/bytestring-conversion/issues
11−stability: experimental
8+copyright: (C) 2014-2015 Toralf Wittner
9+homepage: https://gitlab.com/twittner/bytestring-conversion
10+bug-reports: https://gitlab.com/twittner/bytestring-conversion/issues
1211category: Data
1312build-type: Simple
1413cabal-version: >= 1.10
15−extra-source-files: README.md
14+extra-source-files: README.md, CHANGELOG.txt
1615
1716description:
1817 Defines the type-classes 'ToByteString' and 'FromByteString'
19− to convert values to and from ByteString.
18+ to convert values to and from textual 'ByteString' encodings.
2019
2120source-repository head
22− type: git
23− location: git://github.com/twittner/bytestring-conversion.git
21+ type: git
22+ location: git@gitlab.com:twittner/bytestring-conversion.git
2423
2524library
2625 default-language: Haskell2010
2726 hs-source-dirs: src
28− ghc-options: -Wall -O2 -fwarn-tabs -funbox-strict-fields
29− ghc-prof-options: -prof -auto-all
27+ ghc-options: -Wall -O2 -fwarn-tabs
3028
3129 exposed-modules:
3230 Data.ByteString.Conversion
@@ -37,12 +35,17 @@ library
3735 Data.ByteString.Conversion.Internal
3836
3937 build-depends:
40− base >= 4.5 && < 5.0
41− , attoparsec >= 0.10 && < 0.13
42− , bytestring >= 0.10.4 && < 0.11
43− , case-insensitive == 1.2.*
44− , double-conversion == 2.0.*
45− , text >= 0.11 && < 1.2
38+ base >= 4.5 && < 5.0
39+ , attoparsec >= 0.10 && < 1.0
40+ , bytestring >= 0.10.2 && < 1.0
41+ , case-insensitive >= 1.2 && < 2.0
42+ , text >= 0.11 && < 3.0
43+
44+ if os(windows)
45+ cpp-options: -DWINDOWS
46+ build-depends: blaze-textual >= 0.2 && < 0.3
47+ else
48+ build-depends: double-conversion >= 2.0 && < 3.0
4649
4750test-suite bytestring-conversion-tests
4851 type: exitcode-stdio-1.0
@@ -50,7 +53,6 @@ test-suite bytestring-conversion-tests
5053 hs-source-dirs: test
5154 main-is: Tests.hs
5255 ghc-options: -Wall -O2 -fwarn-tabs
53− ghc-prof-options: -prof -auto-all
5456
5557 other-modules:
5658 Properties
@@ -73,6 +75,6 @@ benchmark bytestring-conversion-bench
7375 base
7476 , bytestring
7577 , bytestring-conversion
76− , criterion >= 1.0.0.2 && < 1.1
78+ , criterion >= 1.0.0.2 && < 2.0
7779 , text
7880 , transformers
src/Data/ByteString/Conversion/From.hs+11
@@ -31,6 +31,8 @@ import Prelude hiding (elem)
3131import qualified Data.Attoparsec.ByteString.Lazy as Lazy
3232import qualified Data.ByteString.Lazy as Lazy
3333import qualified Data.Text as T
34+import qualified Data.Text.Lazy as TL
35+import qualified Data.Text.Lazy.Encoding as TL
3436
3537-- | Parse 'ByteString's.
3638class FromByteString a where
@@ -89,6 +91,10 @@ instance FromByteString [Char] where
8991instance FromByteString Text where
9092 parser = takeByteString >>= text
9193
94+-- | UTF-8 is assumed as encoding format.
95+instance FromByteString TL.Text where
96+ parser = takeLazyByteString >>= ltext
97+
9298instance FromByteString Bool where
9399 parser =
94100 satisfy (`elem` "tT") *> string "rue" *> pure True <|>
@@ -159,3 +165,8 @@ parseList = atEnd >>= \e ->
159165
160166text :: ByteString -> Parser Text
161167text = either (fail . ("Invalid UTF-8: " ++) . show) return . decodeUtf8'
168+{-# INLINE text #-}
169+
170+ltext :: Lazy.ByteString -> Parser TL.Text
171+ltext = either (fail . ("Invalid UTF-8: " ++) . show) return . TL.decodeUtf8'
172+{-# INLINE ltext #-}
src/Data/ByteString/Conversion/Internal.hs+1
@@ -9,6 +9,7 @@ module Data.ByteString.Conversion.Internal where
99import Control.Applicative
1010import Data.Bits (Bits)
1111import Text.Printf (PrintfArg)
12+import Prelude
1213
1314-- | Newtype wrapper to parse and produce integral numbers in
1415-- hexadecimal format
src/Data/ByteString/Conversion/To.hs+14−4
@@ -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
@@ -15,13 +16,11 @@ module Data.ByteString.Conversion.To
1516
1617import Data.ByteString (ByteString)
1718import Data.ByteString.Conversion.Internal
18−import Data.ByteString.Lazy.Builder
19−import Data.ByteString.Lazy.Builder.Extras hiding (runBuilder)
19+import Data.ByteString.Builder
20+import Data.ByteString.Builder.Extra hiding (runBuilder)
2021import Data.CaseInsensitive (CI, original)
21−import Data.Double.Conversion.Text
2222import Data.Int
2323import Data.List (intersperse)
24−import Data.Monoid
2524import Data.Text (Text)
2625import Data.Text.Encoding (encodeUtf8)
2726import Data.Word
@@ -32,6 +31,12 @@ import qualified Data.Text as T
3231import qualified Data.Text.Lazy as TL
3332import qualified Data.Text.Lazy.Encoding as TL
3433
34+#ifdef WINDOWS
35+import Blaze.Text.Double
36+#else
37+import Data.Double.Conversion.Text
38+#endif
39+
3540class ToByteString a where
3641 builder :: a -> Builder
3742
@@ -42,8 +47,13 @@ instance ToByteString Text where builder x = byteString $ encodeUtf8 x
4247instance ToByteString TL.Text where builder x = lazyByteString $ TL.encodeUtf8 x
4348instance ToByteString Char where builder x = builder $ T.singleton x
4449instance ToByteString [Char] where builder x = builder $ TL.pack x
50+#ifdef WINDOWS
51+instance ToByteString Float where builder x = double $ float2Double x
52+instance ToByteString Double where builder x = double x
53+#else
4554instance ToByteString Float where builder x = builder $ toShortest $ float2Double x
4655instance ToByteString Double where builder x = builder $ toShortest x
56+#endif
4757
4858instance ToByteString Int where builder x = intDec x
4959instance ToByteString Int8 where builder x = int8Dec x
test/Properties.hs+1
@@ -17,6 +17,7 @@ import Test.QuickCheck
1717import Test.Tasty
1818import Test.Tasty.QuickCheck
1919import Text.Printf
20+import Prelude
2021
2122tests :: TestTree
2223tests = testGroup "Properties"