Normalize and restrict value-space with pre-lexical and lexical facets. :param text: text string encoded value. :return: a normalized string.
(self, text: str | bytes)
| 445 | any(self.is_derived(mt) for mt in other.member_types) |
| 446 | |
| 447 | def normalize(self, text: str | bytes) -> str: |
| 448 | """ |
| 449 | Normalize and restrict value-space with pre-lexical and lexical facets. |
| 450 | |
| 451 | :param text: text string encoded value. |
| 452 | :return: a normalized string. |
| 453 | """ |
| 454 | if isinstance(text, bytes): |
| 455 | text = text.decode('utf-8') |
| 456 | |
| 457 | match self.white_space: |
| 458 | case 'replace': |
| 459 | return self._REGEX_SPACE.sub(' ', text) |
| 460 | case 'collapse': |
| 461 | return self._REGEX_SPACES.sub(' ', text).strip() |
| 462 | case _: |
| 463 | return text |
| 464 | |
| 465 | def text_decode(self, text: str, validation: str = 'skip', |
| 466 | context: ValidationContext | None = None) -> DecodedValueType: |
no test coverage detected