summaryrefslogtreecommitdiff
path: root/alot/helper.py
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-05-05 11:42:18 +0200
committerAnton Khirnov <anton@khirnov.net>2020-05-05 11:42:18 +0200
commit687e08cfcedc18e605fecf17bc0914154ad1b2fd (patch)
treeb664711c1b9d7f9078d67bf4bb72c1fb5e1d45dd /alot/helper.py
parentb7c03a4e96d04ab7485d133153eeb820e672caa3 (diff)
helper: move string_sanitize() to the only place where it is used
Diffstat (limited to 'alot/helper.py')
-rw-r--r--alot/helper.py40
1 files changed, 0 insertions, 40 deletions
diff --git a/alot/helper.py b/alot/helper.py
index 1d541d76..1ab6ead0 100644
--- a/alot/helper.py
+++ b/alot/helper.py
@@ -49,46 +49,6 @@ def split_commandstring(cmdstring):
return shlex.split(cmdstring)
-def string_sanitize(string, tab_width=8):
- r"""
- strips, and replaces non-printable characters
-
- :param tab_width: number of spaces to replace tabs with. Read from
- `globals.tabwidth` setting if `None`
- :type tab_width: int or `None`
-
- >>> string_sanitize(' foo\rbar ', 8)
- ' foobar '
- >>> string_sanitize('foo\tbar', 8)
- 'foo bar'
- >>> string_sanitize('foo\t\tbar', 8)
- 'foo bar'
- """
-
- string = string.replace('\r', '')
-
- lines = list()
- for line in string.split('\n'):
- tab_count = line.count('\t')
-
- if tab_count > 0:
- line_length = 0
- new_line = list()
- for i, chunk in enumerate(line.split('\t')):
- line_length += len(chunk)
- new_line.append(chunk)
-
- if i < tab_count:
- next_tab_stop_in = tab_width - (line_length % tab_width)
- new_line.append(' ' * next_tab_stop_in)
- line_length += next_tab_stop_in
- lines.append(''.join(new_line))
- else:
- lines.append(line)
-
- return '\n'.join(lines)
-
-
def string_decode(string, enc='ascii'):
"""
safely decodes string to unicode bytestring, respecting `enc` as a hint.