BundleNormalizer { protected static String normalize(String s) { Require.nonNull(s, "parameter s may not be null or empty."); s= replaceUmlauts(s); s= s.replaceAll("[\\ \\.\\-\n/]+", "_"); s= Normalizer .normalize(s, Normalizer.Form.NFKD) .replaceAll("[^\\P{M}]", "") .replaceAll("[^\\p{Alnum}\\_\\-\\ ]", ""); s= s.replaceAll("[_]+", "_"); s= s.replaceAll("^_", "").replaceAll("_$", ""); return s; }  static String toClassName(String s); static String toFieldName(String s); static String toConstName(String s); static String toBundleName(String s);  }
@Test public void testNormalize() { final String input = "Tĥïŝ-ĩš â__fůňķŷ_Šťŕĭńġ.äÄüÿÆ¼.!/\\?+*]{[}$#@@!$%^&&ß!$%&'()*+,-./:;<=>?@[\\]^_`{|}~\""; final String expected= "This_is_a_funky_String_aeAEueyAE14_ss"; final String actual= BundleNormalizer.normalize(input); assertThat(actual).isEqualTo(expected); }
@Test public void testNormalize_alreadyNormalized() { final String input = "This_is_a_funky_String_aeAEueyAE14_ss"; final String expected= "This_is_a_funky_String_aeAEueyAE14_ss"; final String actual= BundleNormalizer.normalize(input); assertThat(actual).isEqualTo(expected); }
@Test public void testNormalize_startsWithNumber() { final String input = "1stOfaSeries"; final String expected= "1stOfaSeries"; final String actual= BundleNormalizer.normalize(input); assertThat(actual).isEqualTo(expected); }
@Test public void testNormalize_withLineBreak() { final String input = "text\nover\nmultiple\nlines"; final String expected= "text_over_multiple_lines"; final String actual= BundleNormalizer.normalize(input); assertThat(actual).isEqualTo(expected); }