[pypy-svn] r75911 - in pypy/branch/rsre2/pypy/rlib/rsre: . test

arigo at codespeak.net arigo at codespeak.net
Tue Jul 6 16:10:16 CEST 2010


Author: arigo
Date: Tue Jul  6 16:10:15 2010
New Revision: 75911

Added:
   pypy/branch/rsre2/pypy/rlib/rsre/test/test_more.py
      - copied unchanged from r75886, pypy/branch/rsre2/pypy/rlib/rsre/test/test_search.py
Removed:
   pypy/branch/rsre2/pypy/rlib/rsre/test/test_search.py
Modified:
   pypy/branch/rsre2/pypy/rlib/rsre/rsre.py
Log:
Search, non-fast version.


Modified: pypy/branch/rsre2/pypy/rlib/rsre/rsre.py
==============================================================================
--- pypy/branch/rsre2/pypy/rlib/rsre/rsre.py	(original)
+++ pypy/branch/rsre2/pypy/rlib/rsre/rsre.py	Tue Jul  6 16:10:15 2010
@@ -331,15 +331,6 @@
 
 # ____________________________________________________________
 
-def match(pattern, string, start=0, flags=0):
-    ctx = MatchContext(pattern, string, start, flags)
-    result = sre_match(ctx, 0, start, None)
-    if result is not None:
-        ctx.match_end = result.end
-        ctx.match_marks = result.marks
-        return ctx
-    return None
-
 def sre_match(ctx, ppos, ptr, marks):
     """Returns either None or a MatchResult object.  Usually we only need
     the first result, but there is the case of REPEAT...UNTIL where we
@@ -706,3 +697,26 @@
         return ctx.at_non_boundary(ptr, rsre_char.is_uni_word)
 
     return False
+
+# ____________________________________________________________
+
+def match(pattern, string, start=0, flags=0):
+    ctx = MatchContext(pattern, string, start, flags)
+    result = sre_match(ctx, 0, start, None)
+    if result is not None:
+        ctx.match_end = result.end
+        ctx.match_marks = result.marks
+        return ctx
+    return None
+
+def search(pattern, string, start=0, flags=0):
+    ctx = MatchContext(pattern, string, start, flags)
+    while start <= ctx.end:
+        result = sre_match(ctx, 0, start, None)
+        if result is not None:
+            ctx.match_start = start
+            ctx.match_end = result.end
+            ctx.match_marks = result.marks
+            return ctx
+        start += 1
+    return None



More information about the Pypy-commit mailing list