package o;

import android.content.res.TypedArray;
import android.util.SparseArray;
import java.lang.Character;
import java.text.BreakIterator;
import java.util.Locale;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.bw, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C0862bw {
    public final /* synthetic */ int a;
    public int b;
    public int c;
    public Object d;
    public Object e;

    public /* synthetic */ C0862bw() {
        this.a = 1;
    }

    public void a(int i) {
        int i2 = this.b;
        int i3 = this.c;
        boolean z = false;
        if (i <= i3 && i2 <= i) {
            z = true;
        }
        if (z) {
            return;
        }
        AbstractC2228qH.a("Invalid offset: " + i + ". Valid range is [" + i2 + " , " + i3 + ']');
    }

    public int b() {
        C2642ui c2642ui = (C2642ui) this.e;
        if (c2642ui == null) {
            return ((String) this.d).length();
        }
        return (c2642ui.b - c2642ui.d()) + (((String) this.d).length() - (this.c - this.b));
    }

    public boolean c(int i) {
        CharSequence charSequence = (CharSequence) this.d;
        int i2 = this.b + 1;
        if (i > this.c || i2 > i) {
            return false;
        }
        if (!Character.isLetterOrDigit(Character.codePointBefore(charSequence, i))) {
            int i3 = i - 1;
            if (!Character.isSurrogate(charSequence.charAt(i3))) {
                if (!C2004nv.d()) {
                    return false;
                }
                C2004nv c2004nvA = C2004nv.a();
                if (c2004nvA.c() != 1 || c2004nvA.b(charSequence, i3) == -1) {
                    return false;
                }
            }
        }
        return true;
    }

    public boolean d(int i) {
        int i2 = this.b + 1;
        if (i > this.c || i2 > i) {
            return false;
        }
        return AbstractC0249Jp.P(Character.codePointBefore((CharSequence) this.d, i));
    }

    public boolean e(int i) {
        a(i);
        if (!((BreakIterator) this.e).isBoundary(i)) {
            return false;
        }
        if (g(i) && g(i - 1) && g(i + 1)) {
            return false;
        }
        return i <= 0 || i >= ((CharSequence) this.d).length() - 1 || !(f(i) || f(i + 1));
    }

    public boolean f(int i) {
        CharSequence charSequence = (CharSequence) this.d;
        int i2 = i - 1;
        Character.UnicodeBlock unicodeBlockOf = Character.UnicodeBlock.of(charSequence.charAt(i2));
        Character.UnicodeBlock unicodeBlock = Character.UnicodeBlock.HIRAGANA;
        if (F3.c(unicodeBlockOf, unicodeBlock) && F3.c(Character.UnicodeBlock.of(charSequence.charAt(i)), Character.UnicodeBlock.KATAKANA)) {
            return true;
        }
        return F3.c(Character.UnicodeBlock.of(charSequence.charAt(i)), unicodeBlock) && F3.c(Character.UnicodeBlock.of(charSequence.charAt(i2)), Character.UnicodeBlock.KATAKANA);
    }

    public boolean g(int i) {
        CharSequence charSequence = (CharSequence) this.d;
        int i2 = this.b;
        if (i >= this.c || i2 > i) {
            return false;
        }
        if (!Character.isLetterOrDigit(Character.codePointAt(charSequence, i)) && !Character.isSurrogate(charSequence.charAt(i))) {
            if (!C2004nv.d()) {
                return false;
            }
            C2004nv c2004nvA = C2004nv.a();
            if (c2004nvA.c() != 1 || c2004nvA.b(charSequence, i) == -1) {
                return false;
            }
        }
        return true;
    }

    public boolean h(int i) {
        int i2 = this.b;
        if (i >= this.c || i2 > i) {
            return false;
        }
        return AbstractC0249Jp.P(Character.codePointAt((CharSequence) this.d, i));
    }

    public int i(int i) {
        a(i);
        int iFollowing = ((BreakIterator) this.e).following(i);
        return (g(iFollowing + (-1)) && g(iFollowing) && !f(iFollowing)) ? i(iFollowing) : iFollowing;
    }

    public int j(int i) {
        a(i);
        int iPreceding = ((BreakIterator) this.e).preceding(i);
        return (g(iPreceding) && c(iPreceding) && !f(iPreceding)) ? j(iPreceding) : iPreceding;
    }

    public void k(int i, String str, int i2) {
        if (i > i2) {
            AbstractC2228qH.a("start index must be less than or equal to end index: " + i + " > " + i2);
        }
        if (i < 0) {
            AbstractC2228qH.a("start must be non-negative, but was " + i);
        }
        C2642ui c2642ui = (C2642ui) this.e;
        if (c2642ui == null) {
            int iMax = Math.max(255, str.length() + 128);
            char[] cArr = new char[iMax];
            int iMin = Math.min(i, 64);
            int iMin2 = Math.min(((String) this.d).length() - i2, 64);
            int i3 = i - iMin;
            ((String) this.d).getChars(i3, i, cArr, 0);
            int i4 = iMax - iMin2;
            int i5 = iMin2 + i2;
            ((String) this.d).getChars(i2, i5, cArr, i4);
            str.getChars(0, str.length(), cArr, iMin);
            int length = str.length() + iMin;
            C2642ui c2642ui2 = new C2642ui(1);
            c2642ui2.b = iMax;
            c2642ui2.e = cArr;
            c2642ui2.c = length;
            c2642ui2.d = i4;
            this.e = c2642ui2;
            this.b = i3;
            this.c = i5;
            return;
        }
        int i6 = this.b;
        int i7 = i - i6;
        int i8 = i2 - i6;
        if (i7 < 0 || i8 > c2642ui.b - c2642ui.d()) {
            this.d = toString();
            this.e = null;
            this.b = -1;
            this.c = -1;
            k(i, str, i2);
            return;
        }
        int length2 = str.length() - (i8 - i7);
        if (length2 > c2642ui.d()) {
            int iD = length2 - c2642ui.d();
            int i9 = c2642ui.b;
            do {
                i9 *= 2;
            } while (i9 - c2642ui.b < iD);
            char[] cArr2 = new char[i9];
            System.arraycopy((char[]) c2642ui.e, 0, cArr2, 0, c2642ui.c);
            int i10 = c2642ui.b;
            int i11 = c2642ui.d;
            int i12 = i10 - i11;
            int i13 = i9 - i12;
            System.arraycopy((char[]) c2642ui.e, i11, cArr2, i13, (i12 + i11) - i11);
            c2642ui.e = cArr2;
            c2642ui.b = i9;
            c2642ui.d = i13;
        }
        int i14 = c2642ui.c;
        if (i7 < i14 && i8 <= i14) {
            int i15 = i14 - i8;
            char[] cArr3 = (char[]) c2642ui.e;
            System.arraycopy(cArr3, i8, cArr3, c2642ui.d - i15, i15);
            c2642ui.c = i7;
            c2642ui.d -= i15;
        } else if (i7 >= i14 || i8 < i14) {
            int iD2 = c2642ui.d() + i7;
            int iD3 = c2642ui.d() + i8;
            int i16 = c2642ui.d;
            int i17 = iD2 - i16;
            char[] cArr4 = (char[]) c2642ui.e;
            System.arraycopy(cArr4, i16, cArr4, c2642ui.c, i17);
            c2642ui.c += i17;
            c2642ui.d = iD3;
        } else {
            c2642ui.d = c2642ui.d() + i8;
            c2642ui.c = i7;
        }
        str.getChars(0, str.length(), (char[]) c2642ui.e, c2642ui.c);
        c2642ui.c = str.length() + c2642ui.c;
    }

    public String toString() {
        switch (this.a) {
            case 1:
                C2642ui c2642ui = (C2642ui) this.e;
                if (c2642ui == null) {
                    return (String) this.d;
                }
                StringBuilder sb = new StringBuilder();
                sb.append((CharSequence) this.d, 0, this.b);
                sb.append((char[]) c2642ui.e, 0, c2642ui.c);
                char[] cArr = (char[]) c2642ui.e;
                int i = c2642ui.d;
                sb.append(cArr, i, c2642ui.b - i);
                String str = (String) this.d;
                sb.append((CharSequence) str, this.c, str.length());
                return sb.toString();
            default:
                return super.toString();
        }
    }

    public C0862bw(CharSequence charSequence, int i, Locale locale) {
        this.a = 2;
        this.d = charSequence;
        if (charSequence.length() < 0) {
            AbstractC2228qH.a("input start index is outside the CharSequence");
        }
        if (i < 0 || i > charSequence.length()) {
            AbstractC2228qH.a("input end index is outside the CharSequence");
        }
        BreakIterator wordInstance = BreakIterator.getWordInstance(locale);
        this.e = wordInstance;
        this.b = Math.max(0, -50);
        this.c = Math.min(charSequence.length(), i + 50);
        wordInstance.setText(new C2261qh(charSequence, i));
    }

    public C0862bw(C0957cw c0957cw, C70 c70) {
        this.a = 0;
        this.d = new SparseArray();
        this.e = c0957cw;
        TypedArray typedArray = (TypedArray) c70.n;
        this.b = typedArray.getResourceId(28, 0);
        this.c = typedArray.getResourceId(52, 0);
    }
}
