diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2011-01-05 13:12:50 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2011-01-05 13:12:50 +0100 |
commit | 664648c5f9693fa5160a5c67aeabe8a9d38df03d (patch) | |
tree | 73421cfdf6d3042988e21ff0520be6cd81203f9c /src/Hakyll/Web/Util/String.hs | |
parent | 77c7d8dc17a86640180b9b233f6e0fd9008c6848 (diff) | |
download | hakyll-664648c5f9693fa5160a5c67aeabe8a9d38df03d.tar.gz |
Proof-of-concept tag module
Diffstat (limited to 'src/Hakyll/Web/Util/String.hs')
-rw-r--r-- | src/Hakyll/Web/Util/String.hs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/Hakyll/Web/Util/String.hs b/src/Hakyll/Web/Util/String.hs index ed8b904..0dde74a 100644 --- a/src/Hakyll/Web/Util/String.hs +++ b/src/Hakyll/Web/Util/String.hs @@ -3,6 +3,7 @@ module Hakyll.Web.Util.String ( trim , replaceAll + , splitAll , toUrl , toSiteRoot ) where @@ -35,6 +36,20 @@ replaceAll pattern f source = replaceAll' source (capture, after) = splitAt l tmp in before ++ f capture ++ replaceAll' after +-- | A simple regex split function. The resulting list will contain no empty +-- strings. +-- +splitAll :: String -- ^ Pattern + -> String -- ^ String to split + -> [String] -- ^ Result +splitAll pattern = filter (not . null) . splitAll' + where + splitAll' src = case listToMaybe (src =~~ pattern) of + Nothing -> [src] + Just (o, l) -> + let (before, tmp) = splitAt o src + in before : splitAll' (drop l tmp) + -- | Convert a filepath to an URL starting from the site root -- -- Example: |