# HG changeset patch
# User Andrey Skvortsov <andrej.skvortzov@gmail.com>
# Date 1497021132 -10800
# Node ID a63bb402585289fd17192a866e09ae773e8b51e4
# Parent  acb767d6ac859399beb479329dbd1d13c37bf6eb
avoid infinite loop in search

for example following regexp '()' creates infinite list of result

diff -r acb767d6ac85 -r a63bb4025852 plcopen/plcopen.py
--- a/plcopen/plcopen.py	Thu Jun 08 17:30:23 2017 +0300
+++ b/plcopen/plcopen.py	Fri Jun 09 18:12:12 2017 +0300
@@ -125,10 +125,13 @@
     test_result = []
     result = criteria["pattern"].search(text)
     while result is not None:
+        prev_pos=result.endpos        
         start = TextLenInRowColumn(text[:result.start()])
         end = TextLenInRowColumn(text[:result.end() - 1])
         test_result.append((start, end, "\n".join(lines[start[0]:end[0] + 1])))
         result = criteria["pattern"].search(text, result.end())
+        if result is not None and prev_pos==result.endpos:
+            break
     return test_result
 
 def TextMatched(str1, str2):