From 3a7888e66008f1df2e68474c94f94c82f6042383 Mon Sep 17 00:00:00 2001 From: bjorn Date: Mon, 15 Sep 2008 13:16:04 +0000 Subject: A somewhat better solution to the words/UTF-8 problem: do encoding last, but only on what appears to be string literals. --- src/GF/Compile/Coding.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/GF/Compile/Coding.hs') diff --git a/src/GF/Compile/Coding.hs b/src/GF/Compile/Coding.hs index a226265c5..704e95201 100644 --- a/src/GF/Compile/Coding.hs +++ b/src/GF/Compile/Coding.hs @@ -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 -- cgit v1.2.3