packages feed

pcre-utils 0.1.2 → 0.1.3

raw patch · 2 files changed

+53/−3 lines, 2 filesdep +arraydep ~regex-pcre-builtin

Dependencies added: array

Dependency ranges changed: regex-pcre-builtin

Files

Text/Regex/PCRE/ByteString/Utils.hs view
@@ -7,10 +7,24 @@ Right ["a","b","c"] -} module Text.Regex.PCRE.ByteString.Utils-    ( substitute+    ( -- * Perl-like utility functions+      substitute     , split     , substituteCompile     , splitCompile+    -- * Re-exports from "Text.Regex.PCRE.ByteString"+    , Regex+    , CompOption+    , ExecOption+    , compBlank+    , execBlank+    -- * Pure version of the functions, using 'unsafePerformIO'+    , compile'+    , execute'+    , substitute'+    , split'+    , substituteCompile'+    , splitCompile'     ) where  import Text.Regex.PCRE.ByteString@@ -20,6 +34,8 @@ import Data.Attoparsec.ByteString.Char8 as A import Control.Applicative import Data.Char (digitToInt)+import System.IO.Unsafe+import qualified Data.Array as A  {-| Substitutes values matched by a `Regex`. References can be used. @@ -60,6 +76,19 @@     where         removeEmptyLeft = reverse . dropWhile BS.null . reverse +-- | A pure version of 'substitute', using unsafePerformIO.+substitute' :: Regex             -- ^ The regular expression, taken from a call to `compile`+            -> BS.ByteString     -- ^ The source string+            -> BS.ByteString     -- ^ The replacement string+            -> Either String BS.ByteString+substitute' regexp srcstring repla = unsafePerformIO (substitute regexp srcstring repla)++-- | A pure version of 'split', using unsafePerformIO.+split' :: Regex  -- ^ The regular expression, taken from a call to `compile`+       -> BS.ByteString -- ^ The source string+       -> Either String [BS.ByteString]+split' regexp srcstring = unsafePerformIO (split regexp srcstring)+ data RegexpSplit a = Matched a                    | Unmatched a                    deriving (Show, Eq, Ord)@@ -139,3 +168,24 @@     case re of         Right cre -> split cre srcstring         Left rr   -> return $ Left $ "Regexp compilation failed: " ++ show rr++-- | A pure version of 'compile', using unsafePerformIO.+compile' :: CompOption -> ExecOption -> BS.ByteString -> Either (MatchOffset, String) Regex+compile' co eo s = unsafePerformIO (compile co eo s)++-- | A pure version of 'execute', using unsafePerformIO.+execute' :: Regex -> BS.ByteString -> Either WrapError (Maybe (A.Array Int (MatchOffset, MatchLength)))+execute' r s = unsafePerformIO (execute r s)++-- | A pure version of 'substituteCompile', using unsafePerformIO.+substituteCompile' :: BS.ByteString     -- ^ The regular expression+                   -> BS.ByteString     -- ^ The source string+                   -> BS.ByteString     -- ^ The replacement string+                   -> Either String BS.ByteString+substituteCompile' regexp srcstring repla = unsafePerformIO (substituteCompile regexp srcstring repla)++-- | A pure version of 'splitCompile', using unsafePerformIO.+splitCompile' :: BS.ByteString -- ^ The regular expression+              -> BS.ByteString -- ^ The source string+              -> Either String [BS.ByteString]+splitCompile' regexp srcstring = unsafePerformIO (splitCompile regexp srcstring)
pcre-utils.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                pcre-utils-version:             0.1.2+version:             0.1.3 synopsis:            Perl-like substitute and split for PCRE regexps. description:         This package introduces split and replace like functions using PCRE regexps. license:             BSD3@@ -25,7 +25,7 @@   ghc-options:         -Wall   ghc-prof-options:    -caf-all -auto-all   extensions:          OverloadedStrings, BangPatterns-  build-depends:       base >= 4.6 && < 4.8, regex-pcre-builtin == 0.94.4.6.8.34, bytestring, attoparsec, mtl, vector+  build-depends:       base >= 4.6 && < 4.8, regex-pcre-builtin >= 0.94.4.8, bytestring, attoparsec, mtl, vector, array  Test-Suite test-split     hs-source-dirs: test