pcre-utils 0.1.0.0 → 0.1.0.1
raw patch · 3 files changed
+11/−8 lines, 3 files
Files
- Text/Regex/PCRE/ByteString/Utils.hs +9/−7
- pcre-utils.cabal +1/−1
- test/subs.hs +1/−0
Text/Regex/PCRE/ByteString/Utils.hs view
@@ -9,7 +9,7 @@ import qualified Data.ByteString.Char8 as BS import Control.Monad.Error import qualified Data.Vector as V-import Data.Attoparsec.ByteString.Char8+import Data.Attoparsec.ByteString.Char8 as A import Control.Applicative {-| Substitutes values matched by a `Regex`. References can be used.@@ -21,10 +21,9 @@ -> BS.ByteString -- ^ The replacement string -> IO (Either String BS.ByteString) substitute regexp srcstring repla = runErrorT $ do- let check x = case x of- Right y -> return y- Left rr -> throwError rr- parsedReplacement <- check (parseOnly repparser repla)+ parsedReplacement <- case parseOnly repparser repla of+ Right y -> return y+ Left rr -> throwError (rr ++ " when parsing the replacement string") (matches, captures) <- getMatches regexp srcstring V.empty let !replaceString = applyCaptures parsedReplacement captures applyReplacement :: RegexpSplit BS.ByteString -> BS.ByteString@@ -104,8 +103,11 @@ escapedThing :: Parser Replacement escapedThing = do void (char '\\')- fmap IndexedReplacement decimal <|> fmap (RawReplacement . BS.cons '\\') rawData-+ let ac = do+ n <- anyChar+ r <- rawData+ return $ BS.cons n r+ fmap IndexedReplacement decimal <|> fmap (RawReplacement . BS.cons '\\') ac -- | Compiles the regular expression (using default options) and `substitute`s substituteCompile :: BS.ByteString -- ^ The regular expression
pcre-utils.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: pcre-utils-version: 0.1.0.0+version: 0.1.0.1 synopsis: Perl-like substitute and split for PCRE regexps. description: This package introduces split and replace like functions using PCRE regexps. license: BSD3
test/subs.hs view
@@ -8,6 +8,7 @@ tests :: [(BS.ByteString, BS.ByteString, BS.ByteString, BS.ByteString)] tests = [ ("l", "x", "lap\\nin", "xap\\nin") , ("log(\\d+)truc", "x\\1x", "log186truc", "x186x")+ , ("'", "'\\''", "# This file is managed by Puppet. DO NOT EDIT.", "# This file is managed by Puppet. DO NOT EDIT.") ] toTest :: (BS.ByteString, BS.ByteString, BS.ByteString, BS.ByteString) -> IO Test