{-# 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.TDFA.ByteString.Lazy
(
(*=~)
, (?=~)
, (*=~/)
, (?=~/)
, 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 qualified Data.ByteString.Lazy.Char8 as LBS
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.SearchReplace.TDFA.ByteString.Lazy
import Text.RE.ZeInternals.TDFA
import Text.Regex.Base
import qualified Text.Regex.TDFA as TDFA
(*=~) :: LBS.ByteString
-> RE
-> Matches LBS.ByteString
*=~ :: ByteString -> RE -> Matches ByteString
(*=~) ByteString
bs RE
rex = CaptureNames -> Matches ByteString -> Matches ByteString
forall a. CaptureNames -> Matches a -> Matches a
addCaptureNamesToMatches (RE -> CaptureNames
reCaptureNames RE
rex) (Matches ByteString -> Matches ByteString)
-> Matches ByteString -> Matches ByteString
forall a b. (a -> b) -> a -> b
$ Regex -> ByteString -> Matches ByteString
forall regex source target.
RegexContext regex source target =>
regex -> source -> target
match (RE -> Regex
reRegex RE
rex) ByteString
bs
(?=~) :: LBS.ByteString
-> RE
-> Match LBS.ByteString
?=~ :: ByteString -> RE -> Match ByteString
(?=~) ByteString
bs RE
rex = CaptureNames -> Match ByteString -> Match ByteString
forall a. CaptureNames -> Match a -> Match a
addCaptureNamesToMatch (RE -> CaptureNames
reCaptureNames RE
rex) (Match ByteString -> Match ByteString)
-> Match ByteString -> Match ByteString
forall a b. (a -> b) -> a -> b
$ Regex -> ByteString -> Match ByteString
forall regex source target.
RegexContext regex source target =>
regex -> source -> target
match (RE -> Regex
reRegex RE
rex) ByteString
bs
(*=~/) :: LBS.ByteString -> SearchReplace RE LBS.ByteString -> LBS.ByteString
*=~/ :: ByteString -> SearchReplace RE ByteString -> ByteString
(*=~/) = (SearchReplace RE ByteString -> ByteString -> ByteString)
-> ByteString -> SearchReplace RE ByteString -> ByteString
forall a b c. (a -> b -> c) -> b -> a -> c
flip SearchReplace RE ByteString -> ByteString -> ByteString
forall re s. IsRegex re s => SearchReplace re s -> s -> s
searchReplaceAll
(?=~/) :: LBS.ByteString -> SearchReplace RE LBS.ByteString -> LBS.ByteString
?=~/ :: ByteString -> SearchReplace RE ByteString -> ByteString
(?=~/) = (SearchReplace RE ByteString -> ByteString -> ByteString)
-> ByteString -> SearchReplace RE ByteString -> ByteString
forall a b c. (a -> b -> c) -> b -> a -> c
flip SearchReplace RE ByteString -> ByteString -> ByteString
forall re s. IsRegex re s => SearchReplace re s -> s -> s
searchReplaceFirst
(=~) :: ( Typeable a
, RegexContext TDFA.Regex LBS.ByteString a
)
=> LBS.ByteString
-> RE
-> a
=~ :: ByteString -> RE -> a
(=~) ByteString
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 -> ByteString -> a
forall regex source target.
RegexContext regex source target =>
regex -> source -> target
match (RE -> Regex
reRegex RE
rex) ByteString
bs
(=~~) :: ( Monad m, MonadFail m
, Functor m
, Typeable a
, RegexContext TDFA.Regex LBS.ByteString a
)
=> LBS.ByteString
-> RE
-> m a
=~~ :: ByteString -> RE -> m a
(=~~) ByteString
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 -> ByteString -> m a
forall regex source target (m :: * -> *).
(RegexContext regex source target, MonadFail m) =>
regex -> source -> m target
matchM (RE -> Regex
reRegex RE
rex) ByteString
bs
instance IsRegex RE LBS.ByteString where
matchOnce :: RE -> ByteString -> Match ByteString
matchOnce = (ByteString -> RE -> Match ByteString)
-> RE -> ByteString -> Match ByteString
forall a b c. (a -> b -> c) -> b -> a -> c
flip ByteString -> RE -> Match ByteString
(?=~)
matchMany :: RE -> ByteString -> Matches ByteString
matchMany = (ByteString -> RE -> Matches ByteString)
-> RE -> ByteString -> Matches ByteString
forall a b c. (a -> b -> c) -> b -> a -> c
flip ByteString -> RE -> Matches ByteString
(*=~)
makeRegexWith :: SimpleREOptions -> ByteString -> 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) -> (ByteString -> String) -> ByteString -> m RE
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
forall a. Replace a => a -> String
unpackR
makeSearchReplaceWith :: SimpleREOptions
-> ByteString -> ByteString -> m (SearchReplace RE ByteString)
makeSearchReplaceWith = \SimpleREOptions
o ByteString
r ByteString
t -> SimpleREOptions
-> String -> String -> m (SearchReplace RE ByteString)
forall (m :: * -> *) s.
(Monad m, MonadFail m, Functor m, IsRegex RE s) =>
SimpleREOptions -> String -> String -> m (SearchReplace RE s)
compileSearchReplaceWith SimpleREOptions
o (ByteString -> String
forall a. Replace a => a -> String
unpackR ByteString
r) (ByteString -> String
forall a. Replace a => a -> String
unpackR ByteString
t)
regexSource :: RE -> ByteString
regexSource = String -> ByteString
forall a. Replace a => String -> a
packR (String -> ByteString) -> (RE -> String) -> RE -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RE -> String
reSource