forked from BlenderCL/weed
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathname_utils.py
More file actions
executable file
·36 lines (31 loc) · 1011 Bytes
/
name_utils.py
File metadata and controls
executable file
·36 lines (31 loc) · 1011 Bytes
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
import re
def get_valid_variable_name(name):
return re.sub("\W+", "", name)
def get_lower_case_with_underscores(name):
words = get_words(name)
words = [word.lower() for word in words]
output = "_".join(words)
return output
def get_separated_capitalized_words(name):
words = get_words(name)
words = [word.capitalize() for word in words]
output = " ".join(words)
return output
def get_words(name):
words = []
current_word = ""
for char in name:
if char.islower():
current_word += char
if char.isupper():
if current_word.isupper() or len(current_word) == 0:
current_word += char
else:
words.append(current_word)
current_word = char
if char == "_":
words.append(current_word)
current_word = ""
words.append(current_word)
words = [word for word in words if len(word) > 0]
return words