From 1af10ed6f662ca894a804a1675985d564ea8bfc0 Mon Sep 17 00:00:00 2001 From: Ben Savage Date: Wed, 5 Jun 2019 16:13:30 +1000 Subject: [PATCH] fixed matching delimiters bug --- stanza | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/stanza b/stanza index 7863f9d..fd4640f 100755 --- a/stanza +++ b/stanza @@ -8,6 +8,7 @@ from pprint import * # Debug function # Setup vars buffering=False +buffered_lines=0 matched=False 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 if buffering: + buffered_lines+=1 output+=line # 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 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) if matched: # 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",'') else: print output - buffering=False - matched=False - output='' - else: - output='' - buffering=False + buffering=False + matched=False + output='' + buffered_lines=0