diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c9162f..535f4a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## [Unreleased] ### Added -- `helpers.match_pattern` and `helpers.translate_glob_to_regex` functions, by @HardNorth +- `match_pattern` and `translate_glob_to_regex`, `normalize_caseless`, `caseless_equal` functions in `helpers` module, by @HardNorth ### Removed - `Python 3.7` support, by @HardNorth diff --git a/reportportal_client/helpers.py b/reportportal_client/helpers.py index 9d1544c..9c6d4b8 100644 --- a/reportportal_client/helpers.py +++ b/reportportal_client/helpers.py @@ -20,6 +20,7 @@ import re import threading import time +import unicodedata import uuid from platform import machine, processor, system from types import MappingProxyType @@ -517,3 +518,22 @@ def match_pattern(pattern: Optional[re.Pattern], line: Optional[str]) -> bool: return False return pattern.fullmatch(line) is not None + + +def normalize_caseless(text: str) -> str: + """Normalize and casefold the text. + + :param text: text to normalize + :return: normalized text + """ + return unicodedata.normalize("NFKD", text.casefold()) + + +def caseless_equal(left: str, right: str) -> bool: + """Check if two strings are equal ignoring case. + + :param left: left string + :param right: right string + :return: True if strings are equal ignoring case, False otherwise + """ + return normalize_caseless(left) == normalize_caseless(right)