on master help sign in
Proper string trimming.
commitd3ce014d2643fc62aa5af5b54b298fb083bf25b0 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateFri 4 Dec 2009, 15:15 (17 years ago) parent9b3babe
2 files changed+11−4
src/Text/Hakyll/Page.hs+3−3 src/Text/Hakyll/Util.hs+8−1
src/Text/Hakyll/Page.hs+3−3
@@ -18,6 +18,7 @@ import Data.Maybe
1818import System.FilePath
1919import System.IO
2020
21+import Text.Hakyll.Util
2122import Text.Pandoc
2223
2324-- | A Page is basically key-value mapping. Certain keys have special
@@ -27,7 +28,6 @@ type Page = M.Map String PageValue
2728-- | We use a ByteString for obvious reasons.
2829type PageValue = B.ByteString
2930
30−
3131-- | Add a key-value mapping to the Page.
3232addContext :: String -> String -> Page -> Page
3333addContext key value = M.insert key (B.pack value)
@@ -61,8 +61,8 @@ readMetaData handle = do
6161 line <- hGetLine handle
6262 if isDelimiter line then return []
6363 else do others <- readMetaData handle
64− return $ (trim . break (== ':')) line : others
65− where trim (key, value) = (key, dropWhile (`elem` ": ") value)
64+ return $ (trimPair . break (== ':')) line : others
65+ where trimPair (key, value) = (trim key, trim $ tail value)
6666
6767isDelimiter :: String -> Bool
6868isDelimiter = L.isPrefixOf "---"
src/Text/Hakyll/Util.hs+8−1
@@ -1,11 +1,13 @@
11module Text.Hakyll.Util
22 ( makeDirectories,
3− getRecursiveContents
3+ getRecursiveContents,
4+ trim
45 ) where
56
67import System.Directory
78import System.FilePath
89import Control.Monad
10+import Data.Char
911
1012-- | Given a path to a file, try to make the path writable by making
1113-- all directories on the path.
@@ -27,3 +29,8 @@ getRecursiveContents topdir = do
2729 else return [path]
2830 return (concat paths)
2931 where isProper = not . (== '.') . head
32+
33+-- | Trim a string (drop spaces and tabs at both sides).
34+trim :: String -> String
35+trim = reverse . trim' . reverse . trim'
36+ where trim' = dropWhile isSpace