Safe Haskell | None |
---|---|
Language | Haskell2010 |
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 a bug or a PR on git to request a new ReplaceOpen
instance
- class ReplaceOpen f r where
- replace :: Extract' a => f MatchArray -> r a -> Body a -> a
- toArray :: [PosLen] -> MatchArray
- class Extract a => Extract' a where
- defaultReplacer :: Extract' a => Int -> (a -> a) -> GroupReplacer a
- getGroup :: Extract a => ReplaceAcc a -> MatchArray -> Int -> Maybe a
- replaceMatch :: Extract' a => PosLen -> (a, ReplaceAcc a) -> ReplaceAcc a
Documentation
class ReplaceOpen f r where Source
replace :: Extract' a => f MatchArray -> r a -> Body a -> a Source
toArray :: [PosLen] -> MatchArray Source
class Extract a => Extract' a where Source
see String, ByteString instances for implementation examples
see Text.Regex.Base.RegexLike for Extract
detail
:: Extract' a | |
=> Int | group idx |
-> (a -> a) | (group match -> replacement) tweak |
-> GroupReplacer 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.
getGroup :: Extract a => ReplaceAcc a -> MatchArray -> Int -> Maybe a Source
get group content safely
see defaultReplacer
source for use example
:: Extract' a | |
=> PosLen | replaceable, unadjusted |
-> (a, ReplaceAcc a) | (new val, acc passed to |
-> ReplaceAcc a | new acc |
call from your custom GroupReplacer
passed to replaceGroup
see defaultReplacer
source for use example