\begin{code}
#if __GLASGOW_HASKELL__ >= 800
#endif
module Text.RE.ZeInternals.Types.IsRegex
( IsRegex(..)
, SearchReplace(..)
, searchReplaceAll
, searchReplaceFirst
) where
import Text.RE.REOptions
import Text.RE.Replace
import Text.RE.ZeInternals.EscapeREString
import Text.RE.ZeInternals.Types.SearchReplace
\end{code}
\begin{code}
class Replace s => IsRegex re s where
matchOnce :: re -> s -> Match s
matchMany :: re -> s -> Matches s
makeRegex :: (Functor m,Monad m) => s -> m re
makeRegexWith :: (Functor m,Monad m) => SimpleREOptions -> s -> m re
makeSearchReplace :: (Functor m,Monad m,IsRegex re s) => s -> s -> m (SearchReplace re s)
makeSearchReplaceWith :: (Functor m,Monad m,IsRegex re s) => SimpleREOptions -> s -> s -> m (SearchReplace re s)
makeEscaped :: (Functor m,Monad m) => (s->s) -> s -> m re
makeEscapedWith :: (Functor m,Monad m) => SimpleREOptions -> (s->s) -> s -> m re
regexSource :: re -> s
makeRegex = makeRegexWith minBound
makeSearchReplace = makeSearchReplaceWith minBound
makeEscaped = makeEscapedWith minBound
makeEscapedWith o f = makeRegexWith o . f . packR . escapeREString . unpackR
\end{code}
\begin{code}
searchReplaceAll :: IsRegex re s => SearchReplace re s -> s -> s
searchReplaceAll SearchReplace{..} = replaceAll getTemplate . matchMany getSearch
searchReplaceFirst :: IsRegex re s => SearchReplace re s -> s -> s
searchReplaceFirst SearchReplace{..} = replace getTemplate . matchOnce getSearch
\end{code}