Fix pascal_to_loudsnakes to handle repeated caps as single term.

Previous code made "R_S_S_ASSIST_FAILED", now "RSS_ASSIST_FAILED".
This commit is contained in:
voussoir 2020-11-09 16:19:37 -08:00
parent 5841279f9e
commit c075133bdb

View file

@ -4,8 +4,8 @@ def pascal_to_loudsnakes(text):
'''
NoSuchPhoto -> NO_SUCH_PHOTO
'''
match = re.findall(r'[A-Z][a-z]*', text)
text = '_'.join(match)
text = re.sub(r'([a-z])([A-Z])', r'\1_\2', text)
text = re.sub(r'([A-Z]+)([A-Z][a-z])', r'\1_\2', text)
text = text.upper()
return text