Add utility library for line scanning
This commit is contained in:
parent
4b962f3e57
commit
9228c72911
|
@ -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]
|
Loading…
Reference in New Issue