Helper { public static String removeNonPrintableChars(@Nullable final String s) { if (null == s || s.isEmpty()) return ""; StringBuilder newString = new StringBuilder(s.length()); for (int offset = 0; offset < s.length(); ) { int codePoint = s.codePointAt(offset); offset += Character.charCount(codePoint); switch (Character.getType(codePoint)) { case Character.CONTROL: case Character.FORMAT: case Character.PRIVATE_USE: case Character.SURROGATE: case Character.UNASSIGNED: break; default: newString.append(Character.toChars(codePoint)); break; } } return newString.toString(); } private  Helper(); static String capitalizeString(String s); static String formatIntAsStr(int value, int length); static String decode64(String encodedString); static String encode64(String rawString); static int dpToPixel(@NonNull final Context context, int dp); static List<Long> getListFromPrimitiveArray(long[] input); static List<Integer> getListFromPrimitiveArray(int[] input); static long[] getPrimitiveLongArrayFromList(List<Long> integers); static boolean isNumeric(String str); static float coerceIn(float value, float min, float max); static List<InputStream> duplicateInputStream(@Nonnull InputStream stream, int numberDuplicates); static boolean copyPlainTextToClipboard(@NonNull Context context, @NonNull String text); static String removeNonPrintableChars(@Nullable final String s); static String replaceUnicode(@NonNull final String s); static Context getFixedContext(Context context); static int getChromeVersion(Context context); static void assertNonUiThread(); static String formatTime(long ms);  }
@Test public void removeInvisibleChars() { assertEquals("a", Helper.removeNonPrintableChars("\uF8FFa")); assertEquals("a", Helper.removeNonPrintableChars("\uDC00a")); assertEquals("a", Helper.removeNonPrintableChars("\u000Ea")); assertEquals("a", Helper.removeNonPrintableChars("\u200Ea")); assertEquals("a", Helper.removeNonPrintableChars("\na")); assertEquals(" a", Helper.removeNonPrintableChars(" a")); }