def to_snake_case(not_snake_case):
    """ Converts camel-case to snake-case.

    Based on https://stackoverflow.com/a/19940888.

    Args:
      not_snake_case: a camel-case string.
    Returns:
      A snake-case string.
    """
    if not_snake_case.isupper():
        return not_snake_case.lower()

    final = ""
    size = len(not_snake_case)
    for i in range(size):
        item = not_snake_case[i]
        next_char_will_be_underscored = (
            i < size - 1 and (
                not_snake_case[i + 1] == "_" or
                not_snake_case[i + 1] == " " or
                not_snake_case[i + 1].isupper()
            )
        )

        if (item == " " or item == "_") and next_char_will_be_underscored:
            continue
        elif (item == " " or item == "_"):
            final += "_"
        elif item.isupper():
            if i > 1 and not_snake_case[i - 1].isupper():
                final += item.lower()
            else:
                final += "_" + item.lower()
        else:
            final += item
    if final[0] == "_":
        final = final[1:]
    return final