Skip to content

Commit 5298dcb

Browse files
author
cheung
committed
Define camel_to_snake function
The function is supposed to change the identifiers format from camelCase to snake_case
1 parent 5b106cf commit 5298dcb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

java2python/config/snake_case.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,15 @@
3333
(Type('FUNCTIION_METHOD_DECL') > Type('IDENT'),camel_to_snake),
3434
(Type('VOID_METHOD_DECL') > Type('IDENT'),camel_to_snake)
3535
]
36+
37+
def camel_to_snake(node,config):
38+
rawstring = re.findall('[a-z]+|[A-Z][a-z]*',node.token.text)
39+
snake_string = ""
40+
index = 0
41+
for word in rawstring:
42+
if index == 0:
43+
snake_string += word
44+
index = index + 1
45+
else:
46+
snake_string += "_" + word
47+
node.token.text = snake_string

0 commit comments

Comments
 (0)