diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-07-21 21:34:13 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-07-21 21:34:13 +0000 |
commit | f0fb4c496b89530f74f4ad17612383563511a27b (patch) | |
tree | 7590787c6c86de949b04a10e1ab8535f160d8eeb /src/Text/Pandoc | |
parent | 33a2f1c78f101662235a8be04910fdad2b6f3075 (diff) | |
download | pandoc-f0fb4c496b89530f74f4ad17612383563511a27b.tar.gz |
Changes to functions for character escaping:
+ Removed escapeCharAsString
+ Added escapeStringUsing
+ Changed backslashEscape to backslashEscapes, which
now returns an association list of escapes to be
passed to escapeStringUsing
git-svn-id: https://pandoc.googlecode.com/svn/trunk@748 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 737282b97..06c1b89c3 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -35,8 +35,8 @@ module Text.Pandoc.Shared ( -- * Text processing joinWithSep, tabsToSpaces, - backslashEscape, - escapeCharAsString, + backslashEscapes, + escapeStringUsing, endsWith, stripTrailingNewlines, removeLeadingTrailingSpace, @@ -260,22 +260,21 @@ tabsInLine num tabstop (c:cs) = else nextnumraw in replacement ++ (tabsInLine nextnum tabstop cs) --- | Escape designated characters with backslash. -backslashEscape :: [Char] -- ^ list of special characters to escape - -> String -- ^ string input - -> String -backslashEscape special [] = [] -backslashEscape special (x:xs) = if x `elem` special - then '\\':x:(backslashEscape special xs) - else x:(backslashEscape special xs) - --- | Escape a character as a string -escapeCharAsString ch str "" = "" -escapeCharAsString ch str (x:xs) | x == ch = - str ++ escapeCharAsString ch str xs -escapeCharAsString ch str xs = - let (a,b) = break (== ch) xs in - a ++ escapeCharAsString ch str b +-- | Returns an association list of backslash escapes for the +-- designated characters. +backslashEscapes :: [Char] -- ^ list of special characters to escape + -> [(Char, String)] +backslashEscapes = map (\ch -> (ch, ['\\',ch])) + +-- | Escape a string of characters, using an association list of +-- characters and strings. +escapeStringUsing :: [(Char, String)] -> String -> String +escapeStringUsing escapeTable "" = "" +escapeStringUsing escapeTable (x:xs) = + case (lookup x escapeTable) of + Just str -> str ++ rest + Nothing -> x:rest + where rest = escapeStringUsing escapeTable xs -- | Returns @True@ if string ends with given character. endsWith :: Char -> [Char] -> Bool |