Skip to content

Commit

Permalink
Add normalize_caseless, caseless_equal functions in helpers module
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Dec 11, 2024
1 parent 960cffe commit bbf711b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 20 additions & 0 deletions reportportal_client/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import re
import threading
import time
import unicodedata
import uuid
from platform import machine, processor, system
from types import MappingProxyType
Expand Down Expand Up @@ -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)

0 comments on commit bbf711b

Please sign in to comment.