Browse files

Added a 'text' Router for Data.Text values.

  • Loading branch information...
1 parent 6d74823 commit f322bf9d0013b4d6730b3e73bad0ddeb4e07b0da @tomlokhorst committed Jul 9, 2011
Showing with 12 additions and 2 deletions.
  1. +11 −1 Web/Zwaluw.hs
  2. +1 −1 Zwaluw.cabal
View
12 Web/Zwaluw.hs
@@ -19,7 +19,7 @@ module Web.Zwaluw (
, manyl, somel, chainl, chainl1
-- * Built-in routers
- , int, integer, string, char, digit, hexDigit
+ , int, integer, string, text, char, digit, hexDigit
, (/), part
, rNil, rCons, rList, rListSep
@@ -34,6 +34,7 @@ import Control.Monad (guard)
import Control.Category
import Data.Monoid
import Data.Char (isDigit, isHexDigit, intToDigit, digitToInt)
+import qualified Data.Text as T
import Web.Zwaluw.Core
import Web.Zwaluw.TH
@@ -117,6 +118,15 @@ string = val parse' serialize
)]
serialize = return . (++)
+-- | Routes any text, upto a slash ("/").
+text :: Router r (T.Text :- r)
+text = val parse' serialize
+ where
+ parse' s = [( T.pack . takeWhile (/= '/') $ s
+ , dropWhile (/= '/') s
+ )]
+ serialize = return . (++) . T.unpack
+
-- | Routes one character satisfying the given predicate.
satisfy :: (Char -> Bool) -> Router r (Char :- r)
satisfy p = val
View
2 Zwaluw.cabal
@@ -24,4 +24,4 @@ Library
Web.Zwaluw.Core,
Web.Zwaluw.TH,
Web.Zwaluw.Regular
- Build-Depends: base >= 4 && < 5, template-haskell >= 2.4 && < 2.6, regular >= 0.3 && < 0.4
+ Build-Depends: base >= 4 && < 5, template-haskell >= 2.4 && < 2.6, regular >= 0.3 && < 0.4, text >= 0.11 && < 0.12

0 comments on commit f322bf9

Please sign in to comment.