replace some control characters with their symbol counterparts

This commit is contained in:
2022-05-07 10:36:55 +02:00
parent 4d794480c7
commit 7d9a2d0648
3 changed files with 42 additions and 11 deletions

View File

@@ -36,12 +36,34 @@ class Line:
prefix_chars = prefix_bytes.decode("utf8", errors="ignore")
return len(prefix_chars)
def line_tabs_replaced(self):
def line_prepared_for_display(self):
line = self._line_tabs_replaced()
line = self._replace_control_chars_with_pictures(line)
return line
def _replace_control_chars_with_pictures(self, line: str):
length = len(line)
for i in range(length):
c = line[i]
if unicodedata.category(c) == "Cc" and c != "\r" and c != "\n" and c != "\t":
ordinal_value = ord(c)
if ordinal_value < 32 and not ordinal_value in [9, 10, 11]:
# print(ord(c), " -> ", hex(ord(c)), " -> ", unicodedata.category(c), " -> ", chr(9216 + ord(c)))
line = line.replace(c, chr(9216 + ord(c))) # see Unicode Block “Control Pictures”
else:
# print(ord(c), " -> ", hex(ord(c)), " -> ", unicodedata.category(c), " -> \u2421")
line = line.replace(c, "\u2421") # symbol for delete (␡)
# print(line)
return line;
def _line_tabs_replaced(self):
line = self._line;
i = 0
offset = 0
result = ""
length = len(line)
# length = len(line)
while True:
tab_index = line.find("\t", offset)
if tab_index < 0: