package k.a.q.y;

import java.util.ArrayList;
import okhttp3.HttpUrl;

/* JADX INFO: compiled from: AbstractJsonLexer.kt */
/* JADX INFO: loaded from: classes.dex */
public abstract class a {
    protected int a;
    private String c;
    public final s b = new s();
    private StringBuilder d = new StringBuilder();

    private final int B(CharSequence charSequence, int i2) {
        char cCharAt = charSequence.charAt(i2);
        if ('0' <= cCharAt && cCharAt < ':') {
            return cCharAt - '0';
        }
        char c = 'a';
        if (!('a' <= cCharAt && cCharAt < 'g')) {
            c = 'A';
            if (!('A' <= cCharAt && cCharAt < 'G')) {
                y(this, "Invalid toHexChar char '" + cCharAt + "' in unicode escape", 0, null, 6, null);
                throw null;
            }
        }
        return (cCharAt - c) + 10;
    }

    private final String K() {
        String str = this.c;
        j.p0.d.r.c(str);
        this.c = null;
        return str;
    }

    private final boolean O() {
        return C().charAt(this.a - 1) != '\"';
    }

    private final int b(int i2) {
        int iG = G(i2);
        if (iG == -1) {
            y(this, "Expected escape sequence to continue, got EOF", 0, null, 6, null);
            throw null;
        }
        int i3 = iG + 1;
        char cCharAt = C().charAt(iG);
        if (cCharAt == 'u') {
            return d(C(), i3);
        }
        char cB = b.b(cCharAt);
        if (cB != 0) {
            this.d.append(cB);
            return i3;
        }
        y(this, "Invalid escaped char '" + cCharAt + '\'', 0, null, 6, null);
        throw null;
    }

    private final int c(int i2, int i3) {
        e(i2, i3);
        return b(i3 + 1);
    }

    private final int d(CharSequence charSequence, int i2) {
        int i3 = i2 + 4;
        if (i3 < charSequence.length()) {
            this.d.append((char) ((B(charSequence, i2) << 12) + (B(charSequence, i2 + 1) << 8) + (B(charSequence, i2 + 2) << 4) + B(charSequence, i2 + 3)));
            return i3;
        }
        this.a = i2;
        v();
        if (this.a + 4 < charSequence.length()) {
            return d(charSequence, this.a);
        }
        y(this, "Unexpected EOF during unicode escape", 0, null, 6, null);
        throw null;
    }

    private final boolean h(int i2) {
        int iG = G(i2);
        if (iG >= C().length() || iG == -1) {
            y(this, "EOF", 0, null, 6, null);
            throw null;
        }
        int i3 = iG + 1;
        int iCharAt = C().charAt(iG) | ' ';
        if (iCharAt == 102) {
            j("alse", i3);
            return false;
        }
        if (iCharAt == 116) {
            j("rue", i3);
            return true;
        }
        y(this, "Expected valid boolean literal prefix, but had '" + s() + '\'', 0, null, 6, null);
        throw null;
    }

    private final void j(String str, int i2) {
        if (C().length() - i2 < str.length()) {
            y(this, "Unexpected end of boolean literal", 0, null, 6, null);
            throw null;
        }
        int length = str.length();
        for (int i3 = 0; i3 < length; i3++) {
            if (str.charAt(i3) != (C().charAt(i2 + i3) | ' ')) {
                y(this, "Expected valid boolean literal prefix, but had '" + s() + '\'', 0, null, 6, null);
                throw null;
            }
        }
        this.a = i2 + str.length();
    }

    private final String u(int i2, int i3) {
        e(i2, i3);
        String string = this.d.toString();
        j.p0.d.r.e(string, "escapedString.toString()");
        this.d.setLength(0);
        return string;
    }

    public static /* synthetic */ Void y(a aVar, String str, int i2, String str2, int i3, Object obj) {
        if (obj != null) {
            throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: fail");
        }
        if ((i3 & 2) != 0) {
            i2 = aVar.a;
        }
        if ((i3 & 4) != 0) {
            str2 = HttpUrl.FRAGMENT_ENCODE_SET;
        }
        aVar.x(str, i2, str2);
        throw null;
    }

    public final void A(String str) {
        j.p0.d.r.f(str, "key");
        x("Encountered an unknown key '" + str + '\'', j.u0.r.Y(J(0, this.a), str, 0, false, 6, null), "Use 'ignoreUnknownKeys = true' in 'Json {}' builder to ignore unknown keys.");
        throw null;
    }

    protected abstract CharSequence C();

    protected final boolean D(char c) {
        return !(((c == '}' || c == ']') || c == ':') || c == ',');
    }

    public final byte E() {
        CharSequence charSequenceC = C();
        int i2 = this.a;
        while (true) {
            int iG = G(i2);
            if (iG == -1) {
                this.a = iG;
                return (byte) 10;
            }
            char cCharAt = charSequenceC.charAt(iG);
            if (cCharAt != ' ' && cCharAt != '\n' && cCharAt != '\r' && cCharAt != '\t') {
                this.a = iG;
                return b.a(cCharAt);
            }
            i2 = iG + 1;
        }
    }

    public final String F(boolean z) {
        String strQ;
        byte bE = E();
        if (z) {
            if (bE != 1 && bE != 0) {
                return null;
            }
            strQ = s();
        } else {
            if (bE != 1) {
                return null;
            }
            strQ = q();
        }
        this.c = strQ;
        return strQ;
    }

    public abstract int G(int i2);

    public final void H(boolean z) {
        ArrayList arrayList = new ArrayList();
        byte bE = E();
        if (bE != 8 && bE != 6) {
            s();
            return;
        }
        while (true) {
            byte bE2 = E();
            boolean z2 = true;
            if (bE2 != 1) {
                if (bE2 != 8 && bE2 != 6) {
                    z2 = false;
                }
                if (z2) {
                    arrayList.add(Byte.valueOf(bE2));
                } else if (bE2 == 9) {
                    if (((Number) j.k0.m.D(arrayList)).byteValue() != 8) {
                        throw q.e(this.a, "found ] instead of } at path: " + this.b, C());
                    }
                    j.k0.m.v(arrayList);
                } else if (bE2 == 7) {
                    if (((Number) j.k0.m.D(arrayList)).byteValue() != 6) {
                        throw q.e(this.a, "found } instead of ] at path: " + this.b, C());
                    }
                    j.k0.m.v(arrayList);
                } else if (bE2 == 10) {
                    y(this, "Unexpected end of input due to malformed JSON during ignoring unknown keys", 0, null, 6, null);
                    throw null;
                }
                m();
                if (arrayList.size() == 0) {
                    return;
                }
            } else if (z) {
                s();
            } else {
                k();
            }
        }
    }

    public abstract int I();

    public String J(int i2, int i3) {
        return C().subSequence(i2, i3).toString();
    }

    public abstract boolean L();

    public final boolean M() {
        int iG = G(I());
        int length = C().length() - iG;
        if (length < 4 || iG == -1) {
            return true;
        }
        for (int i2 = 0; i2 < 4; i2++) {
            if ("null".charAt(i2) != C().charAt(iG + i2)) {
                return true;
            }
        }
        if (length > 4 && b.a(C().charAt(iG + 4)) == 0) {
            return true;
        }
        this.a = iG + 4;
        return false;
    }

    protected final void N(char c) {
        int i2 = this.a - 1;
        this.a = i2;
        if (i2 >= 0 && c == '\"' && j.p0.d.r.a(s(), "null")) {
            x("Expected string literal but 'null' literal was found", this.a - 4, "Use 'coerceInputValues = true' in 'Json {}` builder to coerce nulls to default values.");
            throw null;
        }
        z(b.a(c));
        throw null;
    }

    protected void e(int i2, int i3) {
        this.d.append(C(), i2, i3);
    }

    public abstract boolean f();

    public final boolean g() {
        return h(I());
    }

    public final boolean i() {
        boolean z;
        int I = I();
        if (I == C().length()) {
            y(this, "EOF", 0, null, 6, null);
            throw null;
        }
        if (C().charAt(I) == '\"') {
            I++;
            z = true;
        } else {
            z = false;
        }
        boolean zH = h(I);
        if (z) {
            if (this.a == C().length()) {
                y(this, "EOF", 0, null, 6, null);
                throw null;
            }
            if (C().charAt(this.a) != '\"') {
                y(this, "Expected closing quotation mark", 0, null, 6, null);
                throw null;
            }
            this.a++;
        }
        return zH;
    }

    public abstract String k();

    public abstract String l(String str, boolean z);

    public abstract byte m();

    public final byte n(byte b) {
        byte bM = m();
        if (bM == b) {
            return bM;
        }
        z(b);
        throw null;
    }

    public abstract void o(char c);

    public final long p() {
        boolean z;
        int iG = G(I());
        if (iG >= C().length() || iG == -1) {
            y(this, "EOF", 0, null, 6, null);
            throw null;
        }
        if (C().charAt(iG) == '\"') {
            iG++;
            if (iG == C().length()) {
                y(this, "EOF", 0, null, 6, null);
                throw null;
            }
            z = true;
        } else {
            z = false;
        }
        int i2 = iG;
        long j2 = 0;
        boolean z2 = true;
        boolean z3 = false;
        while (z2) {
            char cCharAt = C().charAt(i2);
            if (cCharAt != '-') {
                if (b.a(cCharAt) != 0) {
                    break;
                }
                i2++;
                boolean z4 = i2 != C().length();
                int i3 = cCharAt - '0';
                if (!(i3 >= 0 && i3 < 10)) {
                    y(this, "Unexpected symbol '" + cCharAt + "' in numeric literal", 0, null, 6, null);
                    throw null;
                }
                boolean z5 = z4;
                j2 = (j2 * ((long) 10)) - ((long) i3);
                if (j2 > 0) {
                    y(this, "Numeric value overflow", 0, null, 6, null);
                    throw null;
                }
                z2 = z5;
            } else {
                if (i2 != iG) {
                    y(this, "Unexpected symbol '-' in numeric literal", 0, null, 6, null);
                    throw null;
                }
                i2++;
                z3 = true;
            }
        }
        if (iG == i2 || (z3 && iG == i2 - 1)) {
            y(this, "Expected numeric literal", 0, null, 6, null);
            throw null;
        }
        if (z) {
            if (!z2) {
                y(this, "EOF", 0, null, 6, null);
                throw null;
            }
            if (C().charAt(i2) != '\"') {
                y(this, "Expected closing quotation mark", 0, null, 6, null);
                throw null;
            }
            i2++;
        }
        this.a = i2;
        if (z3) {
            return j2;
        }
        if (j2 != Long.MIN_VALUE) {
            return -j2;
        }
        y(this, "Numeric value overflow", 0, null, 6, null);
        throw null;
    }

    public final String q() {
        return this.c != null ? K() : k();
    }

    protected final String r(CharSequence charSequence, int i2, int i3) {
        int iG;
        j.p0.d.r.f(charSequence, "source");
        char cCharAt = charSequence.charAt(i3);
        boolean z = false;
        while (cCharAt != '\"') {
            if (cCharAt == '\\') {
                iG = G(c(i2, i3));
                if (iG == -1) {
                    y(this, "EOF", iG, null, 4, null);
                    throw null;
                }
            } else {
                i3++;
                if (i3 >= charSequence.length()) {
                    e(i2, i3);
                    iG = G(i3);
                    if (iG == -1) {
                        y(this, "EOF", iG, null, 4, null);
                        throw null;
                    }
                } else {
                    continue;
                    cCharAt = charSequence.charAt(i3);
                }
            }
            z = true;
            i2 = iG;
            i3 = i2;
            cCharAt = charSequence.charAt(i3);
        }
        String strJ = !z ? J(i2, i3) : u(i2, i3);
        this.a = i3 + 1;
        return strJ;
    }

    public final String s() {
        if (this.c != null) {
            return K();
        }
        int I = I();
        if (I >= C().length() || I == -1) {
            y(this, "EOF", I, null, 4, null);
            throw null;
        }
        byte bA = b.a(C().charAt(I));
        if (bA == 1) {
            return q();
        }
        if (bA != 0) {
            y(this, "Expected beginning of the string, but got " + C().charAt(I), 0, null, 6, null);
            throw null;
        }
        boolean z = false;
        while (b.a(C().charAt(I)) == 0) {
            I++;
            if (I >= C().length()) {
                e(this.a, I);
                int iG = G(I);
                if (iG == -1) {
                    this.a = I;
                    return u(0, 0);
                }
                I = iG;
                z = true;
            }
        }
        String strJ = !z ? J(this.a, I) : u(this.a, I);
        this.a = I;
        return strJ;
    }

    public final String t() {
        String strS = s();
        if (!j.p0.d.r.a(strS, "null") || !O()) {
            return strS;
        }
        y(this, "Unexpected 'null' value instead of string literal", 0, null, 6, null);
        throw null;
    }

    public String toString() {
        return "JsonReader(source='" + ((Object) C()) + "', currentPosition=" + this.a + ')';
    }

    public void v() {
    }

    public final void w() {
        if (m() == 10) {
            return;
        }
        y(this, "Expected EOF after parsing, but had " + C().charAt(this.a - 1) + " instead", 0, null, 6, null);
        throw null;
    }

    public final Void x(String str, int i2, String str2) {
        String str3;
        j.p0.d.r.f(str, "message");
        j.p0.d.r.f(str2, "hint");
        if (str2.length() == 0) {
            str3 = HttpUrl.FRAGMENT_ENCODE_SET;
        } else {
            str3 = '\n' + str2;
        }
        throw q.e(i2, str + " at path: " + this.b.a() + str3, C());
    }

    public final Void z(byte b) {
        y(this, "Expected " + (b == 1 ? "quotation mark '\"'" : b == 4 ? "comma ','" : b == 5 ? "colon ':'" : b == 6 ? "start of the object '{'" : b == 7 ? "end of the object '}'" : b == 8 ? "start of the array '['" : b == 9 ? "end of the array ']'" : "valid token") + ", but had '" + ((this.a == C().length() || this.a <= 0) ? "EOF" : String.valueOf(C().charAt(this.a - 1))) + "' instead", this.a - 1, null, 4, null);
        throw null;
    }
}
