1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
From: Edward Betts <edward@4angle.com>
Date: Sun, 9 Nov 2025 14:33:45 +0000
Subject: fix camelcase normalization
Forwarded: https://github.com/okunishinishi/python-stringcase/pull/47
---
stringcase.py | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/stringcase.py b/stringcase.py
index d995ec9..ccee12f 100644
--- a/stringcase.py
+++ b/stringcase.py
@@ -15,19 +15,17 @@ def camelcase(string):
string: Camel case string.
"""
-
- if string == "":
- return string
- string = string.replace("_","-")
- lst = string.split("-")
- for i in range(len(lst)):
- if i == 0:
- continue
- else:
- lst[i] = lst[i].capitalize()
-
- return "".join(lst)
+ snake = snakecase(string)
+ if not snake:
+ return snake
+
+ words = [word for word in snake.split("_") if word]
+ if not words:
+ return ''
+
+ head, *tail = words
+ return head + ''.join(word.capitalize() for word in tail)
def capitalcase(string):
"""Convert string into capital case.
|