@Test public void testToFieldName_startsWithNumber() { final String input = "1st of a series"; final String expected= "_1stOfASeries"; final String actual= BundleNormalizer.toFieldName(input); assertThat(actual).isEqualTo(expected); }
public static String toFieldName(String s) { Require.nonNull(s, "parameter s may not be null or empty."); Require.nonWhitespace(s, "parameter s may not be null or empty."); s= normalize(s); final char[] chars= s.toCharArray(); final StringBuilder sb= new StringBuilder(); if (Character.isDigit(chars[0])) { sb.append("_"); } sb.append(Character.toLowerCase(chars[0])); for (int i=1; i<chars.length; i++) { if (chars[i] == '_') { if (chars.length > i+1) { final char nextChar= chars[i+1]; sb.append(Character.toUpperCase(nextChar)); i++; } } else { sb.append(chars[i]); } } return sb.toString(); }
BundleNormalizer { public static String toFieldName(String s) { Require.nonNull(s, "parameter s may not be null or empty."); Require.nonWhitespace(s, "parameter s may not be null or empty."); s= normalize(s); final char[] chars= s.toCharArray(); final StringBuilder sb= new StringBuilder(); if (Character.isDigit(chars[0])) { sb.append("_"); } sb.append(Character.toLowerCase(chars[0])); for (int i=1; i<chars.length; i++) { if (chars[i] == '_') { if (chars.length > i+1) { final char nextChar= chars[i+1]; sb.append(Character.toUpperCase(nextChar)); i++; } } else { sb.append(chars[i]); } } return sb.toString(); } }
BundleNormalizer { public static String toFieldName(String s) { Require.nonNull(s, "parameter s may not be null or empty."); Require.nonWhitespace(s, "parameter s may not be null or empty."); s= normalize(s); final char[] chars= s.toCharArray(); final StringBuilder sb= new StringBuilder(); if (Character.isDigit(chars[0])) { sb.append("_"); } sb.append(Character.toLowerCase(chars[0])); for (int i=1; i<chars.length; i++) { if (chars[i] == '_') { if (chars.length > i+1) { final char nextChar= chars[i+1]; sb.append(Character.toUpperCase(nextChar)); i++; } } else { sb.append(chars[i]); } } return sb.toString(); }  }
BundleNormalizer { public static String toFieldName(String s) { Require.nonNull(s, "parameter s may not be null or empty."); Require.nonWhitespace(s, "parameter s may not be null or empty."); s= normalize(s); final char[] chars= s.toCharArray(); final StringBuilder sb= new StringBuilder(); if (Character.isDigit(chars[0])) { sb.append("_"); } sb.append(Character.toLowerCase(chars[0])); for (int i=1; i<chars.length; i++) { if (chars[i] == '_') { if (chars.length > i+1) { final char nextChar= chars[i+1]; sb.append(Character.toUpperCase(nextChar)); i++; } } else { sb.append(chars[i]); } } return sb.toString(); }  static String toClassName(String s); static String toFieldName(String s); static String toConstName(String s); static String toBundleName(String s); }
BundleNormalizer { public static String toFieldName(String s) { Require.nonNull(s, "parameter s may not be null or empty."); Require.nonWhitespace(s, "parameter s may not be null or empty."); s= normalize(s); final char[] chars= s.toCharArray(); final StringBuilder sb= new StringBuilder(); if (Character.isDigit(chars[0])) { sb.append("_"); } sb.append(Character.toLowerCase(chars[0])); for (int i=1; i<chars.length; i++) { if (chars[i] == '_') { if (chars.length > i+1) { final char nextChar= chars[i+1]; sb.append(Character.toUpperCase(nextChar)); i++; } } else { sb.append(chars[i]); } } return sb.toString(); }  static String toClassName(String s); static String toFieldName(String s); static String toConstName(String s); static String toBundleName(String s);  }