summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2013-05-04 07:40:26 -0700
committerJasper Van der Jeugt <jaspervdj@gmail.com>2013-05-04 07:40:26 -0700
commite5709c0c736ced70d500ff8306c0e1fea9eeef59 (patch)
tree333ed9213269703c2473ab92f4e76606f19a685e /src/Hakyll/Core
parentca80171caf1328bc869c61d2f51b1fd657779532 (diff)
parent2651627189ba8b35949580b9a31cc1dde4911f88 (diff)
downloadhakyll-e5709c0c736ced70d500ff8306c0e1fea9eeef59.tar.gz
Merge pull request #143 from sphynx/master
Added teasers support
Diffstat (limited to 'src/Hakyll/Core')
-rw-r--r--src/Hakyll/Core/Util/String.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Hakyll/Core/Util/String.hs b/src/Hakyll/Core/Util/String.hs
index 514dd14..d9ec91c 100644
--- a/src/Hakyll/Core/Util/String.hs
+++ b/src/Hakyll/Core/Util/String.hs
@@ -4,9 +4,11 @@ module Hakyll.Core.Util.String
( trim
, replaceAll
, splitAll
+ , needlePrefix
) where
import Data.Char (isSpace)
+import Data.List (isPrefixOf)
import Data.Maybe (listToMaybe)
import Text.Regex.TDFA ((=~~))
@@ -46,3 +48,21 @@ splitAll pattern = filter (not . null) . splitAll'
Just (o, l) ->
let (before, tmp) = splitAt o src
in before : splitAll' (drop l tmp)
+
+
+-- | Find the first instance of needle (must be non-empty) in
+-- haystack. We return the prefix of haystack before needle is
+-- matched.
+--
+-- Examples:
+-- needlePrefix "cd" "abcde" = "ab"
+-- needlePrefix "ab" "abc" = ""
+-- needlePrefix "ab" "xxab" = "xx"
+-- needlePrefix "a" "xx" = "xx"
+--
+needlePrefix :: String -> String -> String
+needlePrefix needle haystack = go haystack
+ where
+ go [] = []
+ go xss@(x:xs) | needle `isPrefixOf` xss = []
+ | otherwise = x : go xs