summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicole Rauch <nicole.m@gmx.de>2016-08-14 20:16:09 +0200
committerNicole Rauch <nicole.m@gmx.de>2016-08-14 22:13:31 +0200
commit82301c508aeae5749ec5889d95feefcbcd0a2ae4 (patch)
tree332fb7d31098bfaeb90f0648a3ee6fee0f94eb7a /src
parentc32e55447793af259f8483f14c4a93bec882dc65 (diff)
downloadhakyll-82301c508aeae5749ec5889d95feefcbcd0a2ae4.tar.gz
Unified the constant cases in all three functions.
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Web/CompressCss.hs16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/Hakyll/Web/CompressCss.hs b/src/Hakyll/Web/CompressCss.hs
index 21f3087..8e4b268 100644
--- a/src/Hakyll/Web/CompressCss.hs
+++ b/src/Hakyll/Web/CompressCss.hs
@@ -35,12 +35,12 @@ compressCss = compressSeparators . stripComments . compressWhitespace
compressSeparators :: String -> String
compressSeparators [] = []
compressSeparators str
- | isPrefixOf "\"" str = head str : retainConstants compressSeparators "\"" (drop 1 str)
- | isPrefixOf "'" str = head str : retainConstants compressSeparators "'" (drop 1 str)
+ | isConstant = head str : retainConstants compressSeparators (head str) (drop 1 str)
| stripFirst = compressSeparators (drop 1 str)
| stripSecond = compressSeparators (head str : (drop 2 str))
| otherwise = head str : compressSeparators (drop 1 str)
where
+ isConstant = or $ map (isOfPrefix str) ["\"", "'"]
stripFirst = or $ map (isOfPrefix str) [" ", " {", " }", ";;", ";}"]
stripSecond = or $ map (isOfPrefix str) ["{ ", "} ", "; "]
@@ -49,12 +49,12 @@ compressSeparators str
compressWhitespace :: String -> String
compressWhitespace [] = []
compressWhitespace str
- | isPrefixOf "\"" str = head str : retainConstants compressWhitespace "\"" (drop 1 str)
- | isPrefixOf "'" str = head str : retainConstants compressWhitespace "'" (drop 1 str)
+ | isConstant = head str : retainConstants compressWhitespace (head str) (drop 1 str)
| replaceOne = compressWhitespace (' ' : (drop 1 str))
| replaceTwo = compressWhitespace (' ' : (drop 2 str))
| otherwise = head str : compressWhitespace (drop 1 str)
where
+ isConstant = or $ map (isOfPrefix str) ["\"", "'"]
replaceOne = or $ map (isOfPrefix str) ["\t", "\n", "\r"]
replaceTwo = or $ map (isOfPrefix str) [" \t", " \n", " \r", " "]
@@ -63,11 +63,11 @@ compressWhitespace str
stripComments :: String -> String
stripComments [] = []
stripComments str
- | isPrefixOf "\"" str = head str : retainConstants stripComments "\"" (drop 1 str)
- | isPrefixOf "'" str = head str : retainConstants stripComments "'" (drop 1 str)
+ | isConstant = head str : retainConstants stripComments (head str) (drop 1 str)
| isPrefixOf "/*" str = stripComments $ eatComments $ drop 2 str
| otherwise = head str : stripComments (drop 1 str)
where
+ isConstant = or $ map (isOfPrefix str) ["\"", "'"]
eatComments str'
| null str' = []
| isPrefixOf "*/" str' = drop 2 str'
@@ -75,10 +75,10 @@ stripComments str
--------------------------------------------------------------------------------
-- | Helper function to handle string constants correctly.
-retainConstants :: (String -> String) -> String -> String -> String
+retainConstants :: (String -> String) -> Char -> String -> String
retainConstants f delim str
| null str = []
- | isPrefixOf delim str = head str : f (drop 1 str)
+ | isPrefixOf [delim] str = head str : f (drop 1 str)
| otherwise = head str : retainConstants f delim (drop 1 str)
--------------------------------------------------------------------------------