diff options
Diffstat (limited to 'container-compiler-plugin/src/main/java/io/trygvis/container/compiler/Utils.java')
-rw-r--r-- | container-compiler-plugin/src/main/java/io/trygvis/container/compiler/Utils.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/Utils.java b/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/Utils.java new file mode 100644 index 0000000..8bd0de3 --- /dev/null +++ b/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/Utils.java @@ -0,0 +1,31 @@ +package io.trygvis.container.compiler; + +import static java.lang.Character.toLowerCase; +import static java.lang.Character.toUpperCase; + +public class Utils { + public static String toFieldName(String s) { + if (s.length() < 1) { + return s.toLowerCase(); + } + char[] chars = s.toCharArray(); + + boolean toUpper = false; + + int j = 0; + for (int i = 0; i < chars.length; i++) { + char c = chars[i]; + if (c == '_') { + toUpper = true; + } else { + if (j == 0) { + chars[j++] = toLowerCase(c); + } else { + chars[j++] = toUpper ? toUpperCase(c) : c; + } + toUpper = false; + } + } + return new String(chars, 0, j); + } +} |