diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-02-14 17:39:06 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-02-14 17:39:06 +0000 |
commit | 1266b189a1d3dd771621eea0fb4917367e6cd04d (patch) | |
tree | e31838659664c8492fec0b4729ef80e029308b49 /src/Text | |
parent | 5a9b7c229dfa3c5b7801dff31a8d2d534b4ab170 (diff) | |
download | pandoc-1266b189a1d3dd771621eea0fb4917367e6cd04d.tar.gz |
Changed Entities.hs to use Data.Map rather than
an association list, for a slight performance boost.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@532 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Entities.hs | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Entities.hs b/src/Text/Pandoc/Entities.hs index 703d4d230..8e184432b 100644 --- a/src/Text/Pandoc/Entities.hs +++ b/src/Text/Pandoc/Entities.hs @@ -39,15 +39,15 @@ module Text.Pandoc.Entities ( import Data.Char ( chr, ord ) import Text.ParserCombinators.Parsec import Data.Maybe ( fromMaybe ) +import qualified Data.Map as Map -- | Returns a string containing an entity reference for the character. charToEntity :: Char -> String charToEntity char = - let matches = filter (\(entity, character) -> (character == char)) - entityTable in - if (length matches) == 0 + let matches = Map.filter (== char) entityTable in + if Map.null matches then charToNumericalEntity char - else fst (head matches) + else head $ Map.keys matches -- | Returns a string containing a numerical entity reference for the char. charToNumericalEntity :: Char -> String @@ -64,9 +64,7 @@ namedEntity = try $ do body <- many1 alphaNum end <- char ';' let entity = "&" ++ body ++ ";" - return $ case (lookup entity entityTable) of - Just ch -> ch - Nothing -> '?' + return $ Map.findWithDefault '?' entity entityTable -- | Parse SGML hexadecimal entity. hexEntity :: GenParser Char st Char @@ -114,8 +112,8 @@ decodeEntities str = Left err -> error $ "\nError: " ++ show err Right result -> result -entityTable :: [(String, Char)] -entityTable = [ +entityTable :: Map.Map String Char +entityTable = Map.fromList [ (""", chr 34), ("&", chr 38), ("<", chr 60), |