diff options
author | Sjoerd Job Postmus <sjoerdjob@sjec.nl> | 2016-06-02 11:58:19 +0200 |
---|---|---|
committer | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-06-12 17:38:26 -0700 |
commit | 89d4f68ba5bbe78a9dd89257cbe4a9f3cfa76433 (patch) | |
tree | a7df0e698a209edd3dbbca3c8601e2b1bcb961ff /sqlparse/sql.py | |
parent | 8f7968ed5c649e5227e605ee272f59dd5ca75adb (diff) | |
download | sqlparse-89d4f68ba5bbe78a9dd89257cbe4a9f3cfa76433.tar.gz |
Use a specialized token_idx_next.
Prevent calling token_index.
Diffstat (limited to 'sqlparse/sql.py')
-rw-r--r-- | sqlparse/sql.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/sqlparse/sql.py b/sqlparse/sql.py index 9782c33..f3ef642 100644 --- a/sqlparse/sql.py +++ b/sqlparse/sql.py @@ -350,6 +350,26 @@ class TokenList(Token): funcs = lambda tk: not (tk.is_whitespace() and skip_ws) return self._token_matching(funcs, idx) + def token_idx_next(self, idx, skip_ws=True): + """Returns the next token relative to *idx*. + + If *skip_ws* is ``True`` (the default) whitespace tokens are ignored. + ``None`` is returned if there's no next token. + """ + if isinstance(idx, int): + idx += 1 # alot of code usage current pre-compensates for this + try: + if not skip_ws: + return idx, self.tokens[idx] + else: + while True: + token = self.tokens[idx] + if not token.is_whitespace(): + return idx, token + idx += 1 + except IndexError: + return None, None + def token_index(self, token, start=0): """Return list index of token.""" start = self.token_index(start) if not isinstance(start, int) else start |