-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | PCRE wrapper -- -- format, search, replace (String | ByteString) with PCRE regex. -- Utf8-safe @package regex-do @version 3.2.2 module Text.Regex.Do.Match.Option -- | pcre man pages data Comp -- | compBlank -- -- clears default options: extended,caseSensitive,multiline regex Blank :: Comp -- | compAnchored -- -- the pattern is forced to be "anchored", that is, it is constrained to -- match only at the first matching point in the string that is being -- searched (the "subject string"). -- -- This effect can also be achieved by appropriate constructs in the -- pattern itself. Anchored :: Comp -- | compCaseless -- -- letters in the pattern match both upper and lower case letters. -- -- It is equivalent to Perl's /i option, and it can be changed within a -- pattern by a (?i) option setting. -- -- In UTF-8 mode, PCRE always understands the concept of case for -- characters whose values are less than 128, so caseless matching is -- always possible. For characters with higher values, the concept of -- case is supported if PCRE is compiled with Unicode property support. -- If you want to use caseless matching for characters 128 and above, you -- must ensure that PCRE is compiled with Unicode property support as -- well as with UTF-8 support. Caseless :: Comp -- | compDotAll -- -- a dot metacharacter in the pattern matches a character of any value, -- including one that indicates a newline. -- -- However, it only ever matches one character, even if newlines are -- coded as CRLF. -- -- Without this option, a dot does not match when the current position is -- at a newline. -- -- This option is equivalent to Perl's /s option, and it can be changed -- within a pattern by a (?s) option setting. -- -- A negative class such as [^a] always matches newline characters, -- independent of the setting of this option. Dotall :: Comp -- | compMultiline -- -- By default, for the purposes of matching "start of line" and "end of -- line", PCRE treats the subject string as consisting of a single line -- of characters, even if it actually contains newlines. The "start of -- line" metacharacter (^) matches only at the start of the string, and -- the "end of line" metacharacter ($) matches only at the end of the -- string, or before a terminating newline (except when -- PCRE_DOLLAR_ENDONLY is set). Note, however, that unless PCRE_DOTALL is -- set, the "any character" metacharacter (.) does not match at a -- newline. This behaviour (for ^, $, and dot) is the same as Perl. -- -- When PCRE_MULTILINE it is set, the "start of line" and "end of line" -- constructs match immediately following or immediately before internal -- newlines in the subject string, respectively, as well as at the very -- start and end. -- -- This is equivalent to Perl's /m option, and it can be changed within a -- pattern by a (?m) option setting. -- -- If there are no newlines in a subject string, or no occurrences of ^ -- or $ in a pattern, setting PCRE_MULTILINE has no effect. Multiline :: Comp -- | compUTF8 -- -- This option causes PCRE to regard both the pattern and the subject as -- strings of UTF-8 characters instead of single-byte strings. However, -- it is available only when PCRE is built to include UTF support. If -- not, the use of this option provokes an error. Details of how this -- option changes the behaviour of PCRE are given in the pcreunicode -- page. Utf8 :: Comp -- | compUngreedy -- -- This option inverts the "greediness" of the quantifiers so that they -- are not greedy by default, but become greedy if followed by "?". -- -- It can also be set by a (?U) option setting within the pattern. Ungreedy :: Comp data Exec -- | execBlank -- -- clears default options: extended,caseSensitive,multiline regex BlankE :: Exec -- | execNotEmpty -- -- An empty string is not considered to be a valid match if this option -- is set. If there are alternatives in the pattern, they are tried. If -- all the alternatives match the empty string, the entire match fails. -- For example, if the pattern -- -- a?b? -- -- is applied to a string not beginning with "a" or "b", it matches an -- empty string at the start of the subject. With PCRE_NOTEMPTY set, this -- match is not valid, so PCRE searches further into the string for -- occurrences of "a" or "b". NotEmpty :: Exec -- | execPartial -- -- see PCREPARTIAL(3) in pcre man pages Partial :: Exec comp :: [Comp] -> CompOption exec :: [Exec] -> ExecOption instance GHC.Enum.Enum Text.Regex.Do.Match.Option.Exec instance GHC.Classes.Ord Text.Regex.Do.Match.Option.Exec instance GHC.Classes.Eq Text.Regex.Do.Match.Option.Exec instance GHC.Enum.Enum Text.Regex.Do.Match.Option.Comp instance GHC.Classes.Ord Text.Regex.Do.Match.Option.Comp instance GHC.Classes.Eq Text.Regex.Do.Match.Option.Comp module Text.Regex.Do.Pad -- | pad String with Char to total length of Int -- -- pad on left -- --
-- >>> pad '-' 5 "abc" ---- -- "--abc" pad :: Char -> Int -> String -> String -- | pad on right -- --
-- >>> pad' '-' 5 "abc" ---- -- "abc--" pad' :: Char -> Int -> String -> String module Text.Regex.Do.Type.Convert -- | both Ascii and Utf8 toByteString :: String -> ByteString -- | both Ascii and Utf8 toString :: ByteString -> String class ToArray a toArray :: ToArray a => a -> MatchArray instance Text.Regex.Do.Type.Convert.ToArray Text.Regex.Base.RegexLike.MatchArray instance Text.Regex.Do.Type.Convert.ToArray [Text.Regex.Do.Type.Do_.PosLen] module Text.Regex.Do.Type.Do -- | see Text.Regex.Do.Replace.Open defaultReplacer for -- example implementation newtype GroupReplacer b GroupReplacer :: (MatchArray -> ReplaceAcc b -> ReplaceAcc b) -> GroupReplacer b data ReplaceAcc b ReplaceAcc :: b -> Int -> ReplaceAcc b -- | content with some replacements made [acc] :: ReplaceAcc b -> b -- | position adjustment: group replacement length may differ from replaced -- text length [pos_adj] :: ReplaceAcc b -> Int -- | Offset, Length type PosLen = (MatchOffset, MatchLength) -- | Left String returns regex construction error type E a = Either String a newtype Once a -- | replace once Once :: a -> Once a newtype All a -- | replace all All :: a -> All a -- | A compiled regular expression data Regex -- | 0 based array, with 0th index indicating the full match. If the full -- match location is not available, represent as (0,0). type MatchArray = Array Int (MatchOffset, MatchLength) newtype CompOption CompOption :: CInt -> CompOption data ExecOption module Text.Regex.Do.Type.Extract -- | see String, ByteString instances for implementation examples -- -- see Text.Regex.Base.RegexLike for Extract detail class Extract a => Extract' a concat' :: Extract' a => [a] -> a len' :: Extract' a => a -> Int prefix :: Extract a => PosLen -> a -> a suffix :: Extract a => PosLen -> a -> a instance Text.Regex.Do.Type.Extract.Extract' GHC.Base.String instance Text.Regex.Do.Type.Extract.Extract' Data.ByteString.Internal.ByteString instance Text.Regex.Do.Type.Extract.Extract' Data.Text.Internal.Text -- | extensible and reusable replacement functions -- -- Run replacement with your preferred content types e.g. -- Data.Text (implemented), -- -- from search results with non-PCRE regex or non-regex libs -- --
-- >>> replace (Just [(4,3)::PosLen]) "4567" ("abc 123 def"::Text)
--
--
-- "abc 4567 def"
--
-- GroupReplacer : replace with a function
--
-- -- replacer::GroupReplacer Text -- replacer = defaultReplacer 1 tweak1 -- 1: group 1 match. -- where tweak1 str1 = case str1 of -- "123" -> "[1-2-3]" -- otherwise -> traceShow str1 "?" ---- --
-- >>> replace (Just ([(4,3)]::[PosLen])) replacer ("abc 123 def"::Text)
--
--
-- "abc [1-2-3] def"
module Text.Regex.Do.Replace.Open
class Replace f repl body
replace :: (Replace f repl body, Extract' body, ToArray arr) => f arr -> repl -> body -> body
-- | Replaces specified (by idx) group match with value provided by (a
-- -> a) fn. Works for one common simple use case
--
-- GroupReplacer can also be used with multi-group regex
--
-- another custom dynamic replacer could e.g. inspect all group matches
-- before looking up a replacement.
defaultReplacer :: Extract' a => Int -> (a -> a) -> GroupReplacer a
-- | get group content safely:
--
-- -- import Prelude hiding((/)) ---- -- or qualify / with alias e.g. (assuming this module is imported -- with S alias): -- --
-- S./ ---- -- body -> pattern -> result class Split out (/) :: Split out => ByteString -> ByteString -> out -- | keep needle @ front class SplitFront out (-/) :: SplitFront out => ByteString -> ByteString -> out -- | keep needle @ end class SplitEnd out (/-) :: SplitEnd out => ByteString -> ByteString -> out -- | Break result: tuple type T = (ByteString, ByteString) -- | Split result: list type L = [ByteString] instance Text.Regex.Do.Split.SplitEnd (Data.ByteString.Internal.ByteString, Data.ByteString.Internal.ByteString) instance Text.Regex.Do.Split.SplitEnd [Data.ByteString.Internal.ByteString] instance Text.Regex.Do.Split.SplitFront (Data.ByteString.Internal.ByteString, Data.ByteString.Internal.ByteString) instance Text.Regex.Do.Split.SplitFront [Data.ByteString.Internal.ByteString] instance Text.Regex.Do.Split.Split (Data.ByteString.Internal.ByteString, Data.ByteString.Internal.ByteString) instance Text.Regex.Do.Split.Split [Data.ByteString.Internal.ByteString] -- | see also Text.Regex.Do.Replace.Latin -- -- toByteString converts String to ByteString module Text.Regex.Do.Replace.Utf8 -- | see Text.Regex.Do.Replace.Latin for implemented types -- -- GroupReplacer is implemented only for ByteString class Replace hint pattern repl body out replace :: (Replace hint pattern repl body out, Extract' body, RegexLike Regex body) => hint pattern -> repl -> body -> out instance Text.Regex.Do.Replace.Utf8.Replace Text.Regex.Do.Type.MatchHint.Once Text.Regex.PCRE.Wrap.Regex GHC.Base.String GHC.Base.String GHC.Base.String instance Text.Regex.Do.Replace.Utf8.Replace Text.Regex.Do.Type.MatchHint.All Text.Regex.PCRE.Wrap.Regex GHC.Base.String GHC.Base.String GHC.Base.String instance Text.Regex.Do.Replace.Open.Replace GHC.Maybe.Maybe repl Data.ByteString.Internal.ByteString => Text.Regex.Do.Replace.Utf8.Replace Text.Regex.Do.Type.MatchHint.Once Text.Regex.PCRE.Wrap.Regex repl Data.ByteString.Internal.ByteString Data.ByteString.Internal.ByteString instance Text.Regex.Do.Replace.Open.Replace [] repl Data.ByteString.Internal.ByteString => Text.Regex.Do.Replace.Utf8.Replace Text.Regex.Do.Type.MatchHint.All Text.Regex.PCRE.Wrap.Regex repl Data.ByteString.Internal.ByteString Data.ByteString.Internal.ByteString instance Text.Regex.Do.Replace.Utf8.Replace Text.Regex.Do.Type.MatchHint.Once GHC.Base.String GHC.Base.String GHC.Base.String (Text.Regex.Do.Type.Do_.E GHC.Base.String) instance Text.Regex.Do.Replace.Utf8.Replace Text.Regex.Do.Type.MatchHint.All GHC.Base.String GHC.Base.String GHC.Base.String (Text.Regex.Do.Type.Do_.E GHC.Base.String) instance Text.Regex.Do.Replace.Utf8.Replace Text.Regex.Do.Type.MatchHint.Once Data.ByteString.Internal.ByteString Data.ByteString.Internal.ByteString Data.ByteString.Internal.ByteString (Text.Regex.Do.Type.Do_.E Data.ByteString.Internal.ByteString) instance Text.Regex.Do.Replace.Utf8.Replace Text.Regex.Do.Type.MatchHint.All Data.ByteString.Internal.ByteString Data.ByteString.Internal.ByteString Data.ByteString.Internal.ByteString (Text.Regex.Do.Type.Do_.E Data.ByteString.Internal.ByteString) instance Text.Regex.Do.Replace.Utf8.Replace Text.Regex.Do.Type.MatchHint.Once Data.ByteString.Internal.ByteString (Text.Regex.Do.Type.Do_.GroupReplacer Data.ByteString.Internal.ByteString) Data.ByteString.Internal.ByteString (Text.Regex.Do.Type.Do_.E Data.ByteString.Internal.ByteString) instance Text.Regex.Do.Replace.Utf8.Replace Text.Regex.Do.Type.MatchHint.All Data.ByteString.Internal.ByteString (Text.Regex.Do.Type.Do_.GroupReplacer Data.ByteString.Internal.ByteString) Data.ByteString.Internal.ByteString (Text.Regex.Do.Type.Do_.E Data.ByteString.Internal.ByteString) -- | for reliable results with Utf8 pattern or body, use -- Text.Regex.Do.Replace.Utf8 module Text.Regex.Do.Replace.Latin -- | hint: All | Once -- -- pattern: Regex, String, ByteString -- -- String | ByteString pattern may contains regex -- -- body: String, ByteString -- -- result is Either String body: Left String returns regex -- construction errors. class Replace hint pattern repl body out replace :: (Replace hint pattern repl body out, Extract' body, RegexLike Regex body) => hint pattern -> repl -> body -> out instance (Text.Regex.Base.RegexLike.RegexLike Text.Regex.PCRE.Wrap.Regex b, Text.Regex.Do.Replace.Open.Replace GHC.Maybe.Maybe repl b) => Text.Regex.Do.Replace.Latin.Replace Text.Regex.Do.Type.MatchHint.Once Text.Regex.PCRE.Wrap.Regex repl b b instance (Text.Regex.Base.RegexLike.RegexLike Text.Regex.PCRE.Wrap.Regex b, Text.Regex.Do.Replace.Open.Replace [] repl b) => Text.Regex.Do.Replace.Latin.Replace Text.Regex.Do.Type.MatchHint.All Text.Regex.PCRE.Wrap.Regex repl b b instance (Text.Regex.Base.RegexLike.RegexLike Text.Regex.PCRE.Wrap.Regex b, Text.Regex.Do.Match.Regex.Regex b) => Text.Regex.Do.Replace.Latin.Replace Text.Regex.Do.Type.MatchHint.Once b b b (Text.Regex.Do.Type.Do_.E b) instance (Text.Regex.Base.RegexLike.RegexLike Text.Regex.PCRE.Wrap.Regex b, Text.Regex.Do.Match.Regex.Regex b) => Text.Regex.Do.Replace.Latin.Replace Text.Regex.Do.Type.MatchHint.Once b (Text.Regex.Do.Type.Do_.GroupReplacer b) b (Text.Regex.Do.Type.Do_.E b) instance (Text.Regex.Base.RegexLike.RegexLike Text.Regex.PCRE.Wrap.Regex b, Text.Regex.Do.Match.Regex.Regex b) => Text.Regex.Do.Replace.Latin.Replace Text.Regex.Do.Type.MatchHint.All b b b (Text.Regex.Do.Type.Do_.E b) instance (Text.Regex.Base.RegexLike.RegexLike Text.Regex.PCRE.Wrap.Regex b, Text.Regex.Do.Match.Regex.Regex b) => Text.Regex.Do.Replace.Latin.Replace Text.Regex.Do.Type.MatchHint.All b (Text.Regex.Do.Type.Do_.GroupReplacer b) b (Text.Regex.Do.Type.Do_.E b) module Text.Regex.Do.Trim -- | removes leading and trailing spaces and tabs class Trim a trim :: Trim a => a -> a instance Text.Regex.Do.Trim.Trim Data.ByteString.Internal.ByteString instance Text.Regex.Do.Trim.Trim GHC.Base.String instance Text.Regex.Do.Trim.Trim Data.Text.Internal.Text -- | simple (no regex) fast replace on ByteStrings -- -- All occurrences are replaced. There is no Once option -- -- see replace for detail module Text.Regex.Do.Replace.Fast -- |
-- >>> replace "\n" "," "a\nbc\nde" ---- -- "a,bc,de" replace :: ByteString -> ByteString -> ByteString -> ByteString -- | formerly Format -- -- substitutes placeholder values with values from args -- -- in lieu of format function there are 2 operators: < -- and >: no need to remember arg order. -- --
-- import Prelude hiding((<),(>)) ---- -- or qualify < with alias e.g. (assuming this module is -- imported with F alias): -- --
-- F.< --module Text.Regex.Do.Replace.Template -- |