Structure conversion now improved so that it matches correctly

pull/1/head
Ozbolt Menegatti 4 years ago
parent c4938b5785
commit b485fb173f

@ -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("<struktura>", "").replace("</struktura>", "").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

Loading…
Cancel
Save