-- 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 1.4 -- | reexport common types from Text.Regex.PCRE module Text.Regex.Do.TypeRegex -- | 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.Convert -- | both Ascii and Utf8 toByteString :: String -> ByteString -- | both Ascii and Utf8 toString :: ByteString -> String module Text.Regex.Do.TypeDo type GroupReplacer a = MatchArray -> ReplaceAcc a -> ReplaceAcc a data ReplaceAcc a ReplaceAcc :: a -> Int -> ReplaceAcc a -- | Body with some replacements made [acc] :: ReplaceAcc a -> a -- | position adjustment: group replacement length may differ from replaced -- text length [pos_adj] :: ReplaceAcc a -> Int -- | Needle data Pattern n Pattern :: n -> Pattern n -- | Haystack data Body h Body :: h -> Body h 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_ n = RegexMaker Regex CompOption ExecOption n instance GHC.Classes.Eq Text.Regex.Do.TypeDo.ReplaceCase instance GHC.Base.Functor Text.Regex.Do.TypeDo.Replacement instance GHC.Base.Functor Text.Regex.Do.TypeDo.Body instance GHC.Base.Functor Text.Regex.Do.TypeDo.Pattern -- | see Text.Regex.Base.RegexLike module Text.Regex.Do.Pcre.Match -- | see Text.Regex.Do.Pcre.Result to convert MatchArray to -- something useful class Rx_ n h => Match n h where matchOnce r0 (Body b0) = matchOnce (r_ r0) b0 matchTest r0 (Body b0) = matchTest (r_ r0) b0 matchAll r0 (Body b0) = matchAll (r_ r0) b0 matchOnce :: Match n h => Pattern n -> Body h -> Maybe MatchArray matchTest :: Match n h => Pattern n -> Body h -> Bool matchAll :: Match n h => Pattern n -> Body h -> [MatchArray] -- | tweak Regex with options makeRegexOpts :: Opt_ n => [Comp] -> [Exec] -> Pattern n -> Regex -- | accepts regex String -- --
-- >>> matchTest (Pattern "^ab") (Body "abc") ---- -- True -- | accepts regex String -- | accepts regex ByteString -- | accepts regex ByteString -- | accepts Regex made with makeRegexOpts -- | accepts Regex made with makeRegexOpts class Regex_ r r_ :: Regex_ r => Pattern r -> Regex type Rx_ n h = (Extract h, Regex_ n, RegexLike Regex h) instance Text.Regex.Do.Pcre.Match.Match GHC.Base.String GHC.Base.String instance Text.Regex.Do.Pcre.Match.Match GHC.Base.String Data.ByteString.Internal.ByteString instance Text.Regex.Do.Pcre.Match.Match Data.ByteString.Internal.ByteString Data.ByteString.Internal.ByteString instance Text.Regex.Do.Pcre.Match.Match Data.ByteString.Internal.ByteString GHC.Base.String instance Text.Regex.Do.Pcre.Match.Match Text.Regex.PCRE.Wrap.Regex GHC.Base.String instance Text.Regex.Do.Pcre.Match.Match Text.Regex.PCRE.Wrap.Regex Data.ByteString.Internal.ByteString instance Text.Regex.Do.Pcre.Match.Regex_ Data.ByteString.Internal.ByteString instance Text.Regex.Do.Pcre.Match.Regex_ GHC.Base.String instance Text.Regex.Do.Pcre.Match.Regex_ Text.Regex.PCRE.Wrap.Regex module Text.Regex.Do.Pcre.Result -- | match offset, length poslen :: Functor f => f MatchArray -> f [PosLen] -- | all groups allMatches :: (Functor f, Extract a) => Body a -> f MatchArray -> f [a] -- | matches for one group groupMatch :: Extract a => Body a -> MatchArray -> [a] -- | 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 module Text.Regex.Do.Pcre.Replace data ReplaceCase -- | may be omitted Once :: ReplaceCase -- | if both Once and All are passed, All prevails All :: ReplaceCase Utf8 :: ReplaceCase Multiline :: ReplaceCase -- |
-- >>> replacer::GroupReplacer String -- replacer = defaultReplacer 1 tweak1 -- where tweak1 str1 = case str1 of -- "101" -> "[сто один]" -- "3" -> "[three]" -- otherwise -> trace str1 "?" ---- -- Once vs All options -- --
-- >>> replaceGroup [Once,Utf8] (Pattern "\\w=(\\d{1,3})", replacer) $ Body "a=101 b=3 12"
--
--
-- "a=[сто один] b=3 12"
--
--
-- >>> replaceGroup [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 хол.гор." class Replace a where replace cases0 pat0 repl0 hay0 = if isUtf8 cases0 then utfFn2 else fn2 (pat2 pat0, repl0) hay0 where fn1 = if elem All cases0 then rall else ronce fn2 = if elem All cases0 then rall else ronce utfFn2 = let res1 = fn1 (pat2 $ toByteString' <$> pat0, toByteString' <$> repl0) $ toByteString' <$> hay0 in toA res1 pat2 pat0 = addOpt pat0 cOpt1 cOpt1 = comp cases0 replaceGroup cases0 pat0 repl0 = fn1 pat2 repl0 where pat2 = addOpt pat0 cOpt cOpt = comp cases0 fn1 = if elem All cases0 then rallGroup else ronceGroup replace :: (Replace a, Mr_ a) => [ReplaceCase] -> Pattern a -> Replacement a -> Body a -> a replaceGroup :: (Replace a, Mr_ a) => [ReplaceCase] -> Pattern a -> GroupReplacer a -> Body a -> a -- | call from your custom GroupReplacer passed to -- replaceGroup -- -- see example replacer above replaceMatch :: Replace_ a => PosLen -> (a, ReplaceAcc a) -> ReplaceAcc a -- | you can write a custom replacer. This is only one common use case. -- -- Replaces specified (by idx) group match with tweaked value. defaultReplacer :: (Replace_ a, Extract a) => Int -> (a -> a) -> GroupReplacer a -- | get group content safely -- -- call from your custom GroupReplacer passed to -- replaceGroup getGroup :: Extract a => ReplaceAcc a -> MatchArray -> Int -> Maybe a type Mr_ a = (Match Regex a, Replace_ a, Opt_ a) instance Text.Regex.Do.Pcre.Replace.Replace GHC.Base.String instance Text.Regex.Do.Pcre.Replace.Replace Data.ByteString.Internal.ByteString instance Text.Regex.Do.Pcre.Replace.Replace_ GHC.Base.String instance Text.Regex.Do.Pcre.Replace.Replace_ Data.ByteString.Internal.ByteString -- | see Data.ByteString.Search package -- -- this module uses newtypes for args -- -- regex is treated as ordinary String module Text.Regex.Do.Split -- | (front, end) : drop needle -- --
-- >>> break (Pattern ":") (Body "0123:oid:90") ---- -- ("0123", "oid:90") -- --
-- >>> break (Pattern "\n") (Body "a\nbc\nde") ---- -- ("a", "bc\nde") break :: Pattern ByteString -> Body ByteString -> (ByteString, ByteString) -- | (front, needle + end) -- --
-- >>> breakFront (Pattern "\n") (Body "a\nbc\nde") ---- -- ("a", "\nbc\nde") breakFront :: Pattern ByteString -> Body ByteString -> (ByteString, ByteString) -- | (front + needle, end) -- --
-- >>> breakEnd (Pattern "\n") (Body "a\nbc\nde") ---- -- ("a\n", "bc\nde") breakEnd :: 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 (Pattern "\n") (Body "a\nbc\nde") ---- -- ["a", "bc", "de"] -- --
-- >>> split (Pattern " ") (Body "a bc de") ---- -- ["a", "bc", "de"] -- --
-- >>> split (Pattern "\\s") (Body "abc de fghi ") ---- -- ["abc de fghi "] split :: Pattern ByteString -> Body ByteString -> [ByteString] -- |
-- >>> splitEnd (Pattern "\n") (Body "a\nbc\nde") ---- -- ["a\n", "bc\n", "de"] splitEnd :: Pattern ByteString -> Body ByteString -> [ByteString] -- |
-- >>> splitFront (Pattern "\n") (Body "a\nbc\nde") ---- -- ["a", "\nbc", "\nde"] splitFront :: Pattern ByteString -> Body ByteString -> [ByteString] module Text.Regex.Do.Format -- | pad String with Char to total length of Int -- --
-- >>> pad '-' 5 "abc" -- "--abc" --pad :: Char -> Int -> String -> String 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)] 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