Skip to content

Commit

Permalink
fix natural_sort_key with too short string
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans-Peter Jansen committed Mar 10, 2020
1 parent d5eefda commit 046b80b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions wm_win_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class and title are simple case sensitive wildcard pattern, that can be
# vim:set et ts=8 sw=4:
#

__version__ = '0.1.5'
__version__ = '0.1.6'
__author__ = 'Hans-Peter Jansen <[email protected]>'
__license__ = 'GNU GPL 2 - see https://www.gnu.org/licenses/gpl2.txt for details'
__homepage__ = 'https://github.com/frispete/wm-win-tool'
Expand Down Expand Up @@ -140,9 +140,12 @@ def setup_logging(loglevel):


def natural_sort_key(s, case_insensitive = True):
for sl in '[]', '()', '{}', '""', "''":
if s[0] == sl[0] and s[-1] == sl[-1]:
s = s[1:-1]
try:
for sl in '[]', '()', '{}', '""', "''":
if s[0] == sl[0] and s[-1] == sl[-1]:
s = s[1:-1]
except IndexError:
pass
text_case = lambda t: t.lower() if case_insensitive else t
return [int(text) if text.isdigit() else locale.strxfrm(text_case(text))
for text in re.split('([0-9]+)', s)]
Expand Down

0 comments on commit 046b80b

Please sign in to comment.