package androidx.compose.ui.platform;

import java.text.BreakIterator;
import java.util.Locale;

/* loaded from: classes.dex */
public final class h extends b {

    /* renamed from: d, reason: collision with root package name */
    public static final a f2442d = new a(null);

    /* renamed from: e, reason: collision with root package name */
    public static final int f2443e = 8;

    /* renamed from: f, reason: collision with root package name */
    private static h f2444f;

    /* renamed from: c, reason: collision with root package name */
    private BreakIterator f2445c;

    /* loaded from: classes.dex */
    public static final class a {
        private a() {
        }

        public /* synthetic */ a(kotlin.jvm.internal.k kVar) {
            this();
        }

        public final h a(Locale locale) {
            if (h.f2444f == null) {
                h.f2444f = new h(locale, null);
            }
            h hVar = h.f2444f;
            kotlin.jvm.internal.t.e(hVar, "null cannot be cast to non-null type androidx.compose.ui.platform.AccessibilityIterators.WordTextSegmentIterator");
            return hVar;
        }
    }

    public /* synthetic */ h(Locale locale, kotlin.jvm.internal.k kVar) {
        this(locale);
    }

    private final boolean i(int i10) {
        return i10 > 0 && j(i10 + (-1)) && (i10 == d().length() || !j(i10));
    }

    private final boolean j(int i10) {
        if (i10 < 0 || i10 >= d().length()) {
            return false;
        }
        return Character.isLetterOrDigit(d().codePointAt(i10));
    }

    private final boolean k(int i10) {
        return j(i10) && (i10 == 0 || !j(i10 - 1));
    }

    private final void l(Locale locale) {
        this.f2445c = BreakIterator.getWordInstance(locale);
    }

    @Override // androidx.compose.ui.platform.g
    public int[] a(int i10) {
        if (d().length() <= 0 || i10 >= d().length()) {
            return null;
        }
        if (i10 < 0) {
            i10 = 0;
        }
        while (!j(i10) && !k(i10)) {
            BreakIterator breakIterator = this.f2445c;
            if (breakIterator == null) {
                kotlin.jvm.internal.t.y("impl");
                breakIterator = null;
            }
            i10 = breakIterator.following(i10);
            if (i10 == -1) {
                return null;
            }
        }
        BreakIterator breakIterator2 = this.f2445c;
        if (breakIterator2 == null) {
            kotlin.jvm.internal.t.y("impl");
            breakIterator2 = null;
        }
        int following = breakIterator2.following(i10);
        if (following == -1 || !i(following)) {
            return null;
        }
        return c(i10, following);
    }

    @Override // androidx.compose.ui.platform.g
    public int[] b(int i10) {
        int length = d().length();
        if (length <= 0 || i10 <= 0) {
            return null;
        }
        if (i10 > length) {
            i10 = length;
        }
        while (i10 > 0 && !j(i10 - 1) && !i(i10)) {
            BreakIterator breakIterator = this.f2445c;
            if (breakIterator == null) {
                kotlin.jvm.internal.t.y("impl");
                breakIterator = null;
            }
            i10 = breakIterator.preceding(i10);
            if (i10 == -1) {
                return null;
            }
        }
        BreakIterator breakIterator2 = this.f2445c;
        if (breakIterator2 == null) {
            kotlin.jvm.internal.t.y("impl");
            breakIterator2 = null;
        }
        int preceding = breakIterator2.preceding(i10);
        if (preceding == -1 || !k(preceding)) {
            return null;
        }
        return c(preceding, i10);
    }

    @Override // androidx.compose.ui.platform.b
    public void e(String str) {
        super.e(str);
        BreakIterator breakIterator = this.f2445c;
        if (breakIterator == null) {
            kotlin.jvm.internal.t.y("impl");
            breakIterator = null;
        }
        breakIterator.setText(str);
    }

    private h(Locale locale) {
        l(locale);
    }
}
