- 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
This commit is contained in:
Fredrik Lundh 2000-06-29 16:57:40 +00:00
parent 69218178ec
commit be2211e940
4 changed files with 116 additions and 130 deletions

View file

@ -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:])