/** * Fix to https://github.com/TwidereProject/Twidere-Android/issues/449 * * @param string */ public static void fixSHY(Spannable string) { for (int i = 0, j = string.length(); i < j; i++) { if (string.charAt(i) == '\u00ad') { string.setSpan(new ZeroWidthSpan(), i, i + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
/** * If a translator has messed up the edges of paragraph-level markup, fix it to actually cover the * entire paragraph that it is attached to instead of just whatever range they put it on. */ private static void addParagraphSpan(Spannable buffer, Object what, int start, int end) { int len = buffer.length(); if (start != 0 && start != len && buffer.charAt(start - 1) != '\n') { for (start--; start > 0; start--) { if (buffer.charAt(start - 1) == '\n') { break; } } } if (end != 0 && end != len && buffer.charAt(end - 1) != '\n') { for (end++; end < len; end++) { if (buffer.charAt(end - 1) == '\n') { break; } } } buffer.setSpan(what, start, end, Spannable.SPAN_PARAGRAPH); }
public static CharSequence rot13(final Spannable span) { // I needed to re-implement the rot13(String) encryption here because we must work on // a SpannableStringBuilder instead of the pure text and we must replace each character inline. // Otherwise we loose all the images, colors and so on... final SpannableStringBuilder buffer = new SpannableStringBuilder(span); Rot13Encryption rot13 = new Rot13Encryption(); final int length = span.length(); for (int index = 0; index < length; index++) { char c = span.charAt(index); buffer.replace(index, index + 1, String.valueOf(rot13.getNextEncryptedCharacter(c))); } return buffer; }
private static void addUnprintable(Spannable spannable, int start, int end, int color) { for (int i = start; i < end; ++i) { ReplacementSpan span = null; char c = spannable.charAt(i); if (c == '\r' || c == '\n' || c == '\t') { // do nothing } else if (c >= 0x00 && (c - 0x00) < C0.length) { span = new UnprintableSpan(C0[c - 0x00], color); } else if (c >= 0x80 && (c - 0x80) < C1.length) { span = new UnprintableSpan(C1[c - 0x80], color); } // else if (Character.isISOControl(c)) // { // span = new UnprintableSpan('u' + Integer.toString(c, 16), color); // } if (span != null) { // Log.d(TAG, " span " + i + " " + (int)c); spannable.setSpan(span, i, i + 1, android.text.Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }