From 1ce83469217975621da61a2b314930b5ac8d7953 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 29 Oct 2020 16:44:36 +0100 Subject: [PATCH] better implementation of camelcase old camelcase implementation did not work for many cases (multiple capital, spaces, ...). New implementation should catch all problems --- stringcase.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/stringcase.py b/stringcase.py index ae1677d..dde3c67 100644 --- a/stringcase.py +++ b/stringcase.py @@ -16,10 +16,8 @@ def camelcase(string): """ - string = re.sub(r"^[\-_\.]", '', str(string)) - if not string: - return string - return lowercase(string[0]) + re.sub(r"[\-_\.\s]([a-z])", lambda matched: uppercase(matched.group(1)), string[1:]) + string = ''.join(s.capitalize() for s in re.split('([^a-zA-Z0-9])', string) if a.isalnum()) + return str.lower(string[:1]) + string[1:] def capitalcase(string):