1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
module Text.RE.ZeInternals.EscapeREString where
-- | Convert a string into a regular expression that will match that
-- string
escapeREString :: String -> String
escapeREString = foldr esc []
where
esc c t | isMetaChar c = '\\' : c : t
| otherwise = c : t
-- | returns True iff the character is an RE meta character
-- ('[', '*', '{', etc.)
isMetaChar :: Char -> Bool
isMetaChar c = case c of
'^' -> True
'\\' -> True
'.' -> True
'|' -> True
'*' -> True
'?' -> True
'+' -> True
'(' -> True
')' -> True
'[' -> True
']' -> True
'{' -> True
'}' -> True
'$' -> True
_ -> False
|