mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-08-03 09:34:04 +00:00
31 lines
850 B
Python
31 lines
850 B
Python
"""Compare string utility functions."""
|
|
import string
|
|
|
|
|
|
def cmp_string_equal(
|
|
a: str,
|
|
b: str,
|
|
ignore_case: bool = False,
|
|
ignore_punctuation: bool = False,
|
|
ignore_whitespace: bool = False,
|
|
) -> bool:
|
|
"""Compare two strings are equal or not.
|
|
|
|
Args:
|
|
a(str): The first string.
|
|
b(str): The second string.
|
|
ignore_case(bool): Ignore case or not.
|
|
ignore_punctuation(bool): Ignore punctuation or not.
|
|
ignore_whitespace(bool): Ignore whitespace or not.
|
|
"""
|
|
if ignore_case:
|
|
a = a.lower()
|
|
b = b.lower()
|
|
if ignore_punctuation:
|
|
a = a.translate(str.maketrans("", "", string.punctuation))
|
|
b = b.translate(str.maketrans("", "", string.punctuation))
|
|
if ignore_whitespace:
|
|
a = "".join(a.split())
|
|
b = "".join(b.split())
|
|
return a == b
|