Added core.utils.string tests & fixed some functions

This commit is contained in:
2023-04-07 14:03:45 +02:00
parent 1b60debba7
commit 823d524a81
3 changed files with 60 additions and 18 deletions

View File

@@ -37,9 +37,19 @@ class String:
String converted to snake_case
"""
# convert to train-case to CamelCase
if "_" in chars:
chars = chars.replace("_", "-")
if "-" in chars:
chars = "".join(word.title() for word in chars.split("-"))
if " " in chars:
new_chars = ""
for word in chars.split(" "):
new_chars += String.first_to_upper(word)
chars = new_chars
pattern1 = re.compile(r"(.)([A-Z][a-z]+)")
pattern2 = re.compile(r"([a-z0-9])([A-Z])")
file_name = re.sub(pattern1, r"\1_\2", chars)