packages feed

regex-applicative 0.3.2.1 → 0.3.3

raw patch · 5 files changed

+31/−1 lines, 5 files

Files

CHANGES.md view
@@ -1,6 +1,11 @@ Changes ======= +0.3.3+-----++Add `replace`+ 0.3.2.1 ------- 
Text/Regex/Applicative.hs view
@@ -25,6 +25,7 @@     , withMatched     , match     , (=~)+    , replace     , findFirstPrefix     , findLongestPrefix     , findShortestPrefix
Text/Regex/Applicative/Interface.hs view
@@ -328,3 +328,13 @@ -- the prefix and suffix of the string surrounding the match. findShortestInfix :: RE s a -> [s] -> Maybe ([s], a, [s]) findShortestInfix = findExtremalInfix $ flip preferOver++-- | Replace matches of the regular expression with its value.+--+-- >Text.Regex.Applicative > replace ("!" <$ sym 'f' <* some (sym 'o')) "quuxfoofooooofoobarfobar"+-- >"quux!!!bar!bar"+replace :: RE s [s] -> [s] -> [s]+replace r = ($ []) . go+  where go ys = case findLongestInfix r ys of+                    Nothing                -> (ys ++)+                    Just (before, m, rest) -> (before ++) . (m ++) . go rest
regex-applicative.cabal view
@@ -1,5 +1,5 @@ Name:                regex-applicative-Version:             0.3.2.1+Version:             0.3.3 Synopsis:            Regex-based parsing with applicative interface Description:              regex-applicative is a Haskell library for parsing using regular expressions.
tests/test.hs view
@@ -174,6 +174,20 @@                 (findShortestInfix "bc" "tabc")                 (Just ("ta", "bc",""))             ]+        , testGroup "replace"+            [ u "t1"+                (replace ("x" <$ "a" <|> "y" <$ "ab") "tabc")+                "tyc"+            , u "t2"+                (replace ("y" <$ "ab" <|> "x" <$ "a") "tabc")+                "tyc"+            , u "t3"+                (replace ("x" <$ "bc") "tabc")+                "tax"+            , u "t4"+                (replace ("y" <$ "a" <|> "x" <$ "ab") "tacabc")+                "tycxc"+            ]         ]     , stateQueueTests     ]