on master help sign in
Extracted a helper method because it was defined locally twice.
c32e554Nicole Rauch
src/Hakyll/Web/CompressCss.hs+11−8
@@ -37,13 +37,12 @@ compressSeparators [] = []
37compressSeparators str
37compressSeparators str
38 | isPrefixOf "\"" str = head str : retainConstants compressSeparators "\"" (drop 1 str)
38 | isPrefixOf "\"" str = head str : retainConstants compressSeparators "\"" (drop 1 str)
39 | isPrefixOf "'" str = head str : retainConstants compressSeparators "'" (drop 1 str)
39 | isPrefixOf "'" str = head str : retainConstants compressSeparators "'" (drop 1 str)
40− | stripFirst = compressSeparators (drop 1 str)
40+ | stripFirst = compressSeparators (drop 1 str)
41 | stripSecond = compressSeparators (head str : (drop 2 str))
41 | stripSecond = compressSeparators (head str : (drop 2 str))
42− | otherwise = head str : compressSeparators (drop 1 str)
42+ | otherwise = head str : compressSeparators (drop 1 str)
43 where
43 where
44− prefix p = isPrefixOf p str
45− stripFirst = or $ map prefix [" ", " {", " }", ";;", ";}"]
44+ stripFirst = or $ map (isOfPrefix str) [" ", " {", " }", ";;", ";}"]
46− stripSecond = or $ map prefix ["{ ", "} ", "; "]
45+ stripSecond = or $ map (isOfPrefix str) ["{ ", "} ", "; "]
47
46
48--------------------------------------------------------------------------------
47--------------------------------------------------------------------------------
49-- | Compresses all whitespace.
48-- | Compresses all whitespace.
@@ -56,9 +55,8 @@ compressWhitespace str
56 | replaceTwo = compressWhitespace (' ' : (drop 2 str))
55 | replaceTwo = compressWhitespace (' ' : (drop 2 str))
57 | otherwise = head str : compressWhitespace (drop 1 str)
56 | otherwise = head str : compressWhitespace (drop 1 str)
58 where
57 where
59− prefix p = isPrefixOf p str
60− replaceOne = or $ map prefix ["\t", "\n", "\r"]
58+ replaceOne = or $ map (isOfPrefix str) ["\t", "\n", "\r"]
61− replaceTwo = or $ map prefix [" \t", " \n", " \r", " "]
59+ replaceTwo = or $ map (isOfPrefix str) [" \t", " \n", " \r", " "]
62
60
63--------------------------------------------------------------------------------
61--------------------------------------------------------------------------------
64-- | Function that strips CSS comments away.
62-- | Function that strips CSS comments away.
@@ -82,3 +80,8 @@ retainConstants f delim str
82 | null str = []
80 | null str = []
83 | isPrefixOf delim str = head str : f (drop 1 str)
81 | isPrefixOf delim str = head str : f (drop 1 str)
84 | otherwise = head str : retainConstants f delim (drop 1 str)
82 | otherwise = head str : retainConstants f delim (drop 1 str)
83+
84+--------------------------------------------------------------------------------
85+-- | Helper function to determine whether a string is a substring.
86+isOfPrefix :: String -> String -> Bool
87+isOfPrefix = flip isPrefixOf