forked from openlp/openlp
- use list compression in get_natural_key
- define DIGIT_OR_NONDIGIT
This commit is contained in:
parent
118f295204
commit
8696db9f75
@ -62,6 +62,7 @@ UNO_CONNECTION_TYPE = u'pipe'
|
|||||||
#UNO_CONNECTION_TYPE = u'socket'
|
#UNO_CONNECTION_TYPE = u'socket'
|
||||||
CONTROL_CHARS = re.compile(r'[\x00-\x1F\x7F-\x9F]', re.UNICODE)
|
CONTROL_CHARS = re.compile(r'[\x00-\x1F\x7F-\x9F]', re.UNICODE)
|
||||||
INVALID_FILE_CHARS = re.compile(r'[\\/:\*\?"<>\|\+\[\]%]', re.UNICODE)
|
INVALID_FILE_CHARS = re.compile(r'[\\/:\*\?"<>\|\+\[\]%]', re.UNICODE)
|
||||||
|
DIGITS_OR_NONDIGITS = re.compile(r'\d+|\D+', re.UNICODE)
|
||||||
|
|
||||||
|
|
||||||
class VersionThread(QtCore.QThread):
|
class VersionThread(QtCore.QThread):
|
||||||
@ -401,14 +402,8 @@ def get_natural_key(string):
|
|||||||
Generate a key for locale aware natural string sorting.
|
Generate a key for locale aware natural string sorting.
|
||||||
Returns a list of string compare keys and integers.
|
Returns a list of string compare keys and integers.
|
||||||
"""
|
"""
|
||||||
key = re.findall(r'(\d+|\D+)', string)
|
key = DIGITS_OR_NONDIGITS.findall(string)
|
||||||
if len(key) == 1:
|
key = [int(part) if part.isdigit() else get_local_key(part) for part in key]
|
||||||
return list(get_local_key(string))
|
|
||||||
for index, part in enumerate(key):
|
|
||||||
if part.isdigit():
|
|
||||||
key[index] = int(part)
|
|
||||||
else:
|
|
||||||
key[index] = get_local_key(part)
|
|
||||||
return key
|
return key
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user