on master help sign in
Unified the constant cases in all three functions.
commit82301c508aeae5749ec5889d95feefcbcd0a2ae4 authorNicole Rauch <nicole.m@gmx.de> dateSun 14 Aug 2016, 20:16 (10 years ago) parentc32e554
1 file changed+8−8
src/Hakyll/Web/CompressCss.hs+8−8
src/Hakyll/Web/CompressCss.hs+8−8
@@ -35,12 +35,12 @@ compressCss = compressSeparators . stripComments . compressWhitespace
3535compressSeparators :: String -> String
3636compressSeparators [] = []
3737compressSeparators str
38− | isPrefixOf "\"" str = head str : retainConstants compressSeparators "\"" (drop 1 str)
39− | isPrefixOf "'" str = head str : retainConstants compressSeparators "'" (drop 1 str)
38+ | isConstant = head str : retainConstants compressSeparators (head str) (drop 1 str)
4039 | stripFirst = compressSeparators (drop 1 str)
4140 | stripSecond = compressSeparators (head str : (drop 2 str))
4241 | otherwise = head str : compressSeparators (drop 1 str)
4342 where
43+ isConstant = or $ map (isOfPrefix str) ["\"", "'"]
4444 stripFirst = or $ map (isOfPrefix str) [" ", " {", " }", ";;", ";}"]
4545 stripSecond = or $ map (isOfPrefix str) ["{ ", "} ", "; "]
4646
@@ -49,12 +49,12 @@ compressSeparators str
4949compressWhitespace :: String -> String
5050compressWhitespace [] = []
5151compressWhitespace str
52− | isPrefixOf "\"" str = head str : retainConstants compressWhitespace "\"" (drop 1 str)
53− | isPrefixOf "'" str = head str : retainConstants compressWhitespace "'" (drop 1 str)
52+ | isConstant = head str : retainConstants compressWhitespace (head str) (drop 1 str)
5453 | replaceOne = compressWhitespace (' ' : (drop 1 str))
5554 | replaceTwo = compressWhitespace (' ' : (drop 2 str))
5655 | otherwise = head str : compressWhitespace (drop 1 str)
5756 where
57+ isConstant = or $ map (isOfPrefix str) ["\"", "'"]
5858 replaceOne = or $ map (isOfPrefix str) ["\t", "\n", "\r"]
5959 replaceTwo = or $ map (isOfPrefix str) [" \t", " \n", " \r", " "]
6060
@@ -63,11 +63,11 @@ compressWhitespace str
6363stripComments :: String -> String
6464stripComments [] = []
6565stripComments str
66− | isPrefixOf "\"" str = head str : retainConstants stripComments "\"" (drop 1 str)
67− | isPrefixOf "'" str = head str : retainConstants stripComments "'" (drop 1 str)
66+ | isConstant = head str : retainConstants stripComments (head str) (drop 1 str)
6867 | isPrefixOf "/*" str = stripComments $ eatComments $ drop 2 str
6968 | otherwise = head str : stripComments (drop 1 str)
7069 where
70+ isConstant = or $ map (isOfPrefix str) ["\"", "'"]
7171 eatComments str'
7272 | null str' = []
7373 | isPrefixOf "*/" str' = drop 2 str'
@@ -75,10 +75,10 @@ stripComments str
7575
7676--------------------------------------------------------------------------------
7777-- | Helper function to handle string constants correctly.
78−retainConstants :: (String -> String) -> String -> String -> String
78+retainConstants :: (String -> String) -> Char -> String -> String
7979retainConstants f delim str
8080 | null str = []
81− | isPrefixOf delim str = head str : f (drop 1 str)
81+ | isPrefixOf [delim] str = head str : f (drop 1 str)
8282 | otherwise = head str : retainConstants f delim (drop 1 str)
8383
8484--------------------------------------------------------------------------------