From b485fb173f7a9b70e1e53078de06995e98263ace Mon Sep 17 00:00:00 2001 From: Ozbolt Menegatti Date: Tue, 19 May 2020 18:48:05 +0200 Subject: [PATCH] Structure conversion now improved so that it matches correctly --- src/lib/structure_conversions.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lib/structure_conversions.py b/src/lib/structure_conversions.py index 83a93cb..0e7af0d 100644 --- a/src/lib/structure_conversions.py +++ b/src/lib/structure_conversions.py @@ -22,12 +22,10 @@ def build_structure_conversions(): if line[1] == "struktura": continue - vfrom = line[0].replace("?", "\?").replace("%s", "([a-zA-Z螚ȎŠ-]+)") - vmatch = "^" + vfrom + "$" + vfrom = "^" + line[0].replace("?", "\?").replace("%s", "([a-zA-Z螚ȎŠ-]+)") + "$" vto = line[1].replace("", "").replace("", "").replace("%s", "$1").strip() - structure_conversions.append((__new__(RegExp(vmatch, 'u')), - __new__(RegExp(vfrom, 'u')), + structure_conversions.append((__new__(RegExp(vfrom, 'u')), vto)) @@ -35,10 +33,17 @@ def convert_structure(structure): if structure_conversions is None: build_structure_conversions() - for vmatch, vfrom, vto in structure_conversions: - if vmatch.test(structure): + for vfrom, vto in structure_conversions: + match = structure.match(vfrom) + if match: # we need to remove replace alias here as we want to use javascript's one __pragma__('noalias', 'replace') - return structure.replace(vfrom, vto).strip() + result = structure.replace(vfrom, vto).strip() + __pragma__('alias', 'replace', "py_replace") + + # they said this also needs to be done - remove "-d$" from %s match + if len(match) > 1 and match[1].endswith("-d"): + result = result.replace(match[1], match[1][:-2]) + return result return None