1{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE TypeSynonymInstances #-}
4module Servant.Common.Text
9import Data.String.Conversions ( cs )
10import Data.Int ( Int8, Int16, Int32, Int64 )
11import Data.Text ( Text )
12import Data.Text.Read ( rational, signed, decimal, Reader )
13import Data.Word ( Word, Word8, Word16, Word32, Word64 )
15-- | For getting values from url captures and query string parameters
17 fromText :: Text -> Maybe a
19-- | For putting values in paths and query string parameters
23instance FromText Text where
26instance ToText Text where
29instance FromText String where
32instance ToText String where
36-- > fromText "true" = Just True
37-- > fromText "false" = Just False
38-- > fromText _ = Nothing
39instance FromText Bool where
40 fromText "true" = Just True
41 fromText "false" = Just False
45-- > toText True = "true"
46-- > toText False = "false"
47instance ToText Bool where
49 toText False = "false"
51instance FromText Int where
52 fromText = runReader (signed decimal)
54instance ToText Int where
57instance FromText Int8 where
58 fromText = runReader (signed decimal)
60instance ToText Int8 where
63instance FromText Int16 where
64 fromText = runReader (signed decimal)
66instance ToText Int16 where
69instance FromText Int32 where
70 fromText = runReader (signed decimal)
72instance ToText Int32 where
75instance FromText Int64 where
76 fromText = runReader (signed decimal)
78instance ToText Int64 where
81instance FromText Word where
82 fromText = runReader decimal
84instance ToText Word where
87instance FromText Word8 where
88 fromText = runReader decimal
90instance ToText Word8 where
93instance FromText Word16 where
94 fromText = runReader decimal
96instance ToText Word16 where
99instance FromText Word32 where
100 fromText = runReader decimal
102instance ToText Word32 where
105instance FromText Word64 where
106 fromText = runReader decimal
108instance ToText Word64 where
111instance FromText Integer where
112 fromText = runReader decimal
114instance ToText Integer where
117instance FromText Double where
118 fromText = runReader rational
120instance ToText Double where
123instance FromText Float where
124 fromText = runReader rational
126instance ToText Float where
129runReader :: Reader a -> Text -> Maybe a
130runReader reader t = either (const Nothing) (Just . fst) $ reader t
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list