package p4;

import F1.C0186o;
import I2.C0334s;
import java.util.ArrayList;
import java.util.Arrays;
import p5.C2740j;
import p5.C2743m;
import x5.v;

/* JADX INFO: renamed from: p4.d, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public final class C2725d {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public int f23010a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f23011b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f23012c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Cloneable f23013d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public Object f23014e;

    public C2725d(ArrayList arrayList) {
        this.f23014e = new y5.b("", null);
        this.f23012c = 0;
        this.f23013d = arrayList;
        this.f23010a = 0;
        this.f23011b = 0;
        if (arrayList.isEmpty()) {
            return;
        }
        a(0, 0);
        y5.b bVar = (y5.b) arrayList.get(0);
        this.f23014e = bVar;
        this.f23012c = bVar.f26238a.length();
    }

    public void a(int i6, int i7) {
        ArrayList arrayList = (ArrayList) this.f23013d;
        if (i6 < 0 || i6 >= arrayList.size()) {
            StringBuilder sbR = com.google.android.recaptcha.internal.a.r(i6, "Line index ", " out of range, number of lines: ");
            sbR.append(arrayList.size());
            throw new IllegalArgumentException(sbR.toString());
        }
        y5.b bVar = (y5.b) arrayList.get(i6);
        if (i7 < 0 || i7 > bVar.f26238a.length()) {
            StringBuilder sbR2 = com.google.android.recaptcha.internal.a.r(i7, "Index ", " out of range, line length: ");
            sbR2.append(bVar.f26238a.length());
            throw new IllegalArgumentException(sbR2.toString());
        }
    }

    public int b(char c6) {
        int i6 = 0;
        while (true) {
            char cK = k();
            if (cK == 0) {
                return -1;
            }
            if (cK == c6) {
                return i6;
            }
            i6++;
            h();
        }
    }

    public C0334s c(C0186o c0186o, C0186o c0186o2) {
        v vVar;
        ArrayList arrayList = (ArrayList) this.f23013d;
        int i6 = c0186o.f1462a;
        int i7 = c0186o2.f1462a;
        int i8 = c0186o.f1463b;
        int i9 = c0186o2.f1463b;
        if (i6 == i7) {
            y5.b bVar = (y5.b) arrayList.get(i6);
            CharSequence charSequenceSubSequence = bVar.f26238a.subSequence(i8, i9);
            v vVar2 = bVar.f26239b;
            if (vVar2 != null) {
                vVar = new v(vVar2.f26089a, vVar2.f26090b + i8, charSequenceSubSequence.length());
            } else {
                vVar = null;
            }
            y5.b bVar2 = new y5.b(charSequenceSubSequence, vVar);
            C0334s c0334s = new C0334s(8, (byte) 0);
            c0334s.f2658b.add(bVar2);
            return c0334s;
        }
        C0334s c0334s2 = new C0334s(8, (byte) 0);
        y5.b bVar3 = (y5.b) arrayList.get(i6);
        y5.b bVarA = bVar3.a(i8, bVar3.f26238a.length());
        ArrayList arrayList2 = c0334s2.f2658b;
        arrayList2.add(bVarA);
        while (true) {
            i6++;
            if (i6 >= i7) {
                arrayList2.add(((y5.b) arrayList.get(i7)).a(0, i9));
                return c0334s2;
            }
            arrayList2.add((y5.b) arrayList.get(i6));
        }
    }

    public boolean d() {
        return this.f23011b < this.f23012c || this.f23010a < ((ArrayList) this.f23013d).size() - 1;
    }

    public void e(C2723b c2723b) {
        int i6;
        int i7 = c2723b.f23001c;
        if (i7 > 4096) {
            Arrays.fill((C2723b[]) this.f23014e, (Object) null);
            this.f23011b = ((C2723b[]) this.f23014e).length - 1;
            this.f23010a = 0;
            this.f23012c = 0;
            return;
        }
        int i8 = (this.f23012c + i7) - 4096;
        if (i8 > 0) {
            int length = ((C2723b[]) this.f23014e).length - 1;
            int i9 = 0;
            while (true) {
                i6 = this.f23011b;
                if (length < i6 || i8 <= 0) {
                    break;
                }
                int i10 = ((C2723b[]) this.f23014e)[length].f23001c;
                i8 -= i10;
                this.f23012c -= i10;
                this.f23010a--;
                i9++;
                length--;
            }
            C2723b[] c2723bArr = (C2723b[]) this.f23014e;
            int i11 = i6 + 1;
            System.arraycopy(c2723bArr, i11, c2723bArr, i11 + i9, this.f23010a);
            this.f23011b += i9;
        }
        int i12 = this.f23010a + 1;
        C2723b[] c2723bArr2 = (C2723b[]) this.f23014e;
        if (i12 > c2723bArr2.length) {
            C2723b[] c2723bArr3 = new C2723b[c2723bArr2.length * 2];
            System.arraycopy(c2723bArr2, 0, c2723bArr3, c2723bArr2.length, c2723bArr2.length);
            this.f23011b = ((C2723b[]) this.f23014e).length - 1;
            this.f23014e = c2723bArr3;
        }
        int i13 = this.f23011b;
        this.f23011b = i13 - 1;
        ((C2723b[]) this.f23014e)[i13] = c2723b;
        this.f23010a++;
        this.f23012c += i7;
    }

    public int f(w5.a aVar) {
        int i6 = 0;
        while (aVar.f25491a.get(k())) {
            i6++;
            h();
        }
        return i6;
    }

    public int g(char c6) {
        int i6 = 0;
        while (k() == c6) {
            i6++;
            h();
        }
        return i6;
    }

    public void h() {
        int i6 = this.f23011b + 1;
        this.f23011b = i6;
        if (i6 > this.f23012c) {
            int i7 = this.f23010a + 1;
            this.f23010a = i7;
            ArrayList arrayList = (ArrayList) this.f23013d;
            if (i7 < arrayList.size()) {
                y5.b bVar = (y5.b) arrayList.get(this.f23010a);
                this.f23014e = bVar;
                this.f23012c = bVar.f26238a.length();
            } else {
                this.f23014e = new y5.b("", null);
                this.f23012c = "".length();
            }
            this.f23011b = 0;
        }
    }

    public boolean i(char c6) {
        if (k() != c6) {
            return false;
        }
        h();
        return true;
    }

    public boolean j(String str) {
        int i6 = this.f23011b;
        if (i6 < this.f23012c && str.length() + i6 <= this.f23012c) {
            for (int i7 = 0; i7 < str.length(); i7++) {
                if (((y5.b) this.f23014e).f26238a.charAt(this.f23011b + i7) == str.charAt(i7)) {
                }
            }
            this.f23011b = str.length() + this.f23011b;
            return true;
        }
        return false;
    }

    public char k() {
        int i6 = this.f23011b;
        return i6 < this.f23012c ? ((y5.b) this.f23014e).f26238a.charAt(i6) : this.f23010a < ((ArrayList) this.f23013d).size() + (-1) ? '\n' : (char) 0;
    }

    public C0186o l() {
        return new C0186o(this.f23010a, this.f23011b);
    }

    public void m(C0186o c0186o) {
        int i6 = c0186o.f1462a;
        int i7 = c0186o.f1463b;
        a(i6, i7);
        this.f23010a = i6;
        this.f23011b = i7;
        y5.b bVar = (y5.b) ((ArrayList) this.f23013d).get(i6);
        this.f23014e = bVar;
        this.f23012c = bVar.f26238a.length();
    }

    public int n() {
        int i6 = 0;
        while (true) {
            char cK = k();
            if (cK != ' ') {
                switch (cK) {
                    case '\t':
                    case '\n':
                    case 11:
                    case '\f':
                    case '\r':
                        break;
                    default:
                        return i6;
                }
            }
            i6++;
            h();
        }
    }

    public void o(C2743m c2743m) {
        p(c2743m.d(), 127, 0);
        ((C2740j) this.f23013d).N(c2743m);
    }

    public void p(int i6, int i7, int i8) {
        C2740j c2740j = (C2740j) this.f23013d;
        if (i6 < i7) {
            c2740j.Q(i6 | i8);
            return;
        }
        c2740j.Q(i8 | i7);
        int i9 = i6 - i7;
        while (i9 >= 128) {
            c2740j.Q(128 | (i9 & 127));
            i9 >>>= 7;
        }
        c2740j.Q(i9);
    }

    public C2725d(C2740j c2740j) {
        this.f23014e = new C2723b[8];
        this.f23011b = 7;
        this.f23013d = c2740j;
    }
}
