regex-0.5.0.0: Text/RE/Internal/EscapeREString.hs
module Text.RE.Internal.EscapeREString where
escapeREString :: String -> String
escapeREString = foldr esc []
where
esc c t | isMetaChar c = '\\' : c : t
| otherwise = c : t
isMetaChar :: Char -> Bool
isMetaChar c = case c of
'^' -> True
'\\' -> True
'.' -> True
'|' -> True
'*' -> True
'?' -> True
'+' -> True
'(' -> True
')' -> True
'[' -> True
']' -> True
'{' -> True
'}' -> True
'$' -> True
_ -> False