From ecb4d2a89fc41e65a13bcc0c7a7aa2f57b83f35b Mon Sep 17 00:00:00 2001 From: Alessandro Marzialetti Date: Mon, 10 Jul 2017 12:45:36 +0200 Subject: [PATCH] Fixed a bug with the template substitution adding temporary string placeholders to avoid unexpected substitutions (e.g.) with i = 110: line = re.sub(r'20', re.escape(str(i+10)), line.rstrip()) 20 -> 110 line = re.sub(r'11', re.escape(str(i + 1)), line.rstrip()) 110 -> 1010 line = re.sub(r'10(?![0-9])', re.escape(str(i)), line.rstrip()) 1100 -> 10100 --- preprocessed/boost_mpl_preprocess.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/preprocessed/boost_mpl_preprocess.py b/preprocessed/boost_mpl_preprocess.py index 72a18ab..b497391 100755 --- a/preprocessed/boost_mpl_preprocess.py +++ b/preprocessed/boost_mpl_preprocess.py @@ -30,9 +30,12 @@ def create_more_container_files(sourceDir, suffix, maxElements, containers, cont shutil.copyfile( os.path.join( sourceDir, container, container + "20" + suffix ), newFile ) # Adjust copy of "template"-file accordingly. for line in fileinput.input( newFile, inplace=1, mode="rU" ): - line = re.sub(r'20', re.escape(str(i+10)), line.rstrip()) - line = re.sub(r'11', re.escape(str(i + 1)), line.rstrip()) - line = re.sub(r'10(?![0-9])', re.escape(str(i)), line.rstrip()) + line = re.sub(r'20', '%TWENTY%', line.rstrip()) + line = re.sub(r'11', '%ELEVEN%', line.rstrip()) + line = re.sub(r'10(?![0-9])', '%TEN%', line.rstrip()) + line = re.sub(r'%TWENTY%', re.escape(str(i+10)), line.rstrip()) + line = re.sub(r'%ELEVEN%', re.escape(str(i + 1)), line.rstrip()) + line = re.sub(r'%TEN%', re.escape(str(i)), line.rstrip()) print(line) for container in containers2: for i in range(20, maxElements, 10): @@ -41,9 +44,12 @@ def create_more_container_files(sourceDir, suffix, maxElements, containers, cont shutil.copyfile( os.path.join( sourceDir, container, container + "20_c" + suffix ), newFile ) # Adjust copy of "template"-file accordingly. for line in fileinput.input( newFile, inplace=1, mode="rU" ): - line = re.sub(r'20', re.escape(str(i+10)), line.rstrip()) - line = re.sub(r'11', re.escape(str(i + 1)), line.rstrip()) - line = re.sub(r'10(?![0-9])', re.escape(str(i)), line.rstrip()) + line = re.sub(r'20', '%TWENTY%', line.rstrip()) + line = re.sub(r'11', '%ELEVEN%', line.rstrip()) + line = re.sub(r'10(?![0-9])', '%TEN%', line.rstrip()) + line = re.sub(r'%TWENTY%', re.escape(str(i+10)), line.rstrip()) + line = re.sub(r'%ELEVEN%', re.escape(str(i + 1)), line.rstrip()) + line = re.sub(r'%TEN%', re.escape(str(i)), line.rstrip()) print(line)