BundleNormalizer { public static String toClassName(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.toUpperCase(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);  }
@Test public void testToClassName() { final String input = "Tĥïŝ-ĩš â__fůňķŷ_Šťŕĭńġ.äÄüÿÆ¼.!/\\?+*]{[}$#@@!$%^&&ß!$%&'()*+,-./:;<=>?@[\\]^_`{|}~\""; final String expected= "ThisIsAFunkyStringAeAEueyAE14Ss"; final String actual= BundleNormalizer.toClassName(input); assertThat(actual).isEqualTo(expected); }
@Test public void testToClassName_startsWithNumber() { final String input = "1st of a series"; final String expected= "_1stOfASeries"; final String actual= BundleNormalizer.toClassName(input); assertThat(actual).isEqualTo(expected); }