From 49989eab5767b24cb3e917b95137ae05566e34a8 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Mon, 28 Feb 2011 22:33:28 +0100 Subject: Web.Util.String → {Web.Util.Url, Core.Util.String} MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Hakyll/Web/Util/String.hs | 73 ------------------------------------------- src/Hakyll/Web/Util/Url.hs | 30 ++++++++++++++++++ 2 files changed, 30 insertions(+), 73 deletions(-) delete mode 100644 src/Hakyll/Web/Util/String.hs create mode 100644 src/Hakyll/Web/Util/Url.hs (limited to 'src/Hakyll/Web/Util') diff --git a/src/Hakyll/Web/Util/String.hs b/src/Hakyll/Web/Util/String.hs deleted file mode 100644 index 0dde74a..0000000 --- a/src/Hakyll/Web/Util/String.hs +++ /dev/null @@ -1,73 +0,0 @@ --- | Miscellaneous string manipulation functions. --- -module Hakyll.Web.Util.String - ( trim - , replaceAll - , splitAll - , toUrl - , toSiteRoot - ) where - -import Data.Char (isSpace) -import Data.Maybe (listToMaybe) - -import System.FilePath (splitPath, takeDirectory, joinPath) -import Text.Regex.PCRE ((=~~)) - --- | Trim a string (drop spaces, tabs and newlines at both sides). --- -trim :: String -> String -trim = reverse . trim' . reverse . trim' - where - trim' = dropWhile isSpace - --- | A simple (but inefficient) regex replace funcion --- -replaceAll :: String -- ^ Pattern - -> (String -> String) -- ^ Replacement (called on capture) - -> String -- ^ Source string - -> String -- ^ Result -replaceAll pattern f source = replaceAll' source - where - replaceAll' src = case listToMaybe (src =~~ pattern) of - Nothing -> src - Just (o, l) -> - let (before, tmp) = splitAt o src - (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: --- --- > toUrl "foo/bar.html" --- --- Result: --- --- > "/foo/bar.html" --- -toUrl :: FilePath -> String -toUrl = ('/' :) - --- | Get the relative url to the site root, for a given (absolute) url --- -toSiteRoot :: String -> String -toSiteRoot = emptyException . joinPath . map parent . splitPath . takeDirectory - where - parent = const ".." - emptyException [] = "." - emptyException x = x diff --git a/src/Hakyll/Web/Util/Url.hs b/src/Hakyll/Web/Util/Url.hs new file mode 100644 index 0000000..54a361e --- /dev/null +++ b/src/Hakyll/Web/Util/Url.hs @@ -0,0 +1,30 @@ +-- | Miscellaneous URL manipulation functions. +-- +module Hakyll.Web.Util.Url + ( toUrl + , toSiteRoot + ) where + +import System.FilePath (splitPath, takeDirectory, joinPath) + +-- | Convert a filepath to an URL starting from the site root +-- +-- Example: +-- +-- > toUrl "foo/bar.html" +-- +-- Result: +-- +-- > "/foo/bar.html" +-- +toUrl :: FilePath -> String +toUrl = ('/' :) + +-- | Get the relative url to the site root, for a given (absolute) url +-- +toSiteRoot :: String -> String +toSiteRoot = emptyException . joinPath . map parent . splitPath . takeDirectory + where + parent = const ".." + emptyException [] = "." + emptyException x = x -- cgit v1.2.3