# HG changeset patch # User RhodeCode Admin # Date 2023-03-24 08:43:27 # Node ID b0280397e568e4a0248fbb1005a2b076274aad2f # Parent ff25f2010ffa766b49cb3187c7ccb3cbe8b8d38c str_utils: added common non-ascii replacer diff --git a/rhodecode/lib/str_utils.py b/rhodecode/lib/str_utils.py --- a/rhodecode/lib/str_utils.py +++ b/rhodecode/lib/str_utils.py @@ -20,6 +20,7 @@ import logging import rhodecode +import unicodedata from rhodecode.lib.type_utils import aslist log = logging.getLogger(__name__) @@ -133,3 +134,14 @@ def ascii_str(str_): if not isinstance(str_, bytes): raise ValueError('ascii_str cannot convert other types than bytes: got: {}'.format(type(str_))) return str_.decode('ascii') + + +def convert_special_chars(str_): + """ + trie to replace non-ascii letters to their ascii representation eg:: + + `żołw` converts into `zolw` + """ + value = safe_str(str_) + converted_value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode() + return converted_value