-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix natural_sort_key with too short string
- 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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' | ||
|
@@ -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)] | ||
|