Skip to content

Commit 7476a69

Browse files
committed
Fixed camel case to snake case conversion
1 parent 2fca2aa commit 7476a69

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

nicedoc/camel_to_snake.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,22 @@
77

88

99
def convert_camel_to_snake(data):
10-
matches = re.finditer(regex_utils.EXTRACT_CAMEL, data)
10+
matches = re.finditer(regex_utils.EXTRACT_CAMEL, data, re.MULTILINE)
1111

1212
camel_to_snake_map = dict()
1313
for match in matches:
1414
# print(match.groups())
15-
beggining, lowercase_stuff, pascal_stuff, _last_pascal_group = match.groups()
16-
camel_case_to_replace = f"{beggining}{lowercase_stuff}{pascal_stuff}"
15+
beggining, camel_stuff, _, _, _ = match.groups()
1716

1817
# Convert all the groups of uppercase letters to lowercase and prepend them with '_'.
1918
def callback(pattern): return f"_{pattern.group(1).lower()}"
2019

21-
pascal_to_snake = re.sub(r'([A-Z]+)', callback, pascal_stuff)
22-
final_snake_case = f"{beggining}{lowercase_stuff}{pascal_to_snake}"
20+
pascal_to_snake = re.sub(r'([A-Z]+)', callback, camel_stuff)
2321

24-
print(camel_case_to_replace, "=>", final_snake_case)
22+
print(camel_stuff, "=>", pascal_to_snake)
2523

2624
# store the required changes to be made in a dictionary
27-
camel_to_snake_map[camel_case_to_replace] = final_snake_case
25+
camel_to_snake_map[camel_stuff] = pascal_to_snake
2826

2927
# Now replace all the camel-cases with snake-cases.
3028
new_data = data

0 commit comments

Comments
 (0)