MobileTextUtil { public static int replaceAccentedChars(StringBuilder buffer) { int sizeBefore = buffer.length(); String s = Normalizer.normalize(buffer, Normalizer.Form.NFD); int sizeAfter = s.length(); int replaced = sizeAfter - sizeBefore; if (replaced <= 0) { return 0; } s = s.replaceAll("\\p{InCombiningDiacriticalMarks}+", ""); buffer.setLength(0); buffer.append(s); return replaced; }  static int replaceSafeUnicodeChars(StringBuilder buffer); static int replaceAccentedChars(StringBuilder buffer); static final char[][] CHAR_TABLE; }
@Test public void replaceAccentedChars() throws Exception { String source = null; StringBuilder buffer = null; int replaced = -1; source = "hello"; buffer = new StringBuilder(source); replaced = MobileTextUtil.replaceAccentedChars(buffer); Assert.assertEquals(0, replaced); Assert.assertEquals(source, buffer.toString()); source = "h\u00E9llo"; buffer = new StringBuilder(source); replaced = MobileTextUtil.replaceAccentedChars(buffer); Assert.assertEquals(1, replaced); Assert.assertEquals("hello", buffer.toString()); source = "\u00E8\u00E9\u00EA\u00EB\u00EF\u00F1\u00F2"; buffer = new StringBuilder(source); replaced = MobileTextUtil.replaceAccentedChars(buffer); Assert.assertEquals(7, replaced); Assert.assertEquals("eeeeino", buffer.toString()); source = "\u20AC"; buffer = new StringBuilder(source); replaced = MobileTextUtil.replaceAccentedChars(buffer); Assert.assertEquals(0, replaced); Assert.assertEquals("\u20AC", buffer.toString()); }