camel_case_splitter.py 854 B

1234567891011121314151617181920212223242526272829303132333435
  1. def split_camel_case(input):
  2. def remove_camel_case(camel_case_input):
  3. no_camel_case = ""
  4. if len(camel_case_input) <= 0:
  5. return ""
  6. no_camel_case += camel_case_input[0].lower()
  7. for c in camel_case_input[1:]:
  8. if c.isupper():
  9. no_camel_case += "_" + c.lower()
  10. else:
  11. no_camel_case += c
  12. return no_camel_case
  13. underscore_split = input.split("_")
  14. retval = ""
  15. for i in underscore_split:
  16. if is_camel_case_name(i):
  17. retval += remove_camel_case(i) + "_"
  18. else:
  19. retval += i + "_"
  20. return retval[:-1].replace("__", "_")
  21. def is_camel_case_name(input):
  22. if '_' in input:
  23. return False
  24. if input.islower():
  25. return False
  26. if input.isupper():
  27. return False
  28. return True