Skip to content

Commit

Permalink
Refactor to reduce redundant code.
Browse files Browse the repository at this point in the history
  • Loading branch information
living180 authored and andialbrecht committed Aug 8, 2022
1 parent a3e19f1 commit 5ab8344
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions sqlparse/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,16 @@ def _token_matching(self, funcs, start=0, end=None, reverse=False):

if reverse:
assert end is None
for idx in range(start - 2, -1, -1):
token = self.tokens[idx]
for func in funcs:
if func(token):
return idx, token
indexes = range(start - 2, -1, -1)
else:
if end is None:
end = len(self.tokens)
for idx in range(start, end):
token = self.tokens[idx]
for func in funcs:
if func(token):
return idx, token
indexes = range(start, end)
for idx in indexes:
token = self.tokens[idx]
for func in funcs:
if func(token):
return idx, token
return None, None

def token_first(self, skip_ws=True, skip_cm=False):
Expand Down

0 comments on commit 5ab8344

Please sign in to comment.