summaryrefslogtreecommitdiff
path: root/src/GF/Compile/Coding.hs
diff options
context:
space:
mode:
authorbjorn <bjorn@bringert.net>2008-09-15 13:16:04 +0000
committerbjorn <bjorn@bringert.net>2008-09-15 13:16:04 +0000
commit3a7888e66008f1df2e68474c94f94c82f6042383 (patch)
tree441d94d08d4734360541ea6e86f52ab058b7a2e6 /src/GF/Compile/Coding.hs
parentdbb0f3f3e464044aef1de3abfc1286569ea6543f (diff)
A somewhat better solution to the words/UTF-8 problem: do encoding last, but only on what appears to be string literals.
Diffstat (limited to 'src/GF/Compile/Coding.hs')
-rw-r--r--src/GF/Compile/Coding.hs10
1 files changed, 10 insertions, 0 deletions
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