diff --git a/util.py b/util.py new file mode 100644 index 0000000..9d8f679 --- /dev/null +++ b/util.py @@ -0,0 +1,26 @@ +def raiseerror(cls,*args): + raise cls(*args) + +import re + +def matchinglines(lines,regex): + ret = [] + for i in range(len(lines)): + match = re.match(regex,lines[i]) + if match is not None: + ret.append(i) + return ret + +def walkback(lines,start,regex): + possible_lines = matchinglines(lines,regex) + possible_lines = [x for x in possible_lines if x<=start] + possible_lines.sort() + if len(possible_lines)>=1: + return possible_lines[-1] + +def walkup(lines,start,regex): + possible_lines = matchinglines(lines,regex) + possible_lines = [x for x in possible_lines if x>=start] + possible_lines.sort() + if len(possible_lines)>=1: + return possible_lines[0]