1
0
forked from GitHub/gf-core

A somewhat better solution to the words/UTF-8 problem: do encoding last, but only on what appears to be string literals.

This commit is contained in:
bjorn
2008-09-15 13:16:04 +00:00
parent dbb0f3f3e4
commit 3a7888e660
3 changed files with 12 additions and 3 deletions

View File

@@ -48,3 +48,13 @@ codeSourceModule co (id,moi) = case moi of
PSeq p q -> PSeq (codp p) (codp q)
PAlt p q -> PAlt (codp p) (codp q)
_ -> p
-- | Run an encoding function on all string literals within the given string.
codeStringLiterals :: (String -> String) -> String -> String
codeStringLiterals _ [] = []
codeStringLiterals co ('"':cs) = '"' : inStringLiteral cs
where inStringLiteral [] = error "codeStringLiterals: unterminated string literal"
inStringLiteral ('"':ds) = '"' : codeStringLiterals co ds
inStringLiteral ('\\':d:ds) = '\\' : co [d] ++ inStringLiteral ds
inStringLiteral (d:ds) = co [d] ++ inStringLiteral ds
codeStringLiterals co (c:cs) = c : codeStringLiterals co cs