@@ -1,7 +1,10 @@
1{-# LANGUAGE FlexibleInstances #-}
1{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE TypeSynonymInstances #-}
3{-# LANGUAGE TypeSynonymInstances #-}
4−module Servant.Common.Text where
4+module Servant.Common.Text
6import Data.String.Conversions
9import Data.String.Conversions
7import Data.Int
10import Data.Int
@@ -9,11 +12,11 @@ import Data.Text
9import Data.Text.Read
12import Data.Text.Read
10import Data.Word
13import Data.Word
12−-- | For getting values from url captures, get parameters
15+-- | For getting values from url captures and query string parameters
13class FromText a where
16class FromText a where
14 fromText :: Text -> Maybe a
17 fromText :: Text -> Maybe a
16−-- | For putting values in paths, get parameters
19+-- | For putting values in paths and query string parameters
17class ToText a where
20class ToText a where
18 toText :: a -> Text
21 toText :: a -> Text
@@ -29,11 +32,18 @@ instance FromText String where
29instance ToText String where
32instance ToText String where
30 toText = cs
33 toText = cs
36+-- > fromText "true" = Just True
37+-- > fromText "false" = Just False
38+-- > fromText _ = Nothing
32instance FromText Bool where
39instance FromText Bool where
33 fromText "true" = Just True
40 fromText "true" = Just True
34 fromText "false" = Just False
41 fromText "false" = Just False
35 fromText _ = Nothing
42 fromText _ = Nothing
45+-- > toText True = "true"
46+-- > toText False = "false"
37instance ToText Bool where
47instance ToText Bool where
38 toText True = "true"
48 toText True = "true"
39 toText False = "false"
49 toText False = "false"