package e.a.r.y;

import com.seewo.libmcuservice.constant.IChannelConstants;
import java.util.ArrayList;

/* JADX INFO: compiled from: AbstractJsonLexer.kt */
/* JADX INFO: loaded from: classes.dex */
@d.n
public abstract class a {

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private String f2994c;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final a0 f2993b = new a0();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private StringBuilder f2995d = new StringBuilder();

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

    private final String K() {
        String str = this.f2994c;
        d.n0.c.s.b(str);
        this.f2994c = null;
        return str;
    }

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

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

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

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

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

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

    private final String u(int i, int i2) {
        e(i, i2);
        String string = this.f2995d.toString();
        d.n0.c.s.d(string, "escapedString.toString()");
        this.f2995d.setLength(0);
        return string;
    }

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

    public final void A(String str) {
        d.n0.c.s.e(str, "key");
        x("Encountered an unknown key '" + str + '\'', d.s0.r.K(J(0, this.f2992a), str, 0, false, 6, null), "Use 'ignoreUnknownKeys = true' in 'Json {}' builder to ignore unknown keys.");
        throw new d.h();
    }

    protected abstract CharSequence C();

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

    public final byte E() {
        CharSequence charSequenceC = C();
        int i = this.f2992a;
        while (true) {
            int iG = G(i);
            if (iG == -1) {
                this.f2992a = iG;
                return (byte) 10;
            }
            char cCharAt = charSequenceC.charAt(iG);
            if (cCharAt != ' ' && cCharAt != '\n' && cCharAt != '\r' && cCharAt != '\t') {
                this.f2992a = iG;
                return b.a(cCharAt);
            }
            i = 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.f2994c = strQ;
        return strQ;
    }

    public abstract int G(int i);

    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) d.j0.n.t(arrayList)).byteValue() != 8) {
                        throw y.e(this.f2992a, "found ] instead of } at path: " + this.f2993b, C());
                    }
                    d.j0.n.m(arrayList);
                } else if (bE2 == 7) {
                    if (((Number) d.j0.n.t(arrayList)).byteValue() != 6) {
                        throw y.e(this.f2992a, "found } instead of ] at path: " + this.f2993b, C());
                    }
                    d.j0.n.m(arrayList);
                } else if (bE2 == 10) {
                    y(this, "Unexpected end of input due to malformed JSON during ignoring unknown keys", 0, null, 6, null);
                    throw new d.h();
                }
                m();
                if (arrayList.size() == 0) {
                    return;
                }
            } else if (z) {
                s();
            } else {
                k();
            }
        }
    }

    public abstract int I();

    public String J(int i, int i2) {
        return C().subSequence(i, i2).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 i = 0; i < 4; i++) {
            if ("null".charAt(i) != C().charAt(iG + i)) {
                return true;
            }
        }
        if (length > 4 && b.a(C().charAt(iG + 4)) == 0) {
            return true;
        }
        this.f2992a = iG + 4;
        return false;
    }

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

    protected void e(int i, int i2) {
        this.f2995d.append(C(), i, i2);
    }

    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 new d.h();
        }
        if (C().charAt(I) == '\"') {
            I++;
            z = true;
        } else {
            z = false;
        }
        boolean zH = h(I);
        if (z) {
            if (this.f2992a == C().length()) {
                y(this, "EOF", 0, null, 6, null);
                throw new d.h();
            }
            if (C().charAt(this.f2992a) != '\"') {
                y(this, "Expected closing quotation mark", 0, null, 6, null);
                throw new d.h();
            }
            this.f2992a++;
        }
        return zH;
    }

    public abstract String k();

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

    public abstract byte m();

    public final byte n(byte b2) {
        byte bM = m();
        if (bM == b2) {
            return bM;
        }
        z(b2);
        throw new d.h();
    }

    public abstract void o(char c2);

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

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

    protected final String r(CharSequence charSequence, int i, int i2) {
        int iG;
        d.n0.c.s.e(charSequence, IChannelConstants.KEY_SWITCH_SOURCE_SWITCH);
        char cCharAt = charSequence.charAt(i2);
        boolean z = false;
        while (cCharAt != '\"') {
            if (cCharAt == '\\') {
                iG = G(c(i, i2));
                if (iG == -1) {
                    y(this, "EOF", iG, null, 4, null);
                    throw new d.h();
                }
            } else {
                i2++;
                if (i2 >= charSequence.length()) {
                    e(i, i2);
                    iG = G(i2);
                    if (iG == -1) {
                        y(this, "EOF", iG, null, 4, null);
                        throw new d.h();
                    }
                } else {
                    continue;
                    cCharAt = charSequence.charAt(i2);
                }
            }
            z = true;
            i = iG;
            i2 = i;
            cCharAt = charSequence.charAt(i2);
        }
        String strJ = !z ? J(i, i2) : u(i, i2);
        this.f2992a = i2 + 1;
        return strJ;
    }

    public final String s() {
        if (this.f2994c != null) {
            return K();
        }
        int I = I();
        if (I >= C().length() || I == -1) {
            y(this, "EOF", I, null, 4, null);
            throw new d.h();
        }
        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 new d.h();
        }
        boolean z = false;
        while (b.a(C().charAt(I)) == 0) {
            I++;
            if (I >= C().length()) {
                e(this.f2992a, I);
                int iG = G(I);
                if (iG == -1) {
                    this.f2992a = I;
                    return u(0, 0);
                }
                I = iG;
                z = true;
            }
        }
        String strJ = !z ? J(this.f2992a, I) : u(this.f2992a, I);
        this.f2992a = I;
        return strJ;
    }

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

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

    public void v() {
    }

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

    public final Void x(String str, int i, String str2) {
        String str3;
        d.n0.c.s.e(str, "message");
        d.n0.c.s.e(str2, "hint");
        if (str2.length() == 0) {
            str3 = "";
        } else {
            str3 = '\n' + str2;
        }
        throw y.e(i, str + " at path: " + this.f2993b.a() + str3, C());
    }

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