@@ -33,16 +33,24 @@ compressCss = compressSeparators . stripComments . compressWhitespace
33--------------------------------------------------------------------------------
33--------------------------------------------------------------------------------
34-- | Compresses certain forms of separators.
34-- | Compresses certain forms of separators.
35compressSeparators :: String -> String
35compressSeparators :: String -> String
36−compressSeparators =
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)
37− replaceAll "; *}" (const "}") .
41+ replaceAll "; *}" (const "}") $
38− replaceAll " *([{};]) *" (take 1 . dropWhile isSpace) .
42+ replaceAll " *([{};]) *" (take 1 . dropWhile isSpace) $
39− replaceAll ";+" (const ";")
43+ replaceAll ";+" (const ";") str
42--------------------------------------------------------------------------------
46--------------------------------------------------------------------------------
43-- | Compresses all whitespace.
47-- | Compresses all whitespace.
44compressWhitespace :: String -> String
48compressWhitespace :: 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
48--------------------------------------------------------------------------------
56--------------------------------------------------------------------------------
@@ -57,3 +65,11 @@ stripComments str
57 | null str' = []
65 | null str' = []
58 | isPrefixOf "*/" str' = drop 2 str'
66 | isPrefixOf "*/" str' = drop 2 str'
59 | otherwise = eatComments $ drop 1 str'
67 | otherwise = eatComments $ drop 1 str'
69+--------------------------------------------------------------------------------
70+-- | Helper function to handle string constants correctly.
71+retainConstants :: (String -> String) -> String -> String -> String
72+retainConstants f delim str
74+ | isPrefixOf delim str = head str : f (drop 1 str)
75+ | otherwise = head str : retainConstants f delim (drop 1 str)