1-- | Miscellaneous string manipulation functions.
3module Hakyll.Core.Util.String
9import Data.Char (isSpace)
10import Data.Maybe (listToMaybe)
12import Text.Regex.PCRE ((=~~))
14-- | Trim a string (drop spaces, tabs and newlines at both sides).
16trim :: String -> String
17trim = reverse . trim' . reverse . trim'
19 trim' = dropWhile isSpace
21-- | A simple (but inefficient) regex replace funcion
23replaceAll :: String -- ^ Pattern
24 -> (String -> String) -- ^ Replacement (called on capture)
25 -> String -- ^ Source string
27replaceAll pattern f source = replaceAll' source
29 replaceAll' src = case listToMaybe (src =~~ pattern) of
32 let (before, tmp) = splitAt o src
33 (capture, after) = splitAt l tmp
34 in before ++ f capture ++ replaceAll' after
36-- | A simple regex split function. The resulting list will contain no empty
39splitAll :: String -- ^ Pattern
40 -> String -- ^ String to split
41 -> [String] -- ^ Result
42splitAll pattern = filter (not . null) . splitAll'
44 splitAll' src = case listToMaybe (src =~~ pattern) of
47 let (before, tmp) = splitAt o src
48 in before : splitAll' (drop l tmp)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list