summaryrefslogtreecommitdiffstats
path: root/Lib/sre.py
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2000-06-29 16:57:40 (GMT)
committerFredrik Lundh <fredrik@pythonware.com>2000-06-29 16:57:40 (GMT)
commitbe2211e9401a0be96915c473ef99041beb5a4992 (patch)
treeb69453753d4617d7ac4b6b59fcc5a13cc55cd392 /Lib/sre.py
parent69218178ec7f1ed64c1da76e1d5a0ae4a9a2e16b (diff)
downloadcpython-be2211e9401a0be96915c473ef99041beb5a4992.zip
cpython-be2211e9401a0be96915c473ef99041beb5a4992.tar.gz
cpython-be2211e9401a0be96915c473ef99041beb5a4992.tar.bz2
- fixed split
(test_sre still complains about split, but that's caused by the group reset bug, not split itself) - added more mark slots (should be dynamically allocated, but 100 is better than 32. and checking for the upper limit is better than overwriting the memory ;-) - internal: renamed the cursor helper class - internal: removed some bloat from sre_compile
Diffstat (limited to 'Lib/sre.py')
-rw-r--r--Lib/sre.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/Lib/sre.py b/Lib/sre.py
index 32b3e8f..e0a51e3 100644
--- a/Lib/sre.py
+++ b/Lib/sre.py
@@ -26,7 +26,7 @@ T = TEMPLATE = sre_compile.SRE_FLAG_TEMPLATE
U = UNICODE = sre_compile.SRE_FLAG_UNICODE
# sre exception
-error = sre_parse.error
+error = sre_compile.error
# --------------------------------------------------------------------
# public interface
@@ -105,7 +105,7 @@ def _subn(pattern, template, string, count=0):
n = i = 0
s = []
append = s.append
- c = pattern.cursor(string)
+ c = pattern.scanner(string)
while not count or n < count:
m = c.search()
if not m:
@@ -127,16 +127,20 @@ def _split(pattern, string, maxsplit=0):
n = i = 0
s = []
append = s.append
- c = pattern.cursor(string)
+ extend = s.extend
+ c = pattern.scanner(string)
+ g = c.groups
while not maxsplit or n < maxsplit:
m = c.search()
if not m:
break
- j = m.start()
- append(string[i:j])
- i = m.end()
- if i <= j:
- break
+ b, e = m.span()
+ if e == i:
+ continue
+ append(string[i:b])
+ if g and b != e:
+ extend(m.groups())
+ i = e
n = n + 1
if i < len(string):
append(string[i:])