on master help sign in
Add {to,from}Text to uuid-types
commit1cf04b10fb0526f964078bf8cf7c735d587deb89 authorTomas Carnecky <tomas.carnecky@gmail.com> dateFri 29 May 2015, 12:04 (11 years ago) parent255907d
5 files changed+17−1
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
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: