summaryrefslogtreecommitdiff
path: root/sqlparse
diff options
context:
space:
mode:
authorVictor Uriarte <victor.m.uriarte@intel.com>2016-06-08 10:06:24 -0700
committerVictor Uriarte <victor.m.uriarte@intel.com>2016-06-09 20:37:22 -0700
commit0438a1fd05ef5299facce7a097dab39218e53945 (patch)
treeca823fb0ff48aad839b19b92b5889f0d8991f228 /sqlparse
parent9ab51d65524f3816a705fdd98a8aed60ad38fe5c (diff)
downloadsqlparse-0438a1fd05ef5299facce7a097dab39218e53945.tar.gz
Refactor leading ws
Diffstat (limited to 'sqlparse')
-rw-r--r--sqlparse/filters/reindent.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/sqlparse/filters/reindent.py b/sqlparse/filters/reindent.py
index 994f0aa..f7ddfc9 100644
--- a/sqlparse/filters/reindent.py
+++ b/sqlparse/filters/reindent.py
@@ -31,16 +31,18 @@ class ReindentFilter(object):
raise StopIteration
yield t
+ @property
+ def leading_ws(self):
+ return self.offset + self.indent * self.width
+
def _get_offset(self, token):
raw = ''.join(map(text_type, self._flatten_up_to_token(token)))
line = (raw or '\n').splitlines()[-1]
# Now take current offset into account and return relative offset.
- full_offset = len(line) - len(self.char * self.width * self.indent)
- return full_offset - self.offset
+ return len(line) - len(self.char * self.leading_ws)
def nl(self):
- ws = self.n + self.char * (self.indent * self.width + self.offset)
- return sql.Token(T.Whitespace, ws)
+ return sql.Token(T.Whitespace, self.n + self.char * self.leading_ws)
def _next_token(self, tlist, idx=0):
split_words = ('FROM', 'STRAIGHT_JOIN$', 'JOIN$', 'AND', 'OR',