-- 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 2.5 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 -- | reexport common types from Text.Regex.PCRE module Text.Regex.Do.Type.Reexport -- | 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.Pcre.Option -- | pcre man pages data Comp -- | compBlank 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 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.Pcre.Option.Exec instance GHC.Classes.Ord Text.Regex.Do.Pcre.Option.Exec instance GHC.Classes.Eq Text.Regex.Do.Pcre.Option.Exec instance GHC.Enum.Enum Text.Regex.Do.Pcre.Option.Comp instance GHC.Classes.Ord Text.Regex.Do.Pcre.Option.Comp instance GHC.Classes.Eq Text.Regex.Do.Pcre.Option.Comp module Text.Regex.Do.Type.MatchHint newtype Test a -- | test: does body match pattern? Test :: a -> Test a newtype Once a -- | values Once :: a -> Once a newtype All a -- | values All :: a -> All a newtype PosLen' a -- | once PosLen' :: a -> PosLen' a newtype PosLen_ a -- | all PosLen_ :: a -> PosLen_ a class Hint hint unhint :: Hint hint => hint a -> a hint :: Hint hint => a -> hint a instance GHC.Base.Functor Text.Regex.Do.Type.MatchHint.All instance GHC.Base.Functor Text.Regex.Do.Type.MatchHint.Once instance Text.Regex.Do.Type.MatchHint.Hint Text.Regex.Do.Type.MatchHint.Test instance Text.Regex.Do.Type.MatchHint.Hint Text.Regex.Do.Type.MatchHint.Once instance Text.Regex.Do.Type.MatchHint.Hint Text.Regex.Do.Type.MatchHint.All instance Text.Regex.Do.Type.MatchHint.Hint Text.Regex.Do.Type.MatchHint.PosLen' instance Text.Regex.Do.Type.MatchHint.Hint Text.Regex.Do.Type.MatchHint.PosLen_ instance GHC.Base.Applicative Text.Regex.Do.Type.MatchHint.Once instance GHC.Base.Applicative Text.Regex.Do.Type.MatchHint.All module Text.Regex.Do.Type.Do -- | see Text.Regex.Do.Pcre.ReplaceOpen 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 -- | Needle data Pattern a Pattern :: a -> Pattern a -- | Haystack data Body b Body :: b -> Body b data Replacement r Replacement :: r -> Replacement r -- | Offset, Length type PosLen = (MatchOffset, MatchLength) newtype Utf8_ a -- | values Utf8_ :: a -> Utf8_ a -- | does not do any codec. Plain wrap / unwrap newtype -- | does not do any codec. Plain wrap / unwrap newtype class Enc enc val :: Enc enc => enc a -> a enc :: Enc enc => a -> enc a class Enc' f enc val' :: Enc' f enc => f (enc a) -> f a enc' :: Enc' f enc => f a -> f (enc a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Text.Regex.Do.Type.Do.Utf8_ a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Text.Regex.Do.Type.Do.Utf8_ a) instance GHC.Base.Functor Text.Regex.Do.Type.Do.Utf8_ instance GHC.Base.Functor Text.Regex.Do.Type.Do.Replacement instance GHC.Base.Functor Text.Regex.Do.Type.Do.Body instance GHC.Base.Functor Text.Regex.Do.Type.Do.Pattern instance GHC.Base.Functor Text.Regex.Do.Type.Do.ReplaceAcc instance GHC.Base.Applicative Text.Regex.Do.Type.Do.Pattern instance GHC.Base.Applicative Text.Regex.Do.Type.Do.Body instance GHC.Base.Applicative Text.Regex.Do.Type.Do.Replacement instance GHC.Base.Applicative Text.Regex.Do.Type.Do.Utf8_ instance Text.Regex.Do.Type.Do.Enc Text.Regex.Do.Type.Do.Utf8_ instance Text.Regex.Do.Type.Do.Enc enc => Text.Regex.Do.Type.Do.Enc' Text.Regex.Do.Type.Do.GroupReplacer enc module Text.Regex.Do.Convert -- | both Ascii and Utf8 toByteString :: String -> ByteString toByteString' :: String -> Utf8_ ByteString -- | both Ascii and Utf8 toString :: ByteString -> String class ToArray a toArray :: ToArray a => a -> MatchArray instance Text.Regex.Do.Convert.ToArray Text.Regex.Base.RegexLike.MatchArray instance Text.Regex.Do.Convert.ToArray [Text.Regex.Do.Type.Do.PosLen] module Text.Regex.Do.Type.Regex class Regex a makeRegex :: Regex a => Pattern a -> Regex makeRegexOpt :: Regex a => Pattern a -> [Comp] -> [Exec] -> Regex makeRegex' :: Regex a => Pattern a -> Pattern Regex makeRegexOpt' :: Regex a => Pattern a -> [Comp] -> [Exec] -> Pattern Regex type Rx_ a b = (Regex a, Extract b, RegexLike Regex b) type Opt_ a = RegexMaker Regex CompOption ExecOption a type Ro_ rx = (Regex rx, Opt_ rx) instance Text.Regex.Do.Type.Regex.Regex a => Text.Regex.Do.Type.Regex.Regex (Text.Regex.Do.Type.Do.Utf8_ a) instance Text.Regex.Do.Type.Regex.Regex Data.ByteString.Internal.ByteString instance Text.Regex.Do.Type.Regex.Regex GHC.Base.String instance Text.Regex.Do.Type.Regex.Regex Text.Regex.PCRE.Wrap.Regex -- | see Data.ByteString.Search package -- -- regex is treated as ordinary String module Text.Regex.Do.Split -- |
-- >>> break Drop (Pattern "\n") (Body "a\nbc\nde") ---- -- ("a", "bc\nde") -- --
-- >>> break Front (Pattern "\n") (Body "a\nbc\nde") ---- -- ("a", "\nbc\nde") -- --
-- >>> break End (Pattern "\n") (Body "a\nbc\nde") ---- -- ("a\n", "bc\nde") break :: KeepNeedle -> Pattern ByteString -> Body ByteString -> (ByteString, ByteString) -- |
-- >>> replace (Pattern "\n") (Replacement ",") (Body "a\nbc\nde") ---- -- "a,bc,de" replace :: Pattern ByteString -> Replacement ByteString -> Body ByteString -> ByteString -- |
-- >>> split Drop (Pattern " ") (Body "a bc de") ---- -- ["a", "bc", "de"] -- -- space may be used -- --
-- >>> split Front (Pattern "\n") (Body "a\nbc\nde") ---- -- ["a", "\nbc", "\nde"] -- --
-- >>> split End (Pattern "\n") (Body "a\nbc\nde") ---- -- ["a\n", "bc\n", "de"] split :: KeepNeedle -> Pattern ByteString -> Body ByteString -> [ByteString] data KeepNeedle -- | needle between parts disappears Drop :: KeepNeedle -- | needle sticks to front of next part Front :: KeepNeedle -- | needle sticks to end of previous part End :: KeepNeedle module Text.Regex.Do.Format class Format a format :: Format a => String -> a -> String instance Text.Regex.Do.Format.Format [GHC.Base.String] instance Text.Regex.Do.Format.Format [(GHC.Base.String, GHC.Base.String)] -- | internal module, exposed only to show the instances module Text.Regex.Do.Pcre.Matchf type R_ b = RegexLike Regex b class Matchf hint b where type family H hint type family P hint marray_ :: (Matchf hint b, R_ b) => hint (Pattern Regex) -> Body b -> H hint poslen_ :: (Matchf hint b, R_ b) => hint (Pattern Regex) -> Body b -> P hint once :: (R_ b, Extract b) => Pattern Regex -> Body b -> [b] all :: (R_ b, Extract b) => Pattern Regex -> Body b -> [[b]] instance Text.Regex.Do.Pcre.Matchf.Matchf Text.Regex.Do.Type.MatchHint.Once b instance Text.Regex.Do.Pcre.Matchf.Matchf Text.Regex.Do.Type.MatchHint.All b -- | although sometimes funs in Ascii modules work with non-ascii text (as -- some examples show), for reliable results with Utf8 pattern or body, -- use Text.Regex.Do.Pcre.Utf8.Match -- -- see also Text.Regex.Base.RegexLike and -- Text.Regex.Do.Pcre.Ascii.MatchHint module Text.Regex.Do.Pcre.Ascii.Match -- | match covers all result types -- -- compiler looks up the appropriate function depending on the result -- type -- -- =~ is borrowed from Text.Regex.PCRE.Wrap, is a short -- version of match -- -- See also Text.Regex.Do.Pcre.Ascii.MatchHint class Match a b out where (=~) p0 b0 = match (Pattern p0) (Body b0) match :: Match a b out => Pattern a -> Body b -> out (=~) :: Match a b out => a -> b -> out -- | extract takes an offset and length and has a default implementation of -- extract (off,len) source = before len (after off source) extract :: Extract source => (Int, Int) -> source -> source instance Text.Regex.Do.Type.Regex.Rx_ a b => Text.Regex.Do.Pcre.Ascii.Match.Match a b [b] instance Text.Regex.Do.Type.Regex.Rx_ a b => Text.Regex.Do.Pcre.Ascii.Match.Match a b GHC.Types.Bool instance Text.Regex.Do.Type.Regex.Rx_ a b => Text.Regex.Do.Pcre.Ascii.Match.Match a b [[b]] instance Text.Regex.Do.Type.Regex.Rx_ a b => Text.Regex.Do.Pcre.Ascii.Match.Match a b [Text.Regex.Do.Type.Do.PosLen] instance Text.Regex.Do.Type.Regex.Rx_ a b => Text.Regex.Do.Pcre.Ascii.Match.Match a b [[Text.Regex.Do.Type.Do.PosLen]] -- | this module uses TypeFamilies -- -- this module is similar to Text.Regex.Do.Pcre.Ascii.Match. The -- differences are: -- -- Text.Regex.Do.Pcre.Ascii.Match is more flexible: accepts -- Pattern Regex, accepts Pattern and Body of -- different types -- -- Text.Regex.Do.Pcre.Ascii.Match needs to infer result type -- -- in this module the result type is determined by the hint module Text.Regex.Do.Pcre.Ascii.MatchHint -- | picks Match instance where Pattern and Body are -- of the same type -- -- Hint and inferrable Pattern or Body type -- determine the instance -- -- handy when working with OverloadedStrings, in other cases -- when compiler needs a hint class (Hint hint, Match a a (F hint a)) => MatchHint hint a where type family F hint a match h0 = match $ unhint h0 (=~) h0 = (=~) $ unhint h0 match :: MatchHint hint a => hint (Pattern a) -> Body a -> F hint a (=~) :: MatchHint hint a => hint a -> a -> F hint a -- |
-- >>> PosLen' ("и"::String) =~ "бывает и хуже"
--
--
-- [(13,2)]
-- |
-- >>> Once ("^all"::String) =~ "all the time"
--
--
-- ["all"]
-- |
-- >>> Test ("в"::ByteString) =~ "тихо в лесу"
--
--
-- True
instance Text.Regex.Do.Pcre.Ascii.MatchHint.MatchHint Text.Regex.Do.Type.MatchHint.Test GHC.Base.String
instance Text.Regex.Do.Pcre.Ascii.MatchHint.MatchHint Text.Regex.Do.Type.MatchHint.PosLen' GHC.Base.String
instance Text.Regex.Do.Pcre.Ascii.MatchHint.MatchHint Text.Regex.Do.Type.MatchHint.PosLen_ GHC.Base.String
instance Text.Regex.Do.Pcre.Ascii.MatchHint.MatchHint Text.Regex.Do.Type.MatchHint.Once GHC.Base.String
instance Text.Regex.Do.Pcre.Ascii.MatchHint.MatchHint Text.Regex.Do.Type.MatchHint.All GHC.Base.String
instance Text.Regex.Do.Pcre.Ascii.MatchHint.MatchHint Text.Regex.Do.Type.MatchHint.Test Data.ByteString.Internal.ByteString
instance Text.Regex.Do.Pcre.Ascii.MatchHint.MatchHint Text.Regex.Do.Type.MatchHint.PosLen' Data.ByteString.Internal.ByteString
instance Text.Regex.Do.Pcre.Ascii.MatchHint.MatchHint Text.Regex.Do.Type.MatchHint.PosLen_ Data.ByteString.Internal.ByteString
instance Text.Regex.Do.Pcre.Ascii.MatchHint.MatchHint Text.Regex.Do.Type.MatchHint.Once Data.ByteString.Internal.ByteString
instance Text.Regex.Do.Pcre.Ascii.MatchHint.MatchHint Text.Regex.Do.Type.MatchHint.All Data.ByteString.Internal.ByteString
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.Base.RegexLike.Extract (Text.Regex.Do.Type.Do.Utf8_ Data.ByteString.Internal.ByteString)
instance Text.Regex.Do.Type.Extract.Extract' (Text.Regex.Do.Type.Do.Utf8_ Data.ByteString.Internal.ByteString)
instance Text.Regex.Base.RegexLike.Extract Data.Text.Internal.Text
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, from search results with non-PCRE regex or non-regex
-- libs
--
-- open an issue or a PR on git to request a new Extract'
-- instance
--
-- Data.Text instance already works
module Text.Regex.Do.ReplaceOpen
-- | Replacement:
--
-- -- >>> replace (Just [(4,3)::PosLen]) (Replacement "4567") (Body "abc 123 def"::Body Text) ---- -- "abc 4567 def" -- -- GroupReplacer : -- --
-- >>> replacer::GroupReplacer Text -- replacer = defaultReplacer 1 tweak1 -- 1: first match in group -- where tweak1 str1 = case str1 of -- "123" -> "[1-2-3]" -- otherwise -> traceShow str1 "?" ---- --
-- >>> replace (Just ([(4,3),(8,2)]::[PosLen])) replacer (Body "abc 123 def"::Body Text) ---- -- "abc [1-2-3] def" class ReplaceOpen f r replace :: (ReplaceOpen f r, Extract' a, ToArray arr) => f arr -> r a -> Body a -> a -- | Replaces specified (by idx) group match with tweaked value. Works for -- one common simple use case -- -- GroupReplacer can be used with complicated 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 -- -- see defaultReplacer source for use example getGroup :: Extract a => ReplaceAcc a -> MatchArray -> Int -> Maybe a -- | call from your custom GroupReplacer passed to -- replaceGroup -- -- see defaultReplacer source for use example replaceMatch :: Extract' a => PosLen -> (a, ReplaceAcc a) -> ReplaceAcc a instance Text.Regex.Do.ReplaceOpen.ReplaceOpen GHC.Base.Maybe Text.Regex.Do.Type.Do.Replacement instance Text.Regex.Do.ReplaceOpen.ReplaceOpen [] Text.Regex.Do.Type.Do.Replacement instance Text.Regex.Do.ReplaceOpen.ReplaceOpen GHC.Base.Maybe Text.Regex.Do.Type.Do.GroupReplacer instance Text.Regex.Do.ReplaceOpen.ReplaceOpen [] Text.Regex.Do.Type.Do.GroupReplacer -- |