Browse Source

fixed matching delimiters bug

master
Ben Savage 7 years ago
parent
commit
1af10ed6f6
  1. 15
      stanza

15
stanza

@ -8,6 +8,7 @@ from pprint import *
# Debug function # Debug function
# Setup vars # Setup vars
buffering=False buffering=False
buffered_lines=0
matched=False matched=False
output='' output=''
@ -46,6 +47,7 @@ with open(cmd.filename,'r') if cmd.filename else sys.stdin as handle:
# Continue buffering if we've already started # Continue buffering if we've already started
if buffering: if buffering:
buffered_lines+=1
output+=line output+=line
# If a line in the stanza matches, we output the stanza # If a line in the stanza matches, we output the stanza
@ -55,6 +57,9 @@ with open(cmd.filename,'r') if cmd.filename else sys.stdin as handle:
# Output/clear buffer when we encounter an end to the stanza # Output/clear buffer when we encounter an end to the stanza
if re.search(end,line) and buffering==True: if re.search(end,line) and buffering==True:
# if we have the same start and end delimiters, assume there has to be one line differed. Alternatively we could check whether there are at least two on the line... but I'm lazy
if start == end and buffered_lines<=1:
continue
debug('Finished buffering on '+end) debug('Finished buffering on '+end)
if matched: if matched:
# Strip newlines if requrired # Strip newlines if requrired
@ -62,10 +67,8 @@ with open(cmd.filename,'r') if cmd.filename else sys.stdin as handle:
print output.replace("\n",'') print output.replace("\n",'')
else: else:
print output print output
buffering=False buffering=False
matched=False matched=False
output='' output=''
else: buffered_lines=0
output=''
buffering=False

Loading…
Cancel
Save