INNER CODE UNIT · Python
match_case
OpenChemistry/avogadrolibs · scripts/copy-default.py:192
def match_case(source, replacement):
"""Give the replacement the capitalisation style of the source word."""
if len(source) > 1 and source.isupper():
return replacement.upper()
if source[0].isupper():
return replacement[0].upper() + replacement[1:]
return replacement
def common_word(match):
word = match.group(0)
replacement = COMMON_SPELLING.get(word.lower())
if replacement is None:
return word
return match_case(word, replacement)
def swap_z(match):