@@ -405,9 +405,10 @@ def clear():
405405def examples (encoding , number = 10 ):
406406 """ Use the search function to get the matching encodings and provide examples of valid encoding names. """
407407 e = []
408- for n in search (encoding ):
408+ for name in search (encoding ):
409409 for search_function in __codecs_registry :
410- if n == search_function .__name__ :
410+ n = search_function .__name__
411+ if name in [n , n .replace ("_" , "-" )]:
411412 temp = []
412413 for s in generate_strings_from_regex (search_function .__pattern__ , yield_max = 16 * number ):
413414 temp .append (s )
@@ -418,7 +419,7 @@ def examples(encoding, number=10):
418419 e .append (temp [i ])
419420 i += 1
420421 for alias , codec in aliases .items ():
421- if n == codec :
422+ if name == codec :
422423 if codec not in e :
423424 e .append (codec )
424425 if not alias .isdigit ():
@@ -626,9 +627,10 @@ def search(encoding_regex):
626627 matches = []
627628 for search_function in __codecs_registry :
628629 n = search_function .__name__
629- if re .search (encoding_regex , n ):
630- matches .append (n )
631- continue
630+ for name in [n , n .replace ("_" , "-" )]:
631+ if re .search (encoding_regex , name ):
632+ matches .append (name )
633+ continue
632634 # in some cases, encoding_regex can match a generated string that uses a particular portion of its generating
633635 # pattern ; e.g. we expect encoding_regex="uu_" to find "uu" and "uu_codec" while it can also find "morse" or
634636 # "atbash" very rarely because of their dynamic patterns and the limited number of randomly generated strings
0 commit comments