Skip to content

Commit bbf711b

Browse files
committed
Add normalize_caseless, caseless_equal functions in helpers module
1 parent 960cffe commit bbf711b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## [Unreleased]
44
### Added
5-
- `helpers.match_pattern` and `helpers.translate_glob_to_regex` functions, by @HardNorth
5+
- `match_pattern` and `translate_glob_to_regex`, `normalize_caseless`, `caseless_equal` functions in `helpers` module, by @HardNorth
66
### Removed
77
- `Python 3.7` support, by @HardNorth
88

reportportal_client/helpers.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import re
2121
import threading
2222
import time
23+
import unicodedata
2324
import uuid
2425
from platform import machine, processor, system
2526
from types import MappingProxyType
@@ -517,3 +518,22 @@ def match_pattern(pattern: Optional[re.Pattern], line: Optional[str]) -> bool:
517518
return False
518519

519520
return pattern.fullmatch(line) is not None
521+
522+
523+
def normalize_caseless(text: str) -> str:
524+
"""Normalize and casefold the text.
525+
526+
:param text: text to normalize
527+
:return: normalized text
528+
"""
529+
return unicodedata.normalize("NFKD", text.casefold())
530+
531+
532+
def caseless_equal(left: str, right: str) -> bool:
533+
"""Check if two strings are equal ignoring case.
534+
535+
:param left: left string
536+
:param right: right string
537+
:return: True if strings are equal ignoring case, False otherwise
538+
"""
539+
return normalize_caseless(left) == normalize_caseless(right)

0 commit comments

Comments
 (0)