git.iko.soy/typeable/pandoc
on master help sign in
Changed Entities.hs to use Data.Map rather than
1266b18fiddlosopher
src/Text/Pandoc/Entities.hs+7−9
@@ -39,15 +39,15 @@ module Text.Pandoc.Entities (
39import Data.Char ( chr, ord )
39import Data.Char ( chr, ord )
40import Text.ParserCombinators.Parsec
40import Text.ParserCombinators.Parsec
41import Data.Maybe ( fromMaybe )
41import Data.Maybe ( fromMaybe )
42+import qualified Data.Map as Map
42
43
43-- | Returns a string containing an entity reference for the character.
44-- | Returns a string containing an entity reference for the character.
44charToEntity :: Char -> String
45charToEntity :: Char -> String
45charToEntity char =
46charToEntity char =
46− let matches = filter (\(entity, character) -> (character == char))
47− entityTable in
47+ let matches = Map.filter (== char) entityTable in
48− if (length matches) == 0
48+ if Map.null matches
49 then charToNumericalEntity char
49 then charToNumericalEntity char
50− else fst (head matches)
50+ else head $ Map.keys matches
51
51
52-- | Returns a string containing a numerical entity reference for the char.
52-- | Returns a string containing a numerical entity reference for the char.
53charToNumericalEntity :: Char -> String
53charToNumericalEntity :: Char -> String
@@ -64,9 +64,7 @@ namedEntity = try $ do
64 body <- many1 alphaNum
64 body <- many1 alphaNum
65 end <- char ';'
65 end <- char ';'
66 let entity = "&" ++ body ++ ";"
66 let entity = "&" ++ body ++ ";"
67− return $ case (lookup entity entityTable) of
67+ return $ Map.findWithDefault '?' entity entityTable
68− Just ch -> ch
69− Nothing -> '?'
70
68
71-- | Parse SGML hexadecimal entity.
69-- | Parse SGML hexadecimal entity.
72hexEntity :: GenParser Char st Char
70hexEntity :: GenParser Char st Char
@@ -114,8 +112,8 @@ decodeEntities str =
114 Left err -> error $ "\nError: " ++ show err
112 Left err -> error $ "\nError: " ++ show err
115 Right result -> result
113 Right result -> result
116
114
117−entityTable :: [(String, Char)]
115+entityTable :: Map.Map String Char
118−entityTable = [
116+entityTable = Map.fromList [
119 ("&quot;", chr 34),
117 ("&quot;", chr 34),
120 ("&amp;", chr 38),
118 ("&amp;", chr 38),
121 ("&lt;", chr 60),
119 ("&lt;", chr 60),