-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | PCRE wrapper -- -- search, replace, format String | ByteString with PCRE regex Utf8-safe @package regex-do @version 1.3 -- | reexport common types from Text.Regex.PCRE module Regexdo.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 Regexdo.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 Regexdo.Pcre.Option.Exec instance GHC.Enum.Enum Regexdo.Pcre.Option.Comp module Regexdo.Convert -- | both Ascii and Utf8 toByteString :: String -> ByteString -- | both Ascii and Utf8 toString :: ByteString -> String module Regexdo.TypeDo type GroupReplacer a = MatchArray -> ReplaceAcc a -> ReplaceAcc a data ReplaceAcc a ReplaceAcc :: a -> Int -> ReplaceAcc a -- | wip Haystack [acc_haystack] :: ReplaceAcc a -> a [position_adj] :: ReplaceAcc a -> Int data Needle n Needle :: n -> Needle n data Haystack h Haystack :: h -> Haystack h data Replacement r Replacement :: r -> Replacement r 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 instance GHC.Classes.Eq Regexdo.TypeDo.ReplaceCase instance GHC.Base.Functor Regexdo.TypeDo.Replacement instance GHC.Base.Functor Regexdo.TypeDo.Haystack instance GHC.Base.Functor Regexdo.TypeDo.Needle module Regexdo.Pcre.Match -- | see Regexdo.Pcre.Result for funs converting MatchArray -- to something useful -- -- match returns the first occurrence - if any class Match_ctr n h => Match_cl n h where match r0 (Haystack b0) = matchOnce (r_ r0) b0 matchTest r0 (Haystack b0) = matchTest (r_ r0) b0 matchAll r0 (Haystack b0) = matchAll (r_ r0) b0 match :: Match_cl n h => Needle n -> Haystack h -> Maybe MatchArray matchTest :: Match_cl n h => Needle n -> Haystack h -> Bool matchAll :: Match_cl n h => Needle n -> Haystack h -> [MatchArray] -- | tweak Regex with options makeRegexOpts :: Match_opt n => [Comp] -> [Exec] -> Needle n -> Regex -- | this instance accepts regex String -- --
--   >>> matchTest (Needle "^ab") (Haystack "abc")
--   
-- -- True -- | accepts regex String -- | accepts regex ByteString -- | accepts regex ByteString -- | accepts Regex made with makeRegexOpts -- | accepts Regex made with makeRegexOpts -- | _ctr: constraint type Match_ctr n h = (Extract h, Needle_ n, RegexLike Regex h) type Match_opt n = RegexMaker Regex CompOption ExecOption n class Needle_ r r_ :: Needle_ r => Needle r -> Regex instance Regexdo.Pcre.Match.Match_cl GHC.Base.String GHC.Base.String instance Regexdo.Pcre.Match.Match_cl GHC.Base.String Data.ByteString.Internal.ByteString instance Regexdo.Pcre.Match.Match_cl Data.ByteString.Internal.ByteString Data.ByteString.Internal.ByteString instance Regexdo.Pcre.Match.Match_cl Data.ByteString.Internal.ByteString GHC.Base.String instance Regexdo.Pcre.Match.Match_cl Text.Regex.PCRE.Wrap.Regex GHC.Base.String instance Regexdo.Pcre.Match.Match_cl Text.Regex.PCRE.Wrap.Regex Data.ByteString.Internal.ByteString instance Regexdo.Pcre.Match.Needle_ Data.ByteString.Internal.ByteString instance Regexdo.Pcre.Match.Needle_ GHC.Base.String instance Regexdo.Pcre.Match.Needle_ Text.Regex.PCRE.Wrap.Regex module Regexdo.Pcre.Result poslen :: Functor f => f MatchArray -> f [PosLen] -- | all matches value :: (Functor f, Extract a) => Haystack a -> f MatchArray -> f [a] -- | extracts all values in a MatchArray (matched group) oneMatchArray :: Extract a => Haystack 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 Regexdo.Pcre.Replace data ReplaceCase -- | may be omitted Once :: ReplaceCase -- | if both Once and All are passed, All prevails All :: ReplaceCase Utf8 :: ReplaceCase Multiline :: ReplaceCase -- |

dynamic group replace

-- -- custom replacer fn returns replacement value -- --
--   >>> 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] (Needle "\\w=(\\d{1,3})", replacer) $ Haystack "a=101 b=3 12"
--   
-- -- "a=[сто один] b=3 12" -- --
--   >>> replaceGroup [All,Utf8] (Needle "\\w=(\\d{1,3})", replacer) $ Haystack "a=101 b=3 12"
--   
-- -- "a=[сто один] b=[three] 12" -- --

static replace for simple (no group) needle

-- --
--   >>> replace [Once,Utf8] (Needle "менее", Replacement  "более") $ Haystack "менее менее"
--   
-- -- "более менее" -- --
--   >>> replace [Once,Utf8] (Needle "^a\\s", Replacement "A") $ Haystack "a bc хол.гор."
--   
-- -- "Abc хол.гор." class Replace_cl a where replace cases0 (pat1, repl1) hay0 = if isUtf8 cases0 then utfFn2 else fn2 (pat2 pat1, repl1) 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' <$> pat1, toByteString' <$> repl1) $ toByteString' <$> hay0 in toA res1 pat2 pat1 = addOpt pat1 cOpt1 cOpt1 = comp cases0 replaceGroup cases (pat1, repl1) = fn1 (pat2, repl1) where pat2 = addOpt pat1 cOpt cOpt = comp cases fn1 = if elem All cases then rallGroup else ronceGroup replace :: (Replace_cl a, Mr a) => [ReplaceCase] -> (Needle a, Replacement a) -> Haystack a -> a replaceGroup :: (Replace_cl a, Mr a) => [ReplaceCase] -> (Needle a, GroupReplacer a) -> Haystack a -> a -- | call from your custom GroupReplacer passed to -- replaceGroup -- -- see example replacer above replaceMatch :: Replace_cl' 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_cl' 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_cl Regex a, Replace_cl' a, Match_opt a) instance Regexdo.Pcre.Replace.Replace_cl GHC.Base.String instance Regexdo.Pcre.Replace.Replace_cl' GHC.Base.String instance Regexdo.Pcre.Replace.Replace_cl Data.ByteString.Internal.ByteString instance Regexdo.Pcre.Replace.Replace_cl' Data.ByteString.Internal.ByteString -- | wraps functions from stringsearch package -- -- this module uses newtypes for args plus function names are tweaked -- -- regex is treated as ordinary String module Regexdo.Search -- | (front, end) : drop needle -- --
--   >>> break (Needle ":") (Haystack "0123:oid:90")
--   
-- -- ("0123", "oid:90") -- --
--   >>> break (Needle "\n") (Haystack "a\nbc\nde")
--   
-- -- ("a", "bc\nde") break :: Needle ByteString -> Haystack ByteString -> (ByteString, ByteString) -- | (front, needle + end) -- --
--   >>> breakFront (Needle "\n") (Haystack "a\nbc\nde")
--   
-- -- ("a", "\nbc\nde") breakFront :: Needle ByteString -> Haystack ByteString -> (ByteString, ByteString) -- | (front + needle, end) -- --
--   >>> breakEnd (Needle "\n") (Haystack "a\nbc\nde")
--   
-- -- ("a\n", "bc\nde") breakEnd :: Needle ByteString -> Haystack ByteString -> (ByteString, ByteString) -- |
--   >>> replace (Needle "\n") (Replacement ",") (Haystack "a\nbc\nde")
--   
-- -- "a,bc,de" replace :: Needle ByteString -> Replacement ByteString -> Haystack ByteString -> ByteString -- |
--   >>> split (Needle "\n") (Haystack "a\nbc\nde")
--   
-- -- ["a", "bc", "de"] -- --
--   >>> split (Needle " ") (Haystack "a bc de")
--   
-- -- ["a", "bc", "de"] -- --
--   >>> split (Needle "\\s") (Haystack "abc de fghi ")
--   
-- -- ["abc de fghi "] split :: Needle ByteString -> Haystack ByteString -> [ByteString] -- |
--   >>> splitEnd (Needle "\n") (Haystack "a\nbc\nde")
--   
-- -- ["a\n", "bc\n", "de"] splitEnd :: Needle ByteString -> Haystack ByteString -> [ByteString] -- |
--   >>> splitFront (Needle "\n") (Haystack "a\nbc\nde")
--   
-- -- ["a", "\nbc", "\nde"] splitFront :: Needle ByteString -> Haystack ByteString -> [ByteString] module Regexdo.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 Regexdo.Format.Format [GHC.Base.String] instance Regexdo.Format.Format [(GHC.Base.String, GHC.Base.String)] module Regexdo.Trim -- | removes leading and trailing spaces and tabs class Trim a trim :: Trim a => a -> a instance Regexdo.Trim.Trim Data.ByteString.Internal.ByteString instance Regexdo.Trim.Trim GHC.Base.String