Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/core/utils/text.py

18 lines
570 B
Python
Raw Normal View History

2023-06-02 18:04:29 +00:00
import sys
from typing import TypeVar
2023-04-23 10:32:19 +00:00
2023-06-02 18:04:29 +00:00
T = TypeVar("T", str, bytes, bytearray)
2023-04-23 10:32:19 +00:00
2023-06-02 18:04:29 +00:00
if sys.version_info.minor > 8: # PY39
def remove_suffix(string: T, suffix: T) -> T:
return string.removesuffix(suffix)
def remove_prefix(string: T, prefix: T) -> T:
return string.removeprefix(prefix)
else:
def remove_suffix(string: T, suffix: T) -> T:
return string[:-len(suffix)] if string.endswith(suffix) else string
def remove_prefix(string: T, prefix: T) -> T:
return string[len(prefix):] if string.startswith(prefix) else string