From 4e446358d1a356ba77c5f7b3cd967bf6c5285c15 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 21 Dec 2010 08:22:08 -0800 Subject: 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. --- src/Text/Pandoc/XML.hs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'src/Text') 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 '"' -> """ 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 -- cgit v1.2.3