1-- | Miscellaneous string manipulation functions.
3module Hakyll.Web.Util.String
11import Data.Char (isSpace)
12import Data.Maybe (listToMaybe)
14import System.FilePath (splitPath, takeDirectory, joinPath)
15import Text.Regex.PCRE ((=~~))
17-- | Trim a string (drop spaces, tabs and newlines at both sides).
19trim :: String -> String
20trim = reverse . trim' . reverse . trim'
22 trim' = dropWhile isSpace
24-- | A simple (but inefficient) regex replace funcion
26replaceAll :: String -- ^ Pattern
27 -> (String -> String) -- ^ Replacement (called on capture)
28 -> String -- ^ Source string
30replaceAll pattern f source = replaceAll' source
32 replaceAll' src = case listToMaybe (src =~~ pattern) of
35 let (before, tmp) = splitAt o src
36 (capture, after) = splitAt l tmp
37 in before ++ f capture ++ replaceAll' after
39-- | A simple regex split function. The resulting list will contain no empty
42splitAll :: String -- ^ Pattern
43 -> String -- ^ String to split
44 -> [String] -- ^ Result
45splitAll pattern = filter (not . null) . splitAll'
47 splitAll' src = case listToMaybe (src =~~ pattern) of
50 let (before, tmp) = splitAt o src
51 in before : splitAll' (drop l tmp)
53-- | Convert a filepath to an URL starting from the site root
57-- > toUrl "foo/bar.html"
63toUrl :: FilePath -> String
66-- | Get the relative url to the site root, for a given (absolute) url
68toSiteRoot :: String -> String
69toSiteRoot = emptyException . joinPath . map parent . splitPath . takeDirectory
72 emptyException [] = "."
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