@Test public void replaceSafeUnicodeChars() throws Exception { String source = null; StringBuilder buffer = null; int replaced = -1; source = "hello"; buffer = new StringBuilder(source); replaced = MobileTextUtil.replaceSafeUnicodeChars(buffer); Assert.assertEquals(0, replaced); Assert.assertEquals(source, buffer.toString()); source = "\u201chello\u201d \u201cworld\u201d \u201cthis\u201d"; buffer = new StringBuilder(source); replaced = MobileTextUtil.replaceSafeUnicodeChars(buffer); Assert.assertEquals(6, replaced); Assert.assertEquals("\"hello\" \"world\" \"this\"", buffer.toString()); source = "\u201chello\u201d \u201cworld\u201d \u201cthis\u201d"; buffer = new StringBuilder(source); replaced = MobileTextUtil.replaceSafeUnicodeChars(buffer); Assert.assertEquals(6, replaced); Assert.assertEquals("\"hello\" \"world\" \"this\"", buffer.toString()); source = "\u2018hello\u2019 \u2018world\u2019 don\u2019t"; buffer = new StringBuilder(source); replaced = MobileTextUtil.replaceSafeUnicodeChars(buffer); Assert.assertEquals(5, replaced); Assert.assertEquals("\'hello\' \'world\' don\'t", buffer.toString()); }
static public int replaceSafeUnicodeChars(StringBuilder buffer) { int replaced = 0; for (int i = 0; i < buffer.length(); i++) { char c = buffer.charAt(i); for (int j = 0; j < CHAR_TABLE.length; j++) { if (c == CHAR_TABLE[j][0]) { replaced++; buffer.setCharAt(i, CHAR_TABLE[j][1]); } } } return replaced; }
MobileTextUtil { static public int replaceSafeUnicodeChars(StringBuilder buffer) { int replaced = 0; for (int i = 0; i < buffer.length(); i++) { char c = buffer.charAt(i); for (int j = 0; j < CHAR_TABLE.length; j++) { if (c == CHAR_TABLE[j][0]) { replaced++; buffer.setCharAt(i, CHAR_TABLE[j][1]); } } } return replaced; } }
MobileTextUtil { static public int replaceSafeUnicodeChars(StringBuilder buffer) { int replaced = 0; for (int i = 0; i < buffer.length(); i++) { char c = buffer.charAt(i); for (int j = 0; j < CHAR_TABLE.length; j++) { if (c == CHAR_TABLE[j][0]) { replaced++; buffer.setCharAt(i, CHAR_TABLE[j][1]); } } } return replaced; }  }
MobileTextUtil { static public int replaceSafeUnicodeChars(StringBuilder buffer) { int replaced = 0; for (int i = 0; i < buffer.length(); i++) { char c = buffer.charAt(i); for (int j = 0; j < CHAR_TABLE.length; j++) { if (c == CHAR_TABLE[j][0]) { replaced++; buffer.setCharAt(i, CHAR_TABLE[j][1]); } } } return replaced; }  static int replaceSafeUnicodeChars(StringBuilder buffer); static int replaceAccentedChars(StringBuilder buffer); }
MobileTextUtil { static public int replaceSafeUnicodeChars(StringBuilder buffer) { int replaced = 0; for (int i = 0; i < buffer.length(); i++) { char c = buffer.charAt(i); for (int j = 0; j < CHAR_TABLE.length; j++) { if (c == CHAR_TABLE[j][0]) { replaced++; buffer.setCharAt(i, CHAR_TABLE[j][1]); } } } return replaced; }  static int replaceSafeUnicodeChars(StringBuilder buffer); static int replaceAccentedChars(StringBuilder buffer); static final char[][] CHAR_TABLE; }