Skip to content

Commit

Permalink
Add path concatenation function
Browse files Browse the repository at this point in the history
  • Loading branch information
mightybyte committed Mar 18, 2013
1 parent f44d79a commit b2a464b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Snap/Extras/CoreUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Snap.Extras.CoreUtils
, undirify
, maybeBadReq
, fromMaybeM
, (-/-)
) where

-------------------------------------------------------------------------------
Expand Down Expand Up @@ -169,3 +170,15 @@ maybeBadReq e f = fromMaybeM (badReq e) f
fromMaybeM :: Monad m => m a -> m (Maybe a) -> m a
fromMaybeM e f = maybe e return =<< f


------------------------------------------------------------------------------
-- | Concatenates two URL segments with a '/' between them. To prevent double
-- slashes, all trailing slashes are removed from the first path and all
-- leading slashes are removed from the second path.
(-/-) :: ByteString -> ByteString -> ByteString
(-/-) a b = B.concat [revDrop a, "/", dropSlash b]
where
dropSlash = B.dropWhile (=='/')
revDrop = B.reverse . dropSlash . B.reverse


0 comments on commit b2a464b

Please sign in to comment.