Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 30 additions & 17 deletions manimlib/utils/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@


def to_camel_case(name):
return "".join([
[c for c in part if c not in string.punctuation + string.whitespace].capitalize()
for part in name.split("_")
])
return "".join(
[
[
c for c in part if c not in string.punctuation + string.whitespace
].capitalize()
for part in name.split("_")
]
)


def initials(name, sep_values=[" ", "_"]):
return "".join([
(s[0] if s else "")
for s in re.split("|".join(sep_values), name)
])
def initials(name, sep_values=None):
if sep_values is None:
sep_values = [" ", "_"]
return "".join([(s[0] if s else "") for s in re.split("|".join(sep_values), name)])


def camel_case_initials(name):
Expand All @@ -37,10 +40,16 @@ def split_string_to_isolate_substrings(full_string, *substrings_to_isolate):
if len(substrings_to_isolate) == 0:
return [full_string]
substring_to_isolate = substrings_to_isolate[0]
all_substrings = list(it.chain(*list(zip(
full_string.split(substring_to_isolate),
it.repeat(substring_to_isolate)
))))
all_substrings = list(
it.chain(
*list(
zip(
full_string.split(substring_to_isolate),
it.repeat(substring_to_isolate),
)
)
)
)
all_substrings.pop(-1)
all_substrings = [s for s in all_substrings if s != ""]
return split_string_list_to_isolate_substrings(
Expand All @@ -53,7 +62,11 @@ def split_string_list_to_isolate_substrings(string_list, *substrings_to_isolate)
Similar to split_string_to_isolate_substrings, but the first argument
is a list of strings, thought of as something already broken up a bit.
"""
return list(it.chain(*[
split_string_to_isolate_substrings(s, *substrings_to_isolate)
for s in string_list
]))
return list(
it.chain(
*[
split_string_to_isolate_substrings(s, *substrings_to_isolate)
for s in string_list
]
)
)