package w2;

import com.google.firebase.perf.util.Constants;

/* loaded from: classes.dex */
public final class i0 {

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

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

    /* renamed from: a, reason: collision with root package name */
    private String f40765a;

    /* renamed from: b, reason: collision with root package name */
    private o f40766b;

    /* renamed from: c, reason: collision with root package name */
    private int f40767c = -1;

    /* renamed from: d, reason: collision with root package name */
    private int f40768d = -1;

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

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

    public i0(String str) {
        this.f40765a = str;
    }

    public final char a(int i10) {
        o oVar = this.f40766b;
        if (oVar != null && i10 >= this.f40767c) {
            int e10 = oVar.e();
            int i11 = this.f40767c;
            return i10 < e10 + i11 ? oVar.d(i10 - i11) : this.f40765a.charAt(i10 - ((e10 - this.f40768d) + i11));
        }
        return this.f40765a.charAt(i10);
    }

    public final int b() {
        o oVar = this.f40766b;
        return oVar == null ? this.f40765a.length() : (this.f40765a.length() - (this.f40768d - this.f40767c)) + oVar.e();
    }

    public final void c(int i10, int i11, String str) {
        if (!(i10 <= i11)) {
            throw new IllegalArgumentException(("start index must be less than or equal to end index: " + i10 + " > " + i11).toString());
        }
        if (!(i10 >= 0)) {
            throw new IllegalArgumentException(("start must be non-negative, but was " + i10).toString());
        }
        o oVar = this.f40766b;
        if (oVar != null) {
            int i12 = this.f40767c;
            int i13 = i10 - i12;
            int i14 = i11 - i12;
            if (i13 >= 0 && i14 <= oVar.e()) {
                oVar.g(i13, i14, str);
                return;
            }
            this.f40765a = toString();
            this.f40766b = null;
            this.f40767c = -1;
            this.f40768d = -1;
            c(i10, i11, str);
            return;
        }
        int max = Math.max(Constants.MAX_HOST_LENGTH, str.length() + 128);
        char[] cArr = new char[max];
        int min = Math.min(i10, 64);
        int min2 = Math.min(this.f40765a.length() - i11, 64);
        int i15 = i10 - min;
        q.a(this.f40765a, cArr, 0, i15, i10);
        int i16 = max - min2;
        int i17 = min2 + i11;
        q.a(this.f40765a, cArr, i16, i11, i17);
        p.b(str, cArr, min);
        this.f40766b = new o(cArr, min + str.length(), i16);
        this.f40767c = i15;
        this.f40768d = i17;
    }

    public String toString() {
        o oVar = this.f40766b;
        if (oVar == null) {
            return this.f40765a;
        }
        StringBuilder sb2 = new StringBuilder();
        sb2.append((CharSequence) this.f40765a, 0, this.f40767c);
        oVar.a(sb2);
        String str = this.f40765a;
        sb2.append((CharSequence) str, this.f40768d, str.length());
        return sb2.toString();
    }
}
