Created
April 25, 2012 07:14
-
-
Save japsu/2487669 to your computer and use it in GitHub Desktop.
Convert python_style_func_names to javaStyleFuncNames
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
def python_to_java(s): | |
t = list(s) | |
try: | |
i = 0 | |
while True: | |
if t[i] == '_': | |
del t[i] | |
t[i] = t[i].upper() | |
else: | |
i += 1 | |
except IndexError, e: | |
return "".join(t) | |
TEST_DATA = [ | |
('gid_number', 'gidNumber'), | |
('multiple_under_scores', 'multipleUnderScores'), | |
('nounderscores', 'nounderscores'), | |
('underscore_at_the_end_', 'underscoreAtTheEnd'), # XXX what to do in this case? | |
('_underscore_in_the_beginning', 'UnderscoreInTheBeginning'), # XXX what to do in this case? | |
('_', ''), # XXX what to do in this case? | |
('__double_underscore__', 'DoubleUnderscore'), # XXX what to do in this case? | |
('', '') | |
] | |
def test_python_to_java(): | |
for python, java in TEST_DATA: | |
javap = python_to_java(python) | |
assert javap == java, (python, javap, java) | |
if __name__ == "__main__": | |
test_python_to_java() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment