words' on an empty string should return empty list

This commit is contained in:
Simon Michael 2013-02-24 20:04:28 +00:00
parent 8aba692926
commit 33153851e9

View File

@ -87,9 +87,10 @@ escapeQuotes :: String -> String
escapeQuotes = regexReplace "([\"'])" "\\1"
-- | Quote-aware version of words - don't split on spaces which are inside quotes.
-- NB correctly handles "a'b" but not "''a''".
-- NB correctly handles "a'b" but not "''a''". Can raise an error if parsing fails.
words' :: String -> [String]
words' = map stripquotes . fromparse . parsewith p
words' "" = []
words' s = map stripquotes $ fromparse $ parsewith p s
where
p = do ss <- (quotedPattern <|> pattern) `sepBy` many1 spacenonewline
-- eof