Refactoring

main
Bob Mottram 2022-09-26 10:37:44 +01:00
parent 61f489ff51
commit fa08879245
2 changed files with 13 additions and 22 deletions

View File

@ -7553,8 +7553,8 @@ def _test_hashtag_maps():
def _test_uninvert():
print('test_uninvert')
text = 'ʇsǝʇ ɐ sı sıɥʇ'
expected = "this is a test"
text = 'ʇsƎʇ ɐ sı sıɥ⊥'
expected = "This is a tEst"
result = remove_inverted_text(text, 'en')
if result != expected:
print('text: ' + text)

View File

@ -3891,30 +3891,21 @@ def remove_inverted_text(text: str, system_language: str) -> str:
separator = '</p>'
paragraphs = text.split(separator)
new_text = ''
inverted_list = (inverted_lower, inverted_upper)
z_value = (ord('z'), ord('Z'))
for para in paragraphs:
replaced_chars = 0
index = 0
z_value = ord('z')
for test_ch in inverted_lower:
if test_ch == '_':
for idx in range(2):
index = 0
for test_ch in inverted_list[idx]:
if test_ch == '_':
index += 1
continue
if test_ch in para:
para = para.replace(test_ch, chr(z_value[idx] - index))
replaced_chars += 1
index += 1
continue
if test_ch in para:
para = para.replace(test_ch, chr(z_value - index))
replaced_chars += 1
index += 1
index = 0
z_value = ord('Z')
for test_ch in inverted_upper:
if test_ch == '_':
index += 1
continue
if test_ch in para:
para = para.replace(test_ch, chr(z_value - index))
replaced_chars += 1
index += 1
if replaced_chars > 2:
para = para[::-1]