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

Commit b68d147b authored by Raph Levien's avatar Raph Levien
Browse files

Allow null string to BidiFormatter#unicodeWrap

The BidiFormatter#unicodeWrap() methods allow null string, but the
toString() call on the result in the refactored code was crashing.
Also adds @Nullable annotations.

Bug: 27124532
Change-Id: I25922d104587af4a850c3640987af9315c3d3bde
parent ab9651b9
Loading
Loading
Loading
Loading
+6 −2
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package android.text;
package android.text;


import android.annotation.Nullable;
import android.view.View;
import android.view.View;


import static android.text.TextDirectionHeuristics.FIRSTSTRONG_LTR;
import static android.text.TextDirectionHeuristics.FIRSTSTRONG_LTR;
@@ -390,14 +391,17 @@ public final class BidiFormatter {
     * @return Input string after applying the above processing. {@code null} if {@code str} is
     * @return Input string after applying the above processing. {@code null} if {@code str} is
     *     {@code null}.
     *     {@code null}.
     */
     */
    public String unicodeWrap(String str, TextDirectionHeuristic heuristic, boolean isolate) {
    public @Nullable String unicodeWrap(@Nullable String str, TextDirectionHeuristic heuristic,
            boolean isolate) {
        if (str == null) return null;
        return unicodeWrap((CharSequence) str, heuristic, isolate).toString();
        return unicodeWrap((CharSequence) str, heuristic, isolate).toString();
    }
    }


    /**
    /**
     * @hide
     * @hide
     */
     */
    public CharSequence unicodeWrap(CharSequence str, TextDirectionHeuristic heuristic, boolean isolate) {
    public @Nullable CharSequence unicodeWrap(@Nullable CharSequence str,
            TextDirectionHeuristic heuristic, boolean isolate) {
        if (str == null) return null;
        if (str == null) return null;
        final boolean isRtl = heuristic.isRtl(str, 0, str.length());
        final boolean isRtl = heuristic.isRtl(str, 0, str.length());
        SpannableStringBuilder result = new SpannableStringBuilder();
        SpannableStringBuilder result = new SpannableStringBuilder();