Created
April 17, 2012 14:36
-
-
Save dnoseda/2406374 to your computer and use it in GitHub Desktop.
uncamelize key of map in groovy
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
Map toUncamelizedKeyMap(Map map){ | |
(map+[:]).each{k,v-> | |
map[k.replaceAll(/([A-Z])/,'_$1').toLowerCase()] = v | |
} | |
return map | |
} | |
Map toCamelizedKeyMap(def map){ | |
(map+[:]).each{k,v-> | |
def camelized = k.split("_").collect({"${it[0].toUpperCase()}${it[1..-1]}"}).join() | |
map[camelized[0].toLowerCase()+camelized[1..-1]] = v | |
} | |
return map | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment