@@ -9,7 +9,8 @@ module Web.PathPieces
9 , fromMultiPiece
9 , fromMultiPiece
12−import Data.Int (Int64)
12+import Data.Int (Int8, Int16, Int32, Int64)
13+import Data.Word (Word, Word8, Word16, Word32, Word64)
13import qualified Data.Text as S
14import qualified Data.Text as S
14import qualified Data.Text.Lazy as L
15import qualified Data.Text.Lazy as L
15import qualified Data.Text.Read
16import qualified Data.Text.Read
@@ -32,6 +33,16 @@ instance PathPiece L.Text where
32 fromPathPiece = Just . L.fromChunks . return
33 fromPathPiece = Just . L.fromChunks . return
33 toPathPiece = S.concat . L.toChunks
34 toPathPiece = S.concat . L.toChunks
36+parseIntegral :: (Integral a, Bounded a, Ord a) => S.Text -> Maybe a
39+ n = case Data.Text.Read.signed Data.Text.Read.decimal s of
40+ Right (i, "") | i <= top && i >= bot -> Just (fromInteger i)
43+ top = toInteger (maxBound `asTypeOf` witness)
44+ bot = toInteger (minBound `asTypeOf` witness)
35instance PathPiece Integer where
46instance PathPiece Integer where
36 fromPathPiece s =
47 fromPathPiece s =
37 case Data.Text.Read.signed Data.Text.Read.decimal s of
48 case Data.Text.Read.signed Data.Text.Read.decimal s of
@@ -40,10 +51,43 @@ instance PathPiece Integer where
40 toPathPiece = S.pack . show
51 toPathPiece = S.pack . show
42instance PathPiece Int where
53instance PathPiece Int where
43− fromPathPiece s =
54+ fromPathPiece = parseIntegral
44− case Data.Text.Read.signed Data.Text.Read.decimal s of
55+ toPathPiece = S.pack . show
45− Right (i, "") -> Just i
56+
46− _ -> Nothing
57+instance PathPiece Int8 where
58+ fromPathPiece = parseIntegral
59+ toPathPiece = S.pack . show
61+instance PathPiece Int16 where
62+ fromPathPiece = parseIntegral
63+ toPathPiece = S.pack . show
65+instance PathPiece Int32 where
66+ fromPathPiece = parseIntegral
67+ toPathPiece = S.pack . show
69+instance PathPiece Int64 where
70+ fromPathPiece = parseIntegral
71+ toPathPiece = S.pack . show
73+instance PathPiece Word where
74+ fromPathPiece = parseIntegral
75+ toPathPiece = S.pack . show
77+instance PathPiece Word8 where
78+ fromPathPiece = parseIntegral
79+ toPathPiece = S.pack . show
81+instance PathPiece Word16 where
82+ fromPathPiece = parseIntegral
83+ toPathPiece = S.pack . show
85+instance PathPiece Word32 where
86+ fromPathPiece = parseIntegral
87+ toPathPiece = S.pack . show
89+instance PathPiece Word64 where
90+ fromPathPiece = parseIntegral
47 toPathPiece = S.pack . show
91 toPathPiece = S.pack . show
49instance PathPiece Bool where
93instance PathPiece Bool where
@@ -53,13 +97,6 @@ instance PathPiece Bool where
53 _ -> Nothing
97 _ -> Nothing
54 toPathPiece = S.pack . show
98 toPathPiece = S.pack . show
56−instance PathPiece Int64 where
58− case Data.Text.Read.signed Data.Text.Read.decimal s of
59− Right (i, "") -> Just i
61− toPathPiece = S.pack . show
63instance PathPiece Day where
100instance PathPiece Day where
64 fromPathPiece t =
101 fromPathPiece t =
65 case reads $ S.unpack t of
102 case reads $ S.unpack t of