summaryrefslogtreecommitdiff
path: root/kconfiglib.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-01-19 19:43:49 +0100
committerUlf Magnusson <ulfalizer@gmail.com>2018-01-19 19:53:43 +0100
commit48bc8e4a7ba7d5ea4360b22a3527a3b028c6ce3b (patch)
tree6c3eb4c5e322d76b3cb00df2dd3f0e13364e88a9 /kconfiglib.py
parentc3142e821e990a1f1a5eb75cefb8244b553db094 (diff)
Always rstrip() when dedenting
Factors out some code and makes the logic a bit more transparent. It's only used for help text lines.
Diffstat (limited to 'kconfiglib.py')
-rw-r--r--kconfiglib.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index c52b156..db0ffb0 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -1745,7 +1745,7 @@ class Kconfig(object):
self._reuse_line = True # "Unget" the line
break
- help_lines = [_deindent(line, indent).rstrip()]
+ help_lines = [_dedent_rstrip(line, indent)]
# The help text goes on till the first non-empty line with less
# indent
@@ -1758,7 +1758,7 @@ class Kconfig(object):
node.help = "\n".join(help_lines).rstrip() + "\n"
break
- help_lines.append(_deindent(line, indent).rstrip())
+ help_lines.append(_dedent_rstrip(line, indent))
if not line:
break
@@ -3752,11 +3752,18 @@ def _indentation(line):
line = line.expandtabs()
return len(line) - len(line.lstrip())
-def _deindent(line, indent):
- """
- Deindents 'line' by 'indent' spaces.
+def _dedent_rstrip(line, indent):
+ r"""
+ De-indents 'line' by 'indent' spaces and rstrip()s it to remove any
+ newlines (which gets rid of other trailing whitespace too, but that's
+ fine).
+
+ Used to prepare help text lines in a speedy way: The [indent:] might
+ already remove trailing newlines for lines shorter than indent (e.g. empty
+ lines). The rstrip() makes it consistent, meaning we can join the lines
+ with "\n" later.
"""
- return line.expandtabs()[indent:]
+ return line.expandtabs()[indent:].rstrip()
def _is_base_n(s, n):
try: