@@ -33,16 +33,24 @@ compressCss = compressSeparators . stripComments . compressWhitespace
3333--------------------------------------------------------------------------------
3434-- | Compresses certain forms of separators.
3535compressSeparators :: String -> String
36−compressSeparators =
37− replaceAll "; *}" (const "}") .
38− replaceAll " *([{};]) *" (take 1 . dropWhile isSpace) .
39− replaceAll ";+" (const ";")
40−
36+compressSeparators [] = []
37+compressSeparators str
38+ | isPrefixOf "\"" str = head str : retainConstants compressSeparators "\"" (drop 1 str)
39+ | isPrefixOf "'" str = head str : retainConstants compressSeparators "'" (drop 1 str)
40+ | otherwise =
41+ replaceAll "; *}" (const "}") $
42+ replaceAll " *([{};]) *" (take 1 . dropWhile isSpace) $
43+ replaceAll ";+" (const ";") str
44+ where
4145
4246--------------------------------------------------------------------------------
4347-- | Compresses all whitespace.
4448compressWhitespace :: String -> String
45−compressWhitespace = replaceAll "[ \t\n\r]+" (const " ")
49+compressWhitespace [] = []
50+compressWhitespace str
51+ | isPrefixOf "\"" str = head str : retainConstants compressWhitespace "\"" (drop 1 str)
52+ | isPrefixOf "'" str = head str : retainConstants compressWhitespace "'" (drop 1 str)
53+ | otherwise = replaceAll "[ \t\n\r]+" (const " ") str
4654
4755
4856--------------------------------------------------------------------------------
@@ -57,3 +65,11 @@ stripComments str
5765 | null str' = []
5866 | isPrefixOf "*/" str' = drop 2 str'
5967 | otherwise = eatComments $ drop 1 str'
68+
69+--------------------------------------------------------------------------------
70+-- | Helper function to handle string constants correctly.
71+retainConstants :: (String -> String) -> String -> String -> String
72+retainConstants f delim str
73+ | null str = []
74+ | isPrefixOf delim str = head str : f (drop 1 str)
75+ | otherwise = head str : retainConstants f delim (drop 1 str)