Skip to content

Commit

Permalink
0.27.15 - add PathInfo instances for Word* and Int*
Browse files Browse the repository at this point in the history
  • Loading branch information
stepcut committed Feb 6, 2023
1 parent ed89f17 commit 90fcdec
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ jobs:
strategy:
matrix:
include:
- compiler: ghc-9.2.2
- compiler: ghc-9.4.2
compilerKind: ghc
compilerVersion: 9.2.2
compilerVersion: 9.4.2
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.2.5
compilerKind: ghc
compilerVersion: 9.2.5
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.0.2
Expand Down
39 changes: 36 additions & 3 deletions Web/Routes/PathInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ import Control.Applicative ((<$>), (<*))
import Control.Monad (msum)
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.Int (Int64)
import Data.Int (Int8, Int16, Int32, Int64)
import Data.List as List (stripPrefix, tails)
import Data.Text as Text (Text, pack, unpack, null, tails, stripPrefix)
import Data.Text.Encoding (decodeUtf8)
import Data.Text.Read (decimal, signed)
import Data.Maybe (fromJust)
import Data.Word (Word, Word8, Word16, Word32, Word64)
import Network.HTTP.Types
import Text.ParserCombinators.Parsec.Combinator (notFollowedBy)
import Text.ParserCombinators.Parsec.Error (ParseError, errorPos, errorMessages, showErrorMessages)
Expand Down Expand Up @@ -340,14 +341,46 @@ instance PathInfo Int where
toPathSegments i = [pack $ show i]
fromPathSegments = pToken (const "Int") checkIntegral

instance PathInfo Integer where
instance PathInfo Int8 where
toPathSegments i = [pack $ show i]
fromPathSegments = pToken (const "Integer") checkIntegral
fromPathSegments = pToken (const "Int8") checkIntegral

instance PathInfo Int16 where
toPathSegments i = [pack $ show i]
fromPathSegments = pToken (const "Int16") checkIntegral

instance PathInfo Int32 where
toPathSegments i = [pack $ show i]
fromPathSegments = pToken (const "Int32") checkIntegral

instance PathInfo Int64 where
toPathSegments i = [pack $ show i]
fromPathSegments = pToken (const "Int64") checkIntegral

instance PathInfo Integer where
toPathSegments i = [pack $ show i]
fromPathSegments = pToken (const "Integer") checkIntegral

instance PathInfo Word where
toPathSegments i = [pack $ show i]
fromPathSegments = pToken (const "Word") checkIntegral

instance PathInfo Word8 where
toPathSegments i = [pack $ show i]
fromPathSegments = pToken (const "Word8") checkIntegral

instance PathInfo Word16 where
toPathSegments i = [pack $ show i]
fromPathSegments = pToken (const "Word16") checkIntegral

instance PathInfo Word32 where
toPathSegments i = [pack $ show i]
fromPathSegments = pToken (const "Word32") checkIntegral

instance PathInfo Word64 where
toPathSegments i = [pack $ show i]
fromPathSegments = pToken (const "Word64") checkIntegral

checkIntegral :: Integral a => Text -> Maybe a
checkIntegral txt =
case signed decimal txt of
Expand Down
6 changes: 3 additions & 3 deletions web-routes.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: web-routes
Version: 0.27.14.4
Version: 0.27.15
License: BSD3
License-File: LICENSE
Author: [email protected]
Expand All @@ -10,7 +10,7 @@ Description: A collection of types and functions that ensure that URLs gene
Homepage: http://www.happstack.com/docs/crashcourse/index.html#web-routes
Cabal-Version: >= 1.10
Build-type: Simple
tested-with: GHC==8.0.2, GHC==8.2.2, GHC==8.4.1, GHC==8.6.5, GHC==8.8.4, GHC==8.10.7, GHC==9.0.2, GHC==9.2.2
tested-with: GHC==8.0.2, GHC==8.2.2, GHC==8.4.1, GHC==8.6.5, GHC==8.8.4, GHC==8.10.7, GHC==9.0.2, GHC==9.2.5, GHC==9.4.2

test-suite Test
Default-Language : Haskell2010
Expand All @@ -31,7 +31,7 @@ Library
parsec >= 2 && < 4,
bytestring >= 0.9 && < 0.12,
http-types >= 0.6 && < 0.13,
mtl >= 2.0 && < 2.3,
mtl >= 2.0 && < 2.4,
text >= 0.11 && < 2.1,
utf8-string >= 0.3 && < 1.1,
exceptions >= 0.6.1 && < 0.11
Expand Down

0 comments on commit 90fcdec

Please sign in to comment.