From 7d2c9c6fe6458a6b15fa63fe7ee0651a57e5ce32 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Thu, 19 Jul 2007 08:08:51 +0000 Subject: Added escapeCharAsString to Text.Pandoc.Shared. git-svn-id: https://pandoc.googlecode.com/svn/trunk@738 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Shared.hs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index b8500ca7a..78206a7db 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -36,6 +36,7 @@ module Text.Pandoc.Shared ( joinWithSep, tabsToSpaces, backslashEscape, + escapeCharAsString, endsWith, stripTrailingNewlines, removeLeadingTrailingSpace, @@ -268,6 +269,14 @@ 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 @True@ if string ends with given character. endsWith :: Char -> [Char] -> Bool endsWith char [] = False -- cgit v1.2.3