def normalize_name()

in facebook-clang-plugins/libtooling/atdlib/normalize_names_in_atd.py [0:0]


def normalize_name(name, first_letter_in_bigcap = False):
    """
    Convert a name in java-like convention to the small-caps + underscores convention.
    Examples of renaming:
      ThisName -> this_name
      CXXDecl -> cxx_decl
    """
    name = name.strip()
    if name == "":
        return

    def f_sub(m):
        res = "";
        if m.start() != 0:
            res += "_"
        if m.group(1) != "":
            res += m.group(1).lower()
            res += "_"
        res += m.group(2).lower()
        return res

    name = bigcap.sub(f_sub, name)

    if first_letter_in_bigcap:
        name = name[0].upper() + name[1:]
    return name