Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 230e3bed authored by Roozbeh Pournader's avatar Roozbeh Pournader Committed by android-build-merger
Browse files

Merge "Don't crash in TextUtil.concat() with paragraph spans" into oc-dev

am: 4972daf9

Change-Id: I8e24a7b278150bbb8b1e4b629f1d3473a732e7b9
parents 0af6d805 4972daf9
Loading
Loading
Loading
Loading
+28 −22
Original line number Original line Diff line number Diff line
@@ -1520,6 +1520,18 @@ public class TextUtils {
    /**
    /**
     * Returns a CharSequence concatenating the specified CharSequences,
     * Returns a CharSequence concatenating the specified CharSequences,
     * retaining their spans if any.
     * retaining their spans if any.
     *
     * If there are no parameters, an empty string will be returned.
     *
     * If the number of parameters is exactly one, that parameter is returned as output, even if it
     * is null.
     *
     * If the number of parameters is at least two, any null CharSequence among the parameters is
     * treated as if it was the string <code>"null"</code>.
     *
     * If there are paragraph spans in the source CharSequences that satisfy paragraph boundary
     * requirements in the sources but would no longer satisfy them in the concatenated
     * CharSequence, they may get extended in the resulting CharSequence or not retained.
     */
     */
    public static CharSequence concat(CharSequence... text) {
    public static CharSequence concat(CharSequence... text) {
        if (text.length == 0) {
        if (text.length == 0) {
@@ -1531,35 +1543,29 @@ public class TextUtils {
        }
        }


        boolean spanned = false;
        boolean spanned = false;
        for (int i = 0; i < text.length; i++) {
        for (CharSequence piece : text) {
            if (text[i] instanceof Spanned) {
            if (piece instanceof Spanned) {
                spanned = true;
                spanned = true;
                break;
                break;
            }
            }
        }
        }


        StringBuilder sb = new StringBuilder();
        if (spanned) {
        for (int i = 0; i < text.length; i++) {
            final SpannableStringBuilder ssb = new SpannableStringBuilder();
            sb.append(text[i]);
            for (CharSequence piece : text) {
        }
                // If a piece is null, we append the string "null" for compatibility with the

                // behavior of StringBuilder and the behavior of the concat() method in earlier
        if (!spanned) {
                // versions of Android.
            return sb.toString();
                ssb.append(piece == null ? "null" : piece);
            }
            }

            return new SpannedString(ssb);
        SpannableString ss = new SpannableString(sb);
        } else {
        int off = 0;
            final StringBuilder sb = new StringBuilder();
        for (int i = 0; i < text.length; i++) {
            for (CharSequence piece : text) {
            int len = text[i].length();
                sb.append(piece);

            if (text[i] instanceof Spanned) {
                copySpansFrom((Spanned) text[i], 0, len, Object.class, ss, off);
            }
            }

            return sb.toString();
            off += len;
        }
        }

        return new SpannedString(ss);
    }
    }


    /**
    /**