regex-do 1.9 → 2.0
raw patch · 3 files changed
+23/−3 lines, 3 files
Files
- regex-do.cabal +1/−1
- src/Text/Regex/Do/Pcre/ReplaceOpen.hs +20/−2
- test/Main.hs +2/−0
regex-do.cabal view
@@ -1,5 +1,5 @@ name: regex-do-version: 1.9+version: 2.0 synopsis: PCRE wrapper description: format, search, replace (String | ByteString) with PCRE regex. Utf8-safe author: Imants Cekusins
src/Text/Regex/Do/Pcre/ReplaceOpen.hs view
@@ -3,7 +3,15 @@ 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 <https://github.com/ciez/regex-do git> to request a new 'ReplaceOpen' instance -}+ open a bug or a PR on <https://github.com/ciez/regex-do git> to request a new 'Extract'' instance++ "Data.Text" instance already works++ >>> replace (Just $ toArray [(4,3)]) (Replacement "4567") (Body "abc 123 def"::Body Text)++ "abc 4567 def"++ 'GroupReplacer' can be used too -} module Text.Regex.Do.Pcre.ReplaceOpen (ReplaceOpen(..), toArray,@@ -20,6 +28,7 @@ import Data.ByteString as B import Text.Regex.Do.TypeDo import Text.Regex.Do.Pcre.Result as R+import Data.Text as T toArray::[PosLen] -> MatchArray@@ -98,7 +107,17 @@ len' = B.length +instance Extract Text where+ before = T.take+ after = T.drop+ empty = T.empty ++instance Extract' Text where+ concat' = T.concat+ len' = T.length++ -- dynamic {- | Replaces specified (by idx) group match with tweaked value. Works for one common simple use case@@ -106,7 +125,6 @@ 'GroupReplacer' can be used with complicated regex another custom dynamic replacer could e.g.- inspect all group matches before looking up a replacement. -} defaultReplacer::Extract' a => Int -- ^ group idx
test/Main.hs view
@@ -3,6 +3,7 @@ import qualified TestRegex.TestFormat as F import qualified TestRegex.TestPcre as P import qualified TestRegex.TestReplace as R+import qualified TestRegex.TestReplaceOpen as O import qualified TestRegex.TestSplit as S import qualified TestRegex.TestTrim as T @@ -15,3 +16,4 @@ R.main S.main T.main+ O.main