-- 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.1 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 data Comp -- | compBlank Blank :: Comp -- | compAnchored Anchored :: Comp -- | compCaseless Caseless :: Comp -- | compDotAll Dotall :: Comp -- | compMultiline Multiline :: Comp -- | compUTF8 Utf8 :: Comp -- | compUngreedy Ungreedy :: Comp data Exec -- | execBlank BlankE :: Exec -- | execNotEmpty NotEmpty :: Exec -- | execPartial Partial :: Exec comp :: [Comp] -> CompOption exec :: [Exec] -> ExecOption instance GHC.Enum.Enum Text.Regex.Do.Pcre.Option.Exec instance GHC.Enum.Enum Text.Regex.Do.Pcre.Option.Comp 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) data ReplaceCase -- | may be omitted Once :: ReplaceCase -- | if both Once and All are passed, All prevails All :: ReplaceCase Utf8 :: ReplaceCase Multiline :: ReplaceCase type Opt_ a = RegexMaker Regex CompOption ExecOption a instance GHC.Classes.Eq Text.Regex.Do.Type.Do.ReplaceCase 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 module Text.Regex.Do.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.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 r_ :: Regex_ a => Pattern a -> Regex type Rx_ a b = (Regex_ a, Extract b, RegexLike Regex b) 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 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 Data.Text.Internal.Text instance Text.Regex.Do.Type.Extract.Extract' Data.Text.Internal.Text -- | 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)] -- | see Text.Regex.Base.RegexLike module Text.Regex.Do.Pcre.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.MatchSame 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 -- | tweak Regex with options makeRegexOpts :: Opt_ a => [Comp] -> [Exec] -> Pattern a -> Regex instance Text.Regex.Do.Type.Regex_.Rx_ a b => Text.Regex.Do.Pcre.Match.Match a b [b] instance Text.Regex.Do.Type.Regex_.Rx_ a b => Text.Regex.Do.Pcre.Match.Match a b GHC.Types.Bool instance Text.Regex.Do.Type.Regex_.Rx_ a b => Text.Regex.Do.Pcre.Match.Match a b [[b]] instance Text.Regex.Do.Type.Regex_.Rx_ a b => Text.Regex.Do.Pcre.Match.Match a b [Text.Regex.Do.Type.Do.PosLen] instance Text.Regex.Do.Type.Regex_.Rx_ a b => Text.Regex.Do.Pcre.Match.Match a b [[Text.Regex.Do.Type.Do.PosLen]] module Text.Regex.Do.Pcre.MatchSame -- | picks Match instance where Pattern and Body are -- of the same type -- -- specify either Pattern or Body + out types -- -- handy when working with OverloadedStrings -- --
-- >>> ("^all"::String) -~ "all the time"::[String]
--
--
-- ["all"]
class MatchSame a out where match' = match (-~) = (=~)
match' :: (MatchSame a out, Match a a out) => Pattern a -> Body a -> out
(-~) :: (MatchSame a out, Match a a out) => a -> a -> out
instance Text.Regex.Do.Pcre.MatchSame.MatchSame GHC.Base.String GHC.Types.Bool
instance Text.Regex.Do.Pcre.MatchSame.MatchSame GHC.Base.String [GHC.Base.String]
instance Text.Regex.Do.Pcre.MatchSame.MatchSame GHC.Base.String [[GHC.Base.String]]
instance Text.Regex.Do.Pcre.MatchSame.MatchSame GHC.Base.String [Text.Regex.Do.Type.Do.PosLen]
instance Text.Regex.Do.Pcre.MatchSame.MatchSame GHC.Base.String [[Text.Regex.Do.Type.Do.PosLen]]
instance Text.Regex.Do.Pcre.MatchSame.MatchSame Data.ByteString.Internal.ByteString GHC.Types.Bool
instance Text.Regex.Do.Pcre.MatchSame.MatchSame Data.ByteString.Internal.ByteString [Data.ByteString.Internal.ByteString]
instance Text.Regex.Do.Pcre.MatchSame.MatchSame Data.ByteString.Internal.ByteString [[Data.ByteString.Internal.ByteString]]
instance Text.Regex.Do.Pcre.MatchSame.MatchSame Data.ByteString.Internal.ByteString [Text.Regex.Do.Type.Do.PosLen]
instance Text.Regex.Do.Pcre.MatchSame.MatchSame Data.ByteString.Internal.ByteString [[Text.Regex.Do.Type.Do.PosLen]]
-- | 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.Pcre.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.Pcre.ReplaceOpen.ReplaceOpen GHC.Base.Maybe Text.Regex.Do.Type.Do.Replacement instance Text.Regex.Do.Pcre.ReplaceOpen.ReplaceOpen [] Text.Regex.Do.Type.Do.Replacement instance Text.Regex.Do.Pcre.ReplaceOpen.ReplaceOpen GHC.Base.Maybe Text.Regex.Do.Type.Do.GroupReplacer instance Text.Regex.Do.Pcre.ReplaceOpen.ReplaceOpen [] Text.Regex.Do.Type.Do.GroupReplacer module Text.Regex.Do.Pcre.Replace -- |
-- >>> replacer::GroupReplacer String -- replacer = defaultReplacer 1 tweak1 -- where tweak1 str1 = case str1 of -- "101" -> "[сто один]" -- "3" -> "[three]" -- otherwise -> trace str1 "?" ---- -- Once vs All options -- --
-- >>> replace [Once,Utf8] (Pattern "\\w=(\\d{1,3})") replacer $ Body "a=101 b=3 12"
--
--
-- "a=[сто один] b=3 12"
--
--
-- >>> replace [All,Utf8] (Pattern "\\w=(\\d{1,3})") replacer $ Body "a=101 b=3 12"
--
--
-- "a=[сто один] b=[three] 12"
--
-- -- >>> replace [Once,Utf8] (Pattern "менее") (Replacement "более") $ Body "менее менее" ---- -- "более менее" -- --
-- >>> replace [Once,Utf8] (Pattern "^a\\s") (Replacement "A") $ Body "a bc хол.гор." ---- -- "Abc хол.гор." replace :: (Rx_ a a, ReplaceCase_ r a, Opt_ a) => [ReplaceCase] -> Pattern a -> r a -> Body a -> a -- | implementation detail for the curious class ReplaceCase_ r a replace_ :: ReplaceCase_ r a => [ReplaceCase] -> Pattern Regex -> r a -> Body a -> a instance Text.Regex.Do.Pcre.Replace.ReplaceCase_ Text.Regex.Do.Type.Do.Replacement GHC.Base.String instance Text.Regex.Do.Pcre.Replace.ReplaceCase_ Text.Regex.Do.Type.Do.Replacement Data.ByteString.Internal.ByteString instance Text.Regex.Do.Pcre.Replace.ReplaceCase_ Text.Regex.Do.Type.Do.GroupReplacer Data.ByteString.Internal.ByteString instance Text.Regex.Do.Pcre.Replace.ReplaceCase_ Text.Regex.Do.Type.Do.GroupReplacer GHC.Base.String 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