From b5d6f23d8ac3d4bedb139fdaecc2e9dc621f385a Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 3 Aug 2013 15:06:46 +0200 Subject: wip --- .../java/io/trygvis/container/compiler/Utils.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 container-compiler-plugin/src/main/java/io/trygvis/container/compiler/Utils.java (limited to 'container-compiler-plugin/src/main/java/io/trygvis/container/compiler/Utils.java') 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); + } +} -- cgit v1.2.3