mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-04-13 12:09:48 +08:00
feat(string): add natural_sort_key function
This commit is contained in:
@@ -938,3 +938,15 @@ class StringUtils:
|
||||
if isinstance(content, bytes) and content.startswith(b"magnet:"):
|
||||
return True
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def natural_sort_key(text: str) -> List[Union[int, str]]:
|
||||
"""
|
||||
自然排序
|
||||
将字符串拆分为数字和非数字部分,数字部分转换为整数,非数字部分转换为小写字母
|
||||
:param text: 要处理的字符串
|
||||
"""
|
||||
if not isinstance(text, str):
|
||||
return [text]
|
||||
|
||||
return [int(part) if part.isdigit() else part.lower() for part in re.split(r'(\d+)', text)]
|
||||
|
||||
Reference in New Issue
Block a user