Created
July 21, 2012 06:30
-
-
Save sidharthkuruvila/3154845 to your computer and use it in GitHub Desktop.
Utility to functions to convert between camel case and underscore separated names
This file contains 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
/** | |
* Takes a camel cased identifier name and returns an underscore separated | |
* name | |
* | |
* Example: | |
* camelToUnderscores("thisIsA1Test") == "this_is_a_1_test" | |
*/ | |
def camelToUnderscores(name: String) = "[A-Z\\d]".r.replaceAllIn(name, {m => | |
"_" + m.group(0).toLowerCase() | |
}) | |
/* | |
* Takes an underscore separated identifier name and returns a camel cased one | |
* | |
* Example: | |
* underscoreToCamel("this_is_a_1_test") == "thisIsA1Test" | |
*/ | |
def underscoreToCamel(name: String) = "_([a-z\\d])".r.replaceAllIn(name, {m => | |
m.group(1).toUpperCase() | |
}) |
umbarger
commented
Sep 21, 2021
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment