package o;

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

    public C0860bv(C0977d7 c0977d7, long j) {
        String str = c0977d7.m;
        C0862bw c0862bw = new C0862bw();
        c0862bw.d = str;
        c0862bw.b = -1;
        c0862bw.c = -1;
        this.a = c0862bw;
        this.b = Ue0.f(j);
        this.c = Ue0.e(j);
        this.d = -1;
        this.e = -1;
        int iF = Ue0.f(j);
        int iE = Ue0.e(j);
        if (iF < 0 || iF > str.length()) {
            StringBuilder sbO = AbstractC0126Ew.o(iF, "start (", ") offset is outside of text region ");
            sbO.append(str.length());
            throw new IndexOutOfBoundsException(sbO.toString());
        }
        if (iE < 0 || iE > str.length()) {
            StringBuilder sbO2 = AbstractC0126Ew.o(iE, "end (", ") offset is outside of text region ");
            sbO2.append(str.length());
            throw new IndexOutOfBoundsException(sbO2.toString());
        }
        if (iF > iE) {
            throw new IllegalArgumentException(AbstractC0126Ew.i(iF, iE, "Do not set reversed range: ", " > "));
        }
    }

    public final void a(int i, int i2) {
        long jU = AbstractC2378rs0.u(i, i2);
        this.a.k(i, "", i2);
        long jI0 = AbstractC0752ap.i0(AbstractC2378rs0.u(this.b, this.c), jU);
        h(Ue0.f(jI0));
        g(Ue0.e(jI0));
        int i3 = this.d;
        if (i3 != -1) {
            long jI02 = AbstractC0752ap.i0(AbstractC2378rs0.u(i3, this.e), jU);
            if (Ue0.c(jI02)) {
                this.d = -1;
                this.e = -1;
            } else {
                this.d = Ue0.f(jI02);
                this.e = Ue0.e(jI02);
            }
        }
    }

    public final char b(int i) {
        C0862bw c0862bw = this.a;
        C2642ui c2642ui = (C2642ui) c0862bw.e;
        if (c2642ui == null) {
            return ((String) c0862bw.d).charAt(i);
        }
        if (i < c0862bw.b) {
            return ((String) c0862bw.d).charAt(i);
        }
        int iD = c2642ui.b - c2642ui.d();
        int i2 = c0862bw.b;
        if (i >= iD + i2) {
            return ((String) c0862bw.d).charAt(i - ((iD - c0862bw.c) + i2));
        }
        int i3 = i - i2;
        int i4 = c2642ui.c;
        return i3 < i4 ? ((char[]) c2642ui.e)[i3] : ((char[]) c2642ui.e)[(i3 - i4) + c2642ui.d];
    }

    public final Ue0 c() {
        int i = this.d;
        if (i != -1) {
            return new Ue0(AbstractC2378rs0.u(i, this.e));
        }
        return null;
    }

    public final void d(int i, String str, int i2) {
        C0862bw c0862bw = this.a;
        if (i < 0 || i > c0862bw.b()) {
            StringBuilder sbO = AbstractC0126Ew.o(i, "start (", ") offset is outside of text region ");
            sbO.append(c0862bw.b());
            throw new IndexOutOfBoundsException(sbO.toString());
        }
        if (i2 < 0 || i2 > c0862bw.b()) {
            StringBuilder sbO2 = AbstractC0126Ew.o(i2, "end (", ") offset is outside of text region ");
            sbO2.append(c0862bw.b());
            throw new IndexOutOfBoundsException(sbO2.toString());
        }
        if (i > i2) {
            throw new IllegalArgumentException(AbstractC0126Ew.i(i, i2, "Do not set reversed range: ", " > "));
        }
        c0862bw.k(i, str, i2);
        h(str.length() + i);
        g(str.length() + i);
        this.d = -1;
        this.e = -1;
    }

    public final void e(int i, int i2) {
        C0862bw c0862bw = this.a;
        if (i < 0 || i > c0862bw.b()) {
            StringBuilder sbO = AbstractC0126Ew.o(i, "start (", ") offset is outside of text region ");
            sbO.append(c0862bw.b());
            throw new IndexOutOfBoundsException(sbO.toString());
        }
        if (i2 < 0 || i2 > c0862bw.b()) {
            StringBuilder sbO2 = AbstractC0126Ew.o(i2, "end (", ") offset is outside of text region ");
            sbO2.append(c0862bw.b());
            throw new IndexOutOfBoundsException(sbO2.toString());
        }
        if (i >= i2) {
            throw new IllegalArgumentException(AbstractC0126Ew.i(i, i2, "Do not set reversed or empty range: ", " > "));
        }
        this.d = i;
        this.e = i2;
    }

    public final void f(int i, int i2) {
        C0862bw c0862bw = this.a;
        if (i < 0 || i > c0862bw.b()) {
            StringBuilder sbO = AbstractC0126Ew.o(i, "start (", ") offset is outside of text region ");
            sbO.append(c0862bw.b());
            throw new IndexOutOfBoundsException(sbO.toString());
        }
        if (i2 < 0 || i2 > c0862bw.b()) {
            StringBuilder sbO2 = AbstractC0126Ew.o(i2, "end (", ") offset is outside of text region ");
            sbO2.append(c0862bw.b());
            throw new IndexOutOfBoundsException(sbO2.toString());
        }
        if (i > i2) {
            throw new IllegalArgumentException(AbstractC0126Ew.i(i, i2, "Do not set reversed range: ", " > "));
        }
        h(i);
        g(i2);
    }

    public final void g(int i) {
        if (!(i >= 0)) {
            AbstractC2228qH.a("Cannot set selectionEnd to a negative value: " + i);
        }
        this.c = i;
    }

    public final void h(int i) {
        if (!(i >= 0)) {
            AbstractC2228qH.a("Cannot set selectionStart to a negative value: " + i);
        }
        this.b = i;
    }

    public final String toString() {
        return this.a.toString();
    }
}
