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.
This commit is contained in:
parent
6aa0a187b3
commit
4e446358d1
1 changed files with 1 additions and 9 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue