@Test public void shouldFilterPrivateUnicodeCharacters() throws Exception { byte[] b = new byte[] { (byte) 0xee, (byte) 0x90, (byte) 0x87, (byte) 0xf0, (byte) 0x9f, (byte) 0x98, (byte) 0xa4, (byte) 0xee, (byte) 0x84, (byte) 0x87 }; String s = new String(b, Charset.forName("UTF-8")); assertThat(s.length()).isEqualTo(4); String filtered = WhatsAppMessage.filterPrivateBlock(s); assertThat(filtered).isEqualTo("\uD83D\uDE24"); assertThat(filtered.length()).isEqualTo(2); }
static String filterPrivateBlock(String s) { if (s == null) return null; final StringBuilder sb = new StringBuilder(); for (int i=0; i<s.length(); ) { int codepoint = s.codePointAt(i); Character.UnicodeBlock block = Character.UnicodeBlock.of(codepoint); if (block != Character.UnicodeBlock.PRIVATE_USE_AREA) { sb.append(Character.toChars(codepoint)); } i += Character.charCount(codepoint); } return sb.toString(); }
WhatsAppMessage implements Comparable<WhatsAppMessage> { static String filterPrivateBlock(String s) { if (s == null) return null; final StringBuilder sb = new StringBuilder(); for (int i=0; i<s.length(); ) { int codepoint = s.codePointAt(i); Character.UnicodeBlock block = Character.UnicodeBlock.of(codepoint); if (block != Character.UnicodeBlock.PRIVATE_USE_AREA) { sb.append(Character.toChars(codepoint)); } i += Character.charCount(codepoint); } return sb.toString(); } }
WhatsAppMessage implements Comparable<WhatsAppMessage> { static String filterPrivateBlock(String s) { if (s == null) return null; final StringBuilder sb = new StringBuilder(); for (int i=0; i<s.length(); ) { int codepoint = s.codePointAt(i); Character.UnicodeBlock block = Character.UnicodeBlock.of(codepoint); if (block != Character.UnicodeBlock.PRIVATE_USE_AREA) { sb.append(Character.toChars(codepoint)); } i += Character.charCount(codepoint); } return sb.toString(); } WhatsAppMessage();  WhatsAppMessage(Cursor c); }
WhatsAppMessage implements Comparable<WhatsAppMessage> { static String filterPrivateBlock(String s) { if (s == null) return null; final StringBuilder sb = new StringBuilder(); for (int i=0; i<s.length(); ) { int codepoint = s.codePointAt(i); Character.UnicodeBlock block = Character.UnicodeBlock.of(codepoint); if (block != Character.UnicodeBlock.PRIVATE_USE_AREA) { sb.append(Character.toChars(codepoint)); } i += Character.charCount(codepoint); } return sb.toString(); } WhatsAppMessage();  WhatsAppMessage(Cursor c); long getId(); boolean isReceived(); Date getTimestamp(); String getText(); String getFilteredText(); int getStatus(); double getLongitude(); double getLatitude(); int getRecipientCount(); String getNumber(); Media getMedia(); Receipt getReceipt(); boolean hasMediaAttached(); boolean hasText(); @Override String toString(); @Override int compareTo(WhatsAppMessage another); boolean isDirectMessage(); boolean isGroupMessage(); }
WhatsAppMessage implements Comparable<WhatsAppMessage> { static String filterPrivateBlock(String s) { if (s == null) return null; final StringBuilder sb = new StringBuilder(); for (int i=0; i<s.length(); ) { int codepoint = s.codePointAt(i); Character.UnicodeBlock block = Character.UnicodeBlock.of(codepoint); if (block != Character.UnicodeBlock.PRIVATE_USE_AREA) { sb.append(Character.toChars(codepoint)); } i += Character.charCount(codepoint); } return sb.toString(); } WhatsAppMessage();  WhatsAppMessage(Cursor c); long getId(); boolean isReceived(); Date getTimestamp(); String getText(); String getFilteredText(); int getStatus(); double getLongitude(); double getLatitude(); int getRecipientCount(); String getNumber(); Media getMedia(); Receipt getReceipt(); boolean hasMediaAttached(); boolean hasText(); @Override String toString(); @Override int compareTo(WhatsAppMessage another); boolean isDirectMessage(); boolean isGroupMessage(); static final String TABLE; static final String GROUP; static final String DIRECT; }