Skip to content

Commit

Permalink
Optimized code
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenwong7bm committed Feb 9, 2023
1 parent a4fce5b commit 7cbb676
Showing 1 changed file with 39 additions and 38 deletions.
77 changes: 39 additions & 38 deletions inheritedglyphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,52 +93,53 @@ def convert(string: str, *, use_supp_planes='c', use_compatibility=[J, K, T], co

returned = string
for char in string:
value = char
replace = False

# initial conversion

if char in VARIANTS_TABLE:
value, attr = VARIANTS_TABLE[value]
if char not in replaced_cache:
value = char
replace = False

if _check_supp(char, value):
replace = bool(use_supp_planes)
if use_supp_planes == CORE:
replace = use_supp_planes in attr
else:
replace = True
# initial conversion

if replace and (INHERITED in attr):
replace = convert_inherited
elif char in RADICALS_VARIANTS_TABLE:
value = RADICALS_VARIANTS_TABLE[char]
replace = True

# compatibility variants/IVS conversion

for compatibility_table in compatibility_order:
if value in compatibility_table:
value_new, attr = compatibility_table[value]
if char in VARIANTS_TABLE:
value, attr = VARIANTS_TABLE[value]

if _check_supp(value, value_new):
if _check_supp(char, value):
replace = bool(use_supp_planes)
if use_supp_planes == CORE:
replace = use_supp_planes in attr
else:
replace = True

if replace:
value = value_new
break
else:
for ivs_table in ivs_order:
if value in ivs_table:
value = ivs_table[value]
replace = True
break

if replace and char not in replaced_cache:
returned = returned.replace(char, value)
replaced_cache.add(char)
if replace and (INHERITED in attr):
replace = convert_inherited
elif char in RADICALS_VARIANTS_TABLE:
value = RADICALS_VARIANTS_TABLE[char]
replace = True

# compatibility variants/IVS conversion

for compatibility_table in compatibility_order:
if value in compatibility_table:
value_new, attr = compatibility_table[value]

if _check_supp(value, value_new):
replace = bool(use_supp_planes)
if use_supp_planes == CORE:
replace = use_supp_planes in attr
else:
replace = True

if replace:
value = value_new
break
else:
for ivs_table in ivs_order:
if value in ivs_table:
value = ivs_table[value]
replace = True
break

if replace:
returned = returned.replace(char, value)
replaced_cache.add(char)

return returned

0 comments on commit 7cbb676

Please sign in to comment.