From 890c39aca8ac2f3932d61c59a2a186dbe12a0c44 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Thu, 4 Jun 2015 20:49:52 +0200 Subject: Refactor and optimize _indentation(). I must have missed that expandtabs() already takes the context of tabs into account the first time around. Also remove error check that probably won't be useful. --- kconfiglib.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'kconfiglib.py') diff --git a/kconfiglib.py b/kconfiglib.py index c9613de..367de07 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -3681,19 +3681,10 @@ def _strip_quotes(s, line, filename, linenr): return s def _indentation(line): - """Returns the indentation of the line, treating tab stops as being spaced - 8 characters apart.""" - if line.isspace(): - _internal_error("Attempt to take indentation of blank line.") - indent = 0 - for c in line: - if c == " ": - indent += 1 - elif c == "\t": - # Go to the next tab stop - indent = (indent + 8) & ~7 - else: - return indent + """Returns the length of the line's leading whitespace, treating tab stops + as being spaced 8 characters apart.""" + line = line.expandtabs() + return len(line) - len(line.lstrip()) def _deindent(line, indent): """Deindent 'line' by 'indent' spaces.""" -- cgit v1.2.3