mirror of https://gitlab.com/bashrc2/epicyon
Refactoring
parent
61f489ff51
commit
fa08879245
4
tests.py
4
tests.py
|
@ -7553,8 +7553,8 @@ def _test_hashtag_maps():
|
||||||
|
|
||||||
def _test_uninvert():
|
def _test_uninvert():
|
||||||
print('test_uninvert')
|
print('test_uninvert')
|
||||||
text = 'ʇsǝʇ ɐ sı sıɥʇ'
|
text = 'ʇsƎʇ ɐ sı sıɥ⊥'
|
||||||
expected = "this is a test"
|
expected = "This is a tEst"
|
||||||
result = remove_inverted_text(text, 'en')
|
result = remove_inverted_text(text, 'en')
|
||||||
if result != expected:
|
if result != expected:
|
||||||
print('text: ' + text)
|
print('text: ' + text)
|
||||||
|
|
19
utils.py
19
utils.py
|
@ -3891,28 +3891,19 @@ def remove_inverted_text(text: str, system_language: str) -> str:
|
||||||
separator = '</p>'
|
separator = '</p>'
|
||||||
paragraphs = text.split(separator)
|
paragraphs = text.split(separator)
|
||||||
new_text = ''
|
new_text = ''
|
||||||
|
inverted_list = (inverted_lower, inverted_upper)
|
||||||
|
z_value = (ord('z'), ord('Z'))
|
||||||
for para in paragraphs:
|
for para in paragraphs:
|
||||||
replaced_chars = 0
|
replaced_chars = 0
|
||||||
|
|
||||||
|
for idx in range(2):
|
||||||
index = 0
|
index = 0
|
||||||
z_value = ord('z')
|
for test_ch in inverted_list[idx]:
|
||||||
for test_ch in inverted_lower:
|
|
||||||
if test_ch == '_':
|
if test_ch == '_':
|
||||||
index += 1
|
index += 1
|
||||||
continue
|
continue
|
||||||
if test_ch in para:
|
if test_ch in para:
|
||||||
para = para.replace(test_ch, chr(z_value - index))
|
para = para.replace(test_ch, chr(z_value[idx] - 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
|
replaced_chars += 1
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue