Skip to content

Instantly share code, notes, and snippets.

@jilen
Forked from sidharthkuruvila/gist:3154845
Created April 23, 2014 04:46
Show Gist options
  • Save jilen/11202990 to your computer and use it in GitHub Desktop.
Save jilen/11202990 to your computer and use it in GitHub Desktop.
/**
* 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()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment