From cf5aaee05169c96f79b719a721af411edbb18449 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Fri, 4 Dec 2009 15:51:07 +0100 Subject: Added string splitting. --- src/Text/Hakyll/Util.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/Text/Hakyll/Util.hs') diff --git a/src/Text/Hakyll/Util.hs b/src/Text/Hakyll/Util.hs index 50a36e6..83348c3 100644 --- a/src/Text/Hakyll/Util.hs +++ b/src/Text/Hakyll/Util.hs @@ -8,6 +8,7 @@ import System.Directory import System.FilePath import Control.Monad import Data.Char +import Data.List -- | Given a path to a file, try to make the path writable by making -- all directories on the path. @@ -34,3 +35,12 @@ getRecursiveContents topdir = do trim :: String -> String trim = reverse . trim' . reverse . trim' where trim' = dropWhile isSpace + +-- | Split a list at a certain element. +split :: (Eq a) => a -> [a] -> [[a]] +split element = unfoldr splitOnce + where splitOnce l = let r = break (== element) l + in case r of ([], []) -> Nothing + (x, xs) -> if null xs + then Just (x, []) + else Just (x, tail xs) -- cgit v1.2.3