Skip to content
Browse files

Add path concatenation function

  • Loading branch information...
1 parent f44d79a commit b2a464b8c271462ca8c8f9468529d882bec55c33 @mightybyte mightybyte committed
Showing with 13 additions and 0 deletions.
  1. +13 −0 src/Snap/Extras/CoreUtils.hs
View
13 src/Snap/Extras/CoreUtils.hs
@@ -20,6 +20,7 @@ module Snap.Extras.CoreUtils
, undirify
, maybeBadReq
, fromMaybeM
+ , (-/-)
) where
-------------------------------------------------------------------------------
@@ -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.
Something went wrong with that request. Please try again.