aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2010-12-21 08:22:08 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2010-12-21 08:23:48 -0800
commit4e446358d1a356ba77c5f7b3cd967bf6c5285c15 (patch)
tree86d6d6010fe3cdde685d0c89e8be20a2e1ee011f /src
parent6aa0a187b3ec1b633fe5777967c6bf8611cbb46e (diff)
downloadpandoc-4e446358d1a356ba77c5f7b3cd967bf6c5285c15.tar.gz
XML: Replaced escapeStringAsXML with a faster version.
Benchmarked with criterion, it's about 8x faster than the old version. This speeds up docbook, opendocument, and html writers.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/XML.hs10
1 files changed, 1 insertions, 9 deletions
diff --git a/src/Text/Pandoc/XML.hs b/src/Text/Pandoc/XML.hs
index 0c48b48df..426521baa 100644
--- a/src/Text/Pandoc/XML.hs
+++ b/src/Text/Pandoc/XML.hs
@@ -55,17 +55,9 @@ escapeCharForXML x = case x of
'"' -> "&quot;"
c -> [c]
--- | True if the character needs to be escaped.
-needsEscaping :: Char -> Bool
-needsEscaping c = c `elem` "&<>\""
-
-- | Escape string as needed for XML. Entity references are not preserved.
escapeStringForXML :: String -> String
-escapeStringForXML "" = ""
-escapeStringForXML str =
- case break needsEscaping str of
- (okay, "") -> okay
- (okay, (c:cs)) -> okay ++ escapeCharForXML c ++ escapeStringForXML cs
+escapeStringForXML = concatMap escapeCharForXML
-- | Return a text object with a string of formatted XML attributes.
attributeList :: [(String, String)] -> Doc