|
7 | 7 |
|
8 | 8 |
|
9 | 9 | 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) |
11 | 11 |
|
12 | 12 | camel_to_snake_map = dict()
|
13 | 13 | for match in matches:
|
14 | 14 | # 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() |
17 | 16 |
|
18 | 17 | # Convert all the groups of uppercase letters to lowercase and prepend them with '_'.
|
19 | 18 | def callback(pattern): return f"_{pattern.group(1).lower()}"
|
20 | 19 |
|
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) |
23 | 21 |
|
24 |
| - print(camel_case_to_replace, "=>", final_snake_case) |
| 22 | + print(camel_stuff, "=>", pascal_to_snake) |
25 | 23 |
|
26 | 24 | # 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 |
28 | 26 |
|
29 | 27 | # Now replace all the camel-cases with snake-cases.
|
30 | 28 | new_data = data
|
|
0 commit comments