From c075133bdba0af91976a27f54728ebd4a33e92f5 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 9 Nov 2020 16:19:37 -0800 Subject: [PATCH] Fix pascal_to_loudsnakes to handle repeated caps as single term. Previous code made "R_S_S_ASSIST_FAILED", now "RSS_ASSIST_FAILED". --- ycdl/exceptions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ycdl/exceptions.py b/ycdl/exceptions.py index d177f13..b79b967 100644 --- a/ycdl/exceptions.py +++ b/ycdl/exceptions.py @@ -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