{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# OPTIONS_GHC -fno-warn-duplicate-exports #-}
{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ >= 800
{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
#endif
module Text.RE.PCRE.String
(
(*=~)
, (?=~)
, (*=~/)
, (?=~/)
, Matches
, matchesSource
, allMatches
, anyMatches
, countMatches
, matches
, Match
, matchSource
, matched
, matchedText
, module Text.RE.TestBench.Parsers
, RE
, reSource
, SimpleREOptions(..)
, SearchReplace(..)
, compileRegex
, compileRegexWith
, compileSearchReplace
, compileSearchReplaceWith
, escape
, escapeWith
, escapeREString
, (=~)
, (=~~)
, re
, reMultilineSensitive
, reMultilineInsensitive
, reBlockSensitive
, reBlockInsensitive
, reMS
, reMI
, reBS
, reBI
, re_
, edMultilineSensitive
, edMultilineInsensitive
, edBlockSensitive
, edBlockInsensitive
, ed
, edMS
, edMI
, edBS
, edBI
, ed_
, cp
, module Text.RE.Tools.IsRegex
) where
import Control.Monad.Fail
import Data.Typeable
import Prelude.Compat
import Text.RE.REOptions
import Text.RE.Replace
import Text.RE.TestBench.Parsers
import Text.RE.Tools.IsRegex
import Text.RE.ZeInternals
import Text.RE.ZeInternals.PCRE
import Text.RE.ZeInternals.SearchReplace.PCRE.String
import Text.Regex.Base
import qualified Text.Regex.PCRE as PCRE
(*=~) :: String
-> RE
-> Matches String
*=~ :: String -> RE -> Matches String
(*=~) String
bs RE
rex = CaptureNames -> Matches String -> Matches String
forall a. CaptureNames -> Matches a -> Matches a
addCaptureNamesToMatches (RE -> CaptureNames
reCaptureNames RE
rex) (Matches String -> Matches String)
-> Matches String -> Matches String
forall a b. (a -> b) -> a -> b
$ Regex -> String -> Matches String
forall regex source target.
RegexContext regex source target =>
regex -> source -> target
match (RE -> Regex
reRegex RE
rex) String
bs
(?=~) :: String
-> RE
-> Match String
?=~ :: String -> RE -> Match String
(?=~) String
bs RE
rex = CaptureNames -> Match String -> Match String
forall a. CaptureNames -> Match a -> Match a
addCaptureNamesToMatch (RE -> CaptureNames
reCaptureNames RE
rex) (Match String -> Match String) -> Match String -> Match String
forall a b. (a -> b) -> a -> b
$ Regex -> String -> Match String
forall regex source target.
RegexContext regex source target =>
regex -> source -> target
match (RE -> Regex
reRegex RE
rex) String
bs
(*=~/) :: String -> SearchReplace RE String -> String
*=~/ :: String -> SearchReplace RE String -> String
(*=~/) = (SearchReplace RE String -> String -> String)
-> String -> SearchReplace RE String -> String
forall a b c. (a -> b -> c) -> b -> a -> c
flip SearchReplace RE String -> String -> String
forall re s. IsRegex re s => SearchReplace re s -> s -> s
searchReplaceAll
(?=~/) :: String -> SearchReplace RE String -> String
?=~/ :: String -> SearchReplace RE String -> String
(?=~/) = (SearchReplace RE String -> String -> String)
-> String -> SearchReplace RE String -> String
forall a b c. (a -> b -> c) -> b -> a -> c
flip SearchReplace RE String -> String -> String
forall re s. IsRegex re s => SearchReplace re s -> s -> s
searchReplaceFirst
(=~) :: ( Typeable a
, RegexContext PCRE.Regex String a
)
=> String
-> RE
-> a
=~ :: String -> RE -> a
(=~) String
bs RE
rex = CaptureNames -> a -> a
forall a. Typeable a => CaptureNames -> a -> a
addCaptureNames (RE -> CaptureNames
reCaptureNames RE
rex) (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ Regex -> String -> a
forall regex source target.
RegexContext regex source target =>
regex -> source -> target
match (RE -> Regex
reRegex RE
rex) String
bs
(=~~) :: ( Monad m, MonadFail m
, Functor m
, Typeable a
, RegexContext PCRE.Regex String a
)
=> String
-> RE
-> m a
=~~ :: String -> RE -> m a
(=~~) String
bs RE
rex = CaptureNames -> a -> a
forall a. Typeable a => CaptureNames -> a -> a
addCaptureNames (RE -> CaptureNames
reCaptureNames RE
rex) (a -> a) -> m a -> m a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Regex -> String -> m a
forall regex source target (m :: * -> *).
(RegexContext regex source target, MonadFail m) =>
regex -> source -> m target
matchM (RE -> Regex
reRegex RE
rex) String
bs
instance IsRegex RE String where
matchOnce :: RE -> String -> Match String
matchOnce = (String -> RE -> Match String) -> RE -> String -> Match String
forall a b c. (a -> b -> c) -> b -> a -> c
flip String -> RE -> Match String
(?=~)
matchMany :: RE -> String -> Matches String
matchMany = (String -> RE -> Matches String) -> RE -> String -> Matches String
forall a b c. (a -> b -> c) -> b -> a -> c
flip String -> RE -> Matches String
(*=~)
makeRegexWith :: SimpleREOptions -> String -> m RE
makeRegexWith = \SimpleREOptions
o -> SimpleREOptions -> String -> m RE
forall (m :: * -> *).
(Functor m, Monad m, MonadFail m) =>
SimpleREOptions -> String -> m RE
compileRegexWith SimpleREOptions
o (String -> m RE) -> (String -> String) -> String -> m RE
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
forall a. Replace a => a -> String
unpackR
makeSearchReplaceWith :: SimpleREOptions -> String -> String -> m (SearchReplace RE String)
makeSearchReplaceWith = \SimpleREOptions
o String
r String
t -> SimpleREOptions -> String -> String -> m (SearchReplace RE String)
forall (m :: * -> *) s.
(Monad m, MonadFail m, Functor m, IsRegex RE s) =>
SimpleREOptions -> String -> String -> m (SearchReplace RE s)
compileSearchReplaceWith SimpleREOptions
o (String -> String
forall a. Replace a => a -> String
unpackR String
r) (String -> String
forall a. Replace a => a -> String
unpackR String
t)
regexSource :: RE -> String
regexSource = String -> String
forall a. Replace a => String -> a
packR (String -> String) -> (RE -> String) -> RE -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RE -> String
reSource