on master help sign in
Merge pull request #11 from wereHamster/to-from-text

{from,to}Text

commite558bcd5de7b2a96317758eee60dfa0783d7c190 authorAntoine Latter <aslatter@gmail.com> dateFri 29 May 2015, 05:57 (11 years ago) parentf51b6ef1cf04b1
8 files changed+51−48
.travis.yml+19−9 travis-scripts/build.sh+15−25 travis-scripts/install.sh−13 uuid-types/Data/UUID/Types.hs+2 uuid-types/Data/UUID/Types/Internal.hs+10 uuid-types/uuid-types.cabal+2−1 uuid/Data/UUID.hs+2 uuid/uuid.cabal+1
.travis.yml+19−9
@@ -1,12 +1,22 @@
1−language: haskell
2−ghc:
3− - 7.10
4− - 7.8
5− - 7.6
6− - 7.4
1+env:
2+ - CABALVER=1.18 GHCVER=7.6.3
3+ - CABALVER=1.18 GHCVER=7.8.4
4+ - CABALVER=1.22 GHCVER=7.10.1
5+ - CABALVER=head GHCVER=head
6+
7+matrix:
8+ allow_failures:
9+ - env: CABALVER=head GHCVER=head
710
8−sudo: false
911install:
10− - ./travis-scripts/install.sh
12+ - travis_retry sudo add-apt-repository -y ppa:hvr/ghc
13+ - travis_retry sudo apt-get update
14+ - travis_retry sudo apt-get install cabal-install-$CABALVER ghc-$GHCVER
15+ - export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
16+ - cabal --version
17+ - echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"
18+ - travis_retry cabal update
19+ - cabal install --only-dependencies --enable-tests --enable-benchmarks uuid-types/uuid-types.cabal uuid/uuid.cabal
20+
1121script:
12− - ./travis-scripts/build.sh
22+ - for p in uuid-types uuid; do ./travis-scripts/build.sh $p; done
travis-scripts/build.sh+15−25
@@ -1,27 +1,17 @@
1−#!/usr/bin/env sh
2−echo "==========================================="
3−echo "= Building and installing 'uuid-types'... ="
4−echo "==========================================="
1+#!/bin/sh
52
6−# We install here because "uuid" is going to need it.
7−(cd "uuid-types" && \
8− cabal configure --enable-tests && \
9− cabal build && \
10− cabal test && \
11− cabal install) || exit 1
3+cd $1
124
13−echo "========================================="
14−echo "= Installing dependencies for 'uuid'... ="
15−echo "========================================="
16−
17−(cd "uuid" && \
18− cabal install --dependencies-only --enable-tests) || exit 1
19−
20−echo "======================"
21−echo "= Building 'uuid'... ="
22−echo "======================"
23−
24−(cd "uuid" && \
25− cabal configure --enable-tests && \
26− cabal build && \
27− cabal test) || exit 1
5+cabal configure --enable-tests --enable-benchmarks -v2
6+cabal build
7+cabal test
8+cabal check
9+cabal sdist
10+export SRC_TGZ=$(cabal info . | awk '{print $2 ".tar.gz";exit}') ;
11+cd dist/;
12+if [ -f "$SRC_TGZ" ]; then
13+ cabal install --force-reinstalls "$SRC_TGZ";
14+else
15+ echo "expected '$SRC_TGZ' not found";
16+ exit 1;
17+fi
travis-scripts/install.shdeleted−13
@@ -1,13 +0,0 @@
1−#!/usr/bin/env sh
2−
3−# We can only pre-install dependencies for the "uuid-types" project
4−# since the "uuid" project depends on "uuid-types". We could use
5−# sandboxing and "add-source", but it seems quite wasteful of
6−# CPU-cycles to compile everything twice for each version of GHC.
7−
8−echo "==============================================="
9−echo "= Installing dependencies for 'uuid-types'... ="
10−echo "==============================================="
11−
12−(cd "uuid-types" && \
13− cabal install --dependencies-only --enable-tests) || exit 1
uuid-types/Data/UUID/Types.hs+2
@@ -18,6 +18,8 @@ See <http://tools.ietf.org/html/rfc4122> for the specification.
1818module Data.UUID.Types(UUID
1919 ,toString
2020 ,fromString
21+ ,toText
22+ ,fromText
2123 ,toASCIIBytes
2224 ,fromASCIIBytes
2325 ,toLazyASCIIBytes
uuid-types/Data/UUID/Types/Internal.hs+10
@@ -20,6 +20,8 @@ module Data.UUID.Types.Internal
2020 ,toByteString
2121 ,fromString
2222 ,toString
23+ ,fromText
24+ ,toText
2325 ,fromWords
2426 ,toWords
2527 ,toList
@@ -61,6 +63,8 @@ import qualified Data.ByteString as B
6163import qualified Data.ByteString.Internal as BI
6264import qualified Data.ByteString.Lazy as BL
6365import qualified Data.ByteString.Unsafe as BU
66+import Data.Text (Text)
67+import qualified Data.Text as T
6468
6569import Data.UUID.Types.Internal.Builder
6670
@@ -307,6 +311,12 @@ toString (UUID w0 w1 w2 w3) = hexw w0 $ hexw' w1 $ hexw' w2 $ hexw w3 ""
307311 hexn :: Word32 -> Int -> Char
308312 hexn w r = intToDigit $ fromIntegral ((w `shiftR` r) .&. 0xf)
309313
314+fromText :: Text -> Maybe UUID
315+fromText = fromString . T.unpack
316+
317+toText :: UUID -> Text
318+toText = T.pack . toString
319+
310320-- | Convert a UUID into a hyphentated string using lower-case letters, packed
311321-- as ASCII bytes into `B.ByteString`.
312322--
uuid-types/uuid-types.cabal+2−1
@@ -32,7 +32,8 @@ Library
3232 bytestring >= 0.9 && < 0.11,
3333 deepseq >= 1.3 && < 1.5,
3434 hashable (>= 1.1.1.0 && < 1.2.0) || (>= 1.2.1 && < 1.3),
35− random >= 1.0.1 && < 1.2
35+ random >= 1.0.1 && < 1.2,
36+ text >= 1 && < 1.3
3637
3738 Exposed-Modules:
3839 Data.UUID.Types
uuid/Data/UUID.hs+2
@@ -26,6 +26,8 @@ MAC address and current system time in "Data.UUID.V1".
2626module Data.UUID(UUID
2727 ,toString
2828 ,fromString
29+ ,toText
30+ ,fromText
2931 ,toASCIIBytes
3032 ,fromASCIIBytes
3133 ,toLazyASCIIBytes
uuid/uuid.cabal+1
@@ -33,6 +33,7 @@ Library
3333 network-info == 0.2.*,
3434 random >= 1.0.1 && < 1.2,
3535 time >= 1.1 && < 1.6,
36+ text >= 1 && < 1.3,
3637 uuid-types >= 1.0 && < 2
3738
3839 Exposed-Modules: