Skip to content

Instantly share code, notes, and snippets.

@dnoseda
Created October 31, 2011 18:14
Show Gist options
  • Save dnoseda/1328289 to your computer and use it in GitHub Desktop.
Save dnoseda/1328289 to your computer and use it in GitHub Desktop.
camelize in groovy
public String camelize(String cmdName, boolean firstUpper = false) {
def words = cmdName.split("\\_");
return (firstUpper ? capitalize(words[0]) : words[0]) + words[1..(words.size() -1)].collect({capitalize(it)}).join()
}
public String capitalize(String a){
String s = a.substring(1)
return "${a[0].toUpperCase()}${s.toLowerCase()}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment