-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | PCRE regex funs -- -- Convenience functions to search, replace, format String | ByteString -- with PCRE regex @package regex-do @version 1.0 -- | 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 acc = MatchArray -> acc -> acc 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) 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 occurence - 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 -- | this instance accepts regex String -- | this instance accepts regex ByteString -- | this instance accepts regex ByteString -- | this instance accepts Regex made with makeRegexOpts -- | this instance accepts Regex made with makeRegexOpts class Needle_ r r_ :: Needle_ r => Needle r -> Regex -- | _ctr: constraint type Match_ctr n h = (Extract h, Needle_ n, RegexLike Regex h) type Match_opt n = RegexMaker Regex CompOption ExecOption n 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 -- | from stringsearch package -- -- this module uses newtypes for args plus function names are tweaked -- -- regex is treated as ordinary String. Do not use regex. module Regexdo.Search -- | lose 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.Pcre.Replace data ReplaceCase Once :: ReplaceCase All :: ReplaceCase Utf8 :: ReplaceCase Multiline :: ReplaceCase class Replace_cl a replace :: Replace_cl a => [ReplaceCase] -> (Needle a, Replacement a) -> Haystack a -> a -- |

dynamic group replace

-- -- custom replacer fn returns replacement value -- --
--   >>> replacer::GroupReplacer String
--       replacer marr1 acc1 = case val1 of
--                              "101" -> fn1 "[A]"
--                              "3" -> fn1 "[Be]"
--       where ol1 = marr1 ! 3 :: (MatchOffset, MatchLength)
--             val1 = extract ol1 acc1
--             fn1 str1 = replaceMatch ol1 (str1,acc1)
--   
-- -- see extract -- -- below test compares Once vs All options -- --
--   >>> groupReplace::IO()
--       groupReplace =  hspec $ do
--           describe "Pcre.Replace group" $ do
--               it "Once" $ do
--                  runFn1 [Once] `shouldBe` "a=[A] b=3 12"
--               it "All" $ do
--                  runFn1 [All] `shouldBe` "a=[A] b=[Be] 12"
--               where runFn1 opts1 =
--                        let   rx1 = Needle "(\\w)(=)(\\d{1,3})"
--                              body1 = Haystack "a=101 b=3 12"
--                        in replaceGroup opts1 (rx1,replacer) body1
--   
replaceGroup :: Mm a => [ReplaceCase] -> (Needle a, GroupReplacer a) -> Haystack a -> a -- | use in your custom GroupReplacer passed to replaceGroup -- -- see example replacer above replaceMatch :: Replace_cl' a => (MatchOffset, MatchLength) -> (a, a) -> a instance GHC.Classes.Eq Regexdo.Pcre.Replace.ReplaceCase 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 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