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
2023-09-03 16:50:12 +08:00

17 lines
566 B
Python

import sys
from typing import TypeVar
T = TypeVar("T", str, bytes, bytearray)
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