re-pcre: findall(): Rework for compliant implementation.

pull/26/head
Paul Sokolovsky 2015-05-29 02:04:27 +03:00
rodzic b3cfd73659
commit 3ec82997d5
2 zmienionych plików z 12 dodań i 2 usunięć

Wyświetl plik

@ -124,8 +124,9 @@ class PCREPattern:
def findall(self, s):
res = []
start = 0
while True:
m = self.search(s)
m = self.search(s, start)
if not m:
return res
if m.num == 1:
@ -135,7 +136,7 @@ class PCREPattern:
else:
res.append(m.groups())
beg, end = m.span(0)
s = s[end:]
start = end
def compile(pattern, flags=0):

Wyświetl plik

@ -42,3 +42,12 @@ assert re.findall(r"(\w+)(ly)", text) == [('careful', 'ly'), ('quick', 'ly')]
text = "He was carefully disguised but captured quickly by police."
assert re.findall(r"(\w+)ly", text) == ['careful', 'quick']
_leading_whitespace_re = re.compile('(^[ \t]*)(?:[^ \t\n])', re.MULTILINE)
text = "\tfoo\n\tbar"
indents = _leading_whitespace_re.findall(text)
assert indents == ['\t', '\t']
text = " \thello there\n \t how are you?"
indents = _leading_whitespace_re.findall(text)
assert indents == [' \t', ' \t ']