regex-do 2.2 → 2.3
raw patch · 6 files changed
+80/−12 lines, 6 files
Files
- changelog.md +29/−0
- regex-do.cabal +3/−2
- src/Text/Regex/Do/Pcre/Match.hs +6/−6
- src/Text/Regex/Do/Pcre/MatchHint.hs +16/−2
- src/Text/Regex/Do/Type/MatchHint.hs +1/−2
- test/TestRegex/TestReplaceOpen.hs +25/−0
+ changelog.md view
@@ -0,0 +1,29 @@+##### 2.3 + include missing TestReplaceOpen + +##### 2.2 + MatchSame -> MatchHint ++##### 2.1 + *API changes*++ moved type files to Type dir ++ ReplaceOpen accepts both MatchArray and PosLen+ +##### 2.0 + ReplaceOpen : add Text instance+ +##### 1.9 + add ReplaceOpen. ReplaceOpen can replace in various data types in addition to String, ByteString. ++ ReplaceOpen itself does not regex. It only processes results as MatchArray. ++ Replace calls regex, then passes results to ReplaceOpen which replaces+ +##### 1.8 + replace, replaceGroup -> replace++##### 1.7 + add MatchSame+
regex-do.cabal view
@@ -1,5 +1,5 @@ name: regex-do-version: 2.2+version: 2.3 synopsis: PCRE wrapper description: format, search, replace (String | ByteString) with PCRE regex. Utf8-safe author: Imants Cekusins@@ -7,6 +7,7 @@ category: Regex, Search, String license: PublicDomain license-file: PublicDomain+extra-source-files: changelog.md cabal-version: >=1.10 build-type: Simple homepage: https://github.com/ciez/regex-do@@ -35,7 +36,6 @@ other-modules: Text.Regex.Do.Pcre.Matchf Text.Regex.Do.Pcre.Result- ghc-options: -fwarn-unused-imports build-depends: base <= 5.0,@@ -83,6 +83,7 @@ TestRegex.TestReplace TestRegex.TestSplit TestRegex.TestTrim+ TestRegex.TestReplaceOpen build-depends: base <= 5.0, hspec,
src/Text/Regex/Do/Pcre/Match.hs view
@@ -1,4 +1,4 @@--- | see "Text.Regex.Base.RegexLike"+-- | see "Text.Regex.Base.RegexLike" and "Text.Regex.Do.Pcre.MatchHint" module Text.Regex.Do.Pcre.Match (Match(..), R.extract, -- | 'extract' is reexport from "Text.Regex.Base.RegexLike"@@ -20,7 +20,7 @@ '=~' is borrowed from "Text.Regex.PCRE.Wrap", is a short version of 'match' - See also "Text.Regex.Do.Pcre.MatchSame" -}+ See also "Text.Regex.Do.Pcre.MatchHint" -} class Match a b out where match::Pattern a -> Body b -> out@@ -37,7 +37,7 @@ \["all"\] - "Text.Regex.Do.Pcre.MatchSame" -}+ "Text.Regex.Do.Pcre.MatchHint" -} instance Rx_ a b => Match a b Bool where match p0 (Body b0) = R.matchTest (r_ p0) b0 {- ^ test@@ -46,7 +46,7 @@ True - "Text.Regex.Do.Pcre.MatchSame" -}+ "Text.Regex.Do.Pcre.MatchHint" -} -- | match all instance Rx_ a b => Match a b [[b]] where@@ -55,7 +55,7 @@ \[["well"\],\["well"\]] - "Text.Regex.Do.Pcre.MatchSame" -}+ "Text.Regex.Do.Pcre.MatchHint" -} -- | match once instance Rx_ a b => Match a b [PosLen] where@@ -66,7 +66,7 @@ /Utf8/ - "Text.Regex.Do.Pcre.MatchSame" -}+ "Text.Regex.Do.Pcre.MatchHint" -} -- | match all instance Rx_ a b => Match a b [[PosLen]] where
src/Text/Regex/Do/Pcre/MatchHint.hs view
@@ -1,5 +1,15 @@ {- | this module uses <https://cdepillabout.github.io/haskell-type-families-presentation/#/ TypeFamilies>++ this module is similar to "Text.Regex.Do.Pcre.Match". The differences are:++ "Text.Regex.Do.Pcre.Match" is more flexible:+ accepts 'Pattern' Regex,+ accepts 'Pattern' and 'Body' of different types++ "Text.Regex.Do.Pcre.Match" needs to infer result type++ in this module the result type is determined by the hint -} {-# LANGUAGE TypeFamilies #-}@@ -18,6 +28,10 @@ handy when working with 'OverloadedStrings', in other cases when compiler needs a hint + >>> Test ("в"::ByteString) =~ "тихо в лесу"++ True+ >>> Once ("^all"::String) =~ "all the time" \["all"\]@@ -31,9 +45,9 @@ match::hint (Pattern a) -> Body a -> F hint a match h0 = M.match $ unhint h0 - (=~)::hint a -- ^ pattern+ (=~)::hint a -- ^ hint & pattern -> a -- ^ body- -> F hint a -- ^ \- in ('-~') is the minus sign+ -> F hint a -- ^ type defined by the instance, determined by the hint (=~) h0 = (M.=~) $ unhint h0
src/Text/Regex/Do/Type/MatchHint.hs view
@@ -1,7 +1,6 @@ module Text.Regex.Do.Type.MatchHint where --newtype Test a = Test a+newtype Test a = Test a -- ^ test: does body match pattern? newtype Once a = Once a -- ^ values newtype All a = All a -- ^ values newtype PosLen' a = PosLen' a -- ^ once
+ test/TestRegex/TestReplaceOpen.hs view
@@ -0,0 +1,25 @@+{-# LANGUAGE OverloadedStrings #-}+module TestRegex.TestReplaceOpen where++import Test.Hspec+import Text.Regex.Do.Pcre.ReplaceOpen as O+import Text.Regex.Do.Type.Do+import Data.Text+import Text.Regex.Do.Convert()+import Debug.Trace+++main::IO()+main = hspec $ do+ describe "TestRegex.TestReplaceOpen" $ do+ it "case 1" $+ O.replace (Just [(4,3)::PosLen]) (Replacement "4567") (Body "abc 123 def"::Body Text) `shouldBe` ("abc 4567 def"::Text)+ it "case 2" $+ O.replace (Just ([(4,3),(8,2)]::[PosLen])) replacer (Body "abc 123 def"::Body Text) `shouldBe` ("abc [1-2-3] def"::Text)+++replacer::GroupReplacer Text+replacer = defaultReplacer 1 tweak1+ where tweak1 str1 = case str1 of+ "123" -> "[1-2-3]"+ otherwise -> traceShow str1 "?"