From 9c0fe70a4aad9be783538c21d90e05d034c82288 Mon Sep 17 00:00:00 2001 From: Toilal Date: Sun, 1 Nov 2015 15:07:42 +0100 Subject: [PATCH] Some fixes in Matches methods --- rebulk/match.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/rebulk/match.py b/rebulk/match.py index 9e53eee..c70391f 100644 --- a/rebulk/match.py +++ b/rebulk/match.py @@ -210,6 +210,9 @@ def chain_before(self, position, seps, start=0, predicate=None, index=None): :return: :rtype: """ + if hasattr(position, 'start'): + position = position.start + chain = _BaseMatches._base() position = min(self.max_end, position) @@ -242,6 +245,8 @@ def chain_after(self, position, seps, end=None, predicate=None, index=None): :return: :rtype: """ + if hasattr(position, 'end'): + position = position.end chain = _BaseMatches._base() if end is None: @@ -327,19 +332,16 @@ def holes(self, start=0, end=None, formatter=None, ignore=None, seps=None, predi else: end = min(self.max_end, end) ret = _BaseMatches._base() - current = [] hole = False rindex = start loop_start = self._hole_start(start, ignore) for rindex in range(loop_start, end): - for starting in self.starting(rindex): - if starting not in current and (not ignore or not ignore(starting)): - current.append(starting) - for ending in self.ending(rindex): - if ending in current: - current.remove(ending) + current = [] + for at_index in self.at_index(rindex): + if not ignore or not ignore(at_index): + current.append(at_index) if seps and hole and self.input_string and self.input_string[rindex] in seps: hole = False