[Pkg-haskell-commits] r1266 - in /packages/haskell-regex-compat/trunk: Text/Regex.hs debian/changelog regex-compat.cabal

arjan at users.alioth.debian.org arjan at users.alioth.debian.org
Mon Oct 13 05:40:14 UTC 2008


Author: arjan
Date: Mon Oct 13 05:40:14 2008
New Revision: 1266

URL: http://svn.debian.org/wsvn/pkg-haskell/?sc=1&rev=1266
Log:
New upstream release

Modified:
    packages/haskell-regex-compat/trunk/Text/Regex.hs
    packages/haskell-regex-compat/trunk/debian/changelog
    packages/haskell-regex-compat/trunk/regex-compat.cabal

Modified: packages/haskell-regex-compat/trunk/Text/Regex.hs
URL: http://svn.debian.org/wsvn/pkg-haskell/packages/haskell-regex-compat/trunk/Text/Regex.hs?rev=1266&op=diff
==============================================================================
--- packages/haskell-regex-compat/trunk/Text/Regex.hs (original)
+++ packages/haskell-regex-compat/trunk/Text/Regex.hs Mon Oct 13 05:40:14 2008
@@ -29,8 +29,9 @@
     splitRegex
   ) where
 
+import Data.Array((!))
 import Data.Bits((.|.))
-import Text.Regex.Base(RegexMaker(makeRegexOpts),defaultExecOpt,RegexLike(matchOnceText),RegexContext(matchM))
+import Text.Regex.Base(RegexMaker(makeRegexOpts),defaultExecOpt,RegexLike(matchAll,matchAllText),RegexContext(matchM),MatchText)
 import Text.Regex.Posix(Regex,compNewline,compIgnoreCase,compExtended)
 
 -- | Makes a regular expression with the default options (multi-line,
@@ -91,6 +92,70 @@
 misfeature is here to match the behavior of the the original
 Text.Regex API.
 -}
+
+subRegex :: Regex                          -- ^ Search pattern
+         -> String                         -- ^ Input string
+         -> String                         -- ^ Replacement text
+         -> String                         -- ^ Output string
+subRegex _ "" _ = ""
+subRegex regexp inp repl =
+  let compile _i str [] = \ _m ->  (str++)
+      compile i str (("\\",(off,len)):rest) =
+        let i' = off+len
+            pre = take (off-i) str
+            str' = drop (i'-i) str
+        in if null str' then \ _m -> (pre ++) . ('\\':)
+             else \  m -> (pre ++) . ('\\' :) . compile i' str' rest m
+      compile i str ((xstr,(off,len)):rest) =
+        let i' = off+len
+            pre = take (off-i) str
+            str' = drop (i'-i) str
+            x = read xstr
+        in if null str' then \ m -> (pre++) . ((fst (m!x))++)
+             else \ m -> (pre++) . ((fst (m!x))++) . compile i' str' rest m
+      compiled :: MatchText String -> String -> String
+      compiled = compile 0 repl findrefs where
+        -- bre matches a backslash then capture either a backslash or some digits
+        bre = mkRegex "\\\\(\\\\|[0-9]+)"
+        findrefs = map (\m -> (fst (m!1),snd (m!0))) (matchAllText bre repl)
+      go _i str [] = str
+      go i str (m:ms) =
+        let (_,(off,len)) = m!0
+            i' = off+len
+            pre = take (off-i) str
+            str' = drop (i'-i) str
+        in if null str' then pre ++ (compiled m "")
+             else pre ++ (compiled m (go i' str' ms))
+  in go 0 inp (matchAllText regexp inp)
+
+{- | Splits a string based on a regular expression.  The regular expression
+should identify one delimiter.
+
+This does not advance and produces an infinite list of [] if the regex
+matches an empty string.  This misfeature is here to match the
+behavior of the the original Text.Regex API.
+-}
+
+splitRegex :: Regex -> String -> [String]
+splitRegex _ [] = []
+splitRegex delim strIn = 
+  let matches = map (!0) (matchAll delim strIn)
+      go _i str [] = str : []
+      go i str ((off,len):rest) =
+        let i' = off+len
+            firstline = take (off-i) str
+            remainder = drop (i'-i) str
+        in seq i' $
+           if null remainder then [firstline,""]
+             else firstline : go i' remainder rest
+  in go 0 strIn matches
+
+{-
+
+-- These are the older versions which failed on (correct answer:)
+-- let r = mkRegex "^(.)" in subRegex2 r "abc\ndef" "|\\1"
+-- "|abc\n|def"
+
 subRegex :: Regex                          -- ^ Search pattern
       -> String                         -- ^ Input string
       -> String                         -- ^ Replacement text
@@ -119,14 +184,6 @@
        Just (lead, match, trail, groups) ->
          lead ++ lookup match repl groups ++ (subRegex regexp trail repl)
 
-{- | Splits a string based on a regular expression.  The regular expression
-should identify one delimiter.
-
-This does not advance and produces an infinite list of [] if the regex
-matches an empty string.  This misfeature is here to match the
-behavior of the the original Text.Regex API.
--}
-
 splitRegex :: Regex -> String -> [String]
 splitRegex _ [] = []
 splitRegex delim strIn = loop strIn where
@@ -136,3 +193,5 @@
                   if null remainder
                     then [firstline,""]
                     else firstline : loop remainder
+
+-}

Modified: packages/haskell-regex-compat/trunk/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-haskell/packages/haskell-regex-compat/trunk/debian/changelog?rev=1266&op=diff
==============================================================================
--- packages/haskell-regex-compat/trunk/debian/changelog (original)
+++ packages/haskell-regex-compat/trunk/debian/changelog Mon Oct 13 05:40:14 2008
@@ -1,3 +1,9 @@
+haskell-regex-compat (0.92-1~pre1) unstable; urgency=low
+
+  * New upstream release
+
+ -- Arjan Oosting <arjan at debian.org>  Mon, 13 Oct 2008 07:39:04 +0200
+
 haskell-regex-compat (0.91-1) unstable; urgency=low
 
   * Take over package from Ian, as I already maintain haskell-regex-base,

Modified: packages/haskell-regex-compat/trunk/regex-compat.cabal
URL: http://svn.debian.org/wsvn/pkg-haskell/packages/haskell-regex-compat/trunk/regex-compat.cabal?rev=1266&op=diff
==============================================================================
--- packages/haskell-regex-compat/trunk/regex-compat.cabal (original)
+++ packages/haskell-regex-compat/trunk/regex-compat.cabal Mon Oct 13 05:40:14 2008
@@ -1,6 +1,7 @@
 Name:                   regex-compat
-Version:                0.91
+Version:                0.92
 Cabal-Version:          >=1.2
+build-type:             Simple
 License:                BSD3
 License-File:           LICENSE
 Copyright:              Copyright (c) 2006, Christopher Kuklewicz
@@ -17,7 +18,7 @@
   description: Choose the new smaller, split-up base package.
 library
   if flag(splitBase)
-    Build-Depends:      base >= 3.0, regex-base >= 0.93, regex-posix >= 0.93
+    Build-Depends:      base >= 3.0, regex-base >= 0.93, regex-posix >= 0.93, array
   else
     Build-Depends:      base < 3.0,  regex-base >= 0.93, regex-posix >= 0.93
   -- Data-Files:




More information about the Pkg-haskell-commits mailing list