packages feed

path-pieces 0.1.4 → 0.1.5

raw patch · 4 files changed

+62/−13 lines, 4 files

Files

+ ChangeLog.md view
@@ -0,0 +1,3 @@+## 0.1.5++Added more integral instances, and check bounds on them [#5](https://github.com/yesodweb/path-pieces/pull/5).
+ README.md view
@@ -0,0 +1,6 @@+## path-pieces++Defines two typeclasses used for converting Haskell data types to and from route pieces.+Used in Yesod to automatically marshall data in the request path.++see http://www.yesodweb.com/ for more information.
Web/PathPieces.hs view
@@ -9,7 +9,8 @@     , fromMultiPiece     ) where -import Data.Int (Int64)+import Data.Int (Int8, Int16, Int32, Int64)+import Data.Word (Word, Word8, Word16, Word32, Word64) import qualified Data.Text as S import qualified Data.Text.Lazy as L import qualified Data.Text.Read@@ -32,6 +33,16 @@     fromPathPiece = Just . L.fromChunks . return     toPathPiece = S.concat . L.toChunks +parseIntegral :: (Integral a, Bounded a, Ord a) => S.Text -> Maybe a+parseIntegral s = n+    where+    n = case Data.Text.Read.signed Data.Text.Read.decimal s of+        Right (i, "") | i <= top && i >= bot -> Just (fromInteger i)+        _ -> Nothing+    Just witness = n+    top = toInteger (maxBound `asTypeOf` witness)+    bot = toInteger (minBound `asTypeOf` witness)+ instance PathPiece Integer where     fromPathPiece s =         case Data.Text.Read.signed Data.Text.Read.decimal s of@@ -40,24 +51,50 @@     toPathPiece = S.pack . show  instance PathPiece Int where-    fromPathPiece s =-        case Data.Text.Read.signed Data.Text.Read.decimal s of-            Right (i, "") -> Just i-            _ -> Nothing+    fromPathPiece = parseIntegral     toPathPiece = S.pack . show +instance PathPiece Int8 where+    fromPathPiece = parseIntegral+    toPathPiece = S.pack . show++instance PathPiece Int16 where+    fromPathPiece = parseIntegral+    toPathPiece = S.pack . show++instance PathPiece Int32 where+    fromPathPiece = parseIntegral+    toPathPiece = S.pack . show++instance PathPiece Int64 where+    fromPathPiece = parseIntegral+    toPathPiece = S.pack . show++instance PathPiece Word where+    fromPathPiece = parseIntegral+    toPathPiece = S.pack . show++instance PathPiece Word8 where+    fromPathPiece = parseIntegral+    toPathPiece = S.pack . show++instance PathPiece Word16 where+    fromPathPiece = parseIntegral+    toPathPiece = S.pack . show++instance PathPiece Word32 where+    fromPathPiece = parseIntegral+    toPathPiece = S.pack . show++instance PathPiece Word64 where+    fromPathPiece = parseIntegral+    toPathPiece = S.pack . show+ instance PathPiece Bool where     fromPathPiece t =         case filter (null . snd) $ reads $ S.unpack t of             (a, s):_ -> assert (null s) (Just a)             _        -> Nothing-    toPathPiece = S.pack . show--instance PathPiece Int64 where-    fromPathPiece s =-        case Data.Text.Read.signed Data.Text.Read.decimal s of-            Right (i, "") -> Just i-            _ -> Nothing     toPathPiece = S.pack . show  instance PathPiece Day where
path-pieces.cabal view
@@ -1,16 +1,19 @@ name:            path-pieces-version:         0.1.4+version:         0.1.5 license:         BSD3 license-file:    LICENSE author:          Michael Snoyman <michael@snoyman.com> maintainer:      Michael Snoyman <michael@snoyman.com> synopsis:        Components of paths.+description:    Hackage documentation generation is not reliable. For up to date documentation, please see: <http://www.stackage.org/package/path-pieces>. category:        Web, Yesod stability:       unstable cabal-version:   >= 1.8 build-type:      Simple extra-source-files:   test/main.hs+  ChangeLog.md+  README.md  library     build-depends:   base             >= 4       && < 5