StringHelper { public static String sanitize(String s) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); ++i) { char c = s.charAt(i); switch (c) { case '\u00c0': case '\u00c1': case '\u00c3': case '\u00c4': sb.append('A'); break; case '\u00c8': case '\u00c9': case '\u00cb': sb.append('E'); break; case '\u00cc': case '\u00cd': case '\u00cf': sb.append('I'); break; case '\u00d2': case '\u00d3': case '\u00d5': case '\u00d6': sb.append('O'); break; case '\u00d9': case '\u00da': case '\u00dc': sb.append('U'); break; case '\u00e0': case '\u00e1': case '\u00e3': case '\u00e4': sb.append('a'); break; case '\u00e8': case '\u00e9': case '\u00eb': sb.append('e'); break; case '\u00ec': case '\u00ed': case '\u00ef': sb.append('i'); break; case '\u00f2': case '\u00f3': case '\u00f6': case '\u00f5': sb.append('o'); break; case '\u00f9': case '\u00fa': case '\u00fc': sb.append('u'); break; case '\u00d1': sb.append('N'); break; case '\u00f1': sb.append('n'); break; case '\u010c': sb.append('C'); break; case '\u0160': sb.append('S'); break; case '\u017d': sb.append('Z'); break; case '\u010d': sb.append('c'); break; case '\u0161': sb.append('s'); break; case '\u017e': sb.append('z'); break; case '\u00df': sb.append("ss"); break; default: if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) { sb.append(c); } else { sb.append('_'); } break; } } return sb.toString(); }  static String sanitize(String s); static String escapeJava(String s); static int overlap(CharSequence a, CharSequence b); static String toTitleCase(String str);  }
@Test public void sanitize() { assertEquals("Kramer", StringHelper.sanitize("Kr\u00E4mer")); assertEquals("Giessen", StringHelper.sanitize("Gie\u00dfen")); assertEquals("Elsyee", StringHelper.sanitize("Elsy\u00e9e")); assertEquals("Champs_Elysees", StringHelper.sanitize("Champs-\u00c9lys\u00e9es")); assertEquals("A_test_with_spaces", StringHelper.sanitize("A test with spaces")); assertEquals("any_thing_else", StringHelper.sanitize("any+thing*else")); assertEquals("Numbers_0124", StringHelper.sanitize("Numbers 0124")); }