package defpackage;

import com.squareup.moshi.JsonDataException;
import java.io.Closeable;
import java.io.Flushable;
import java.io.IOException;
import java.util.Arrays;

/* renamed from: ˌᵮᵠ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C1639 implements Closeable, Flushable {

    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public static final String[] f6547 = new String[128];

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public final InterfaceC3656 f6548;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public String f6549;

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public int[] f6551;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public boolean f6552;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public String[] f6555 = new String[32];

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public int[] f6554 = new int[32];

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public int f6550 = -1;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public int f6553 = 1;

    static {
        for (int i = 0; i <= 31; i++) {
            f6547[i] = String.format("\\u%04x", Integer.valueOf(i));
        }
        String[] strArr = f6547;
        strArr[34] = "\\\"";
        strArr[92] = "\\\\";
        strArr[9] = "\\t";
        strArr[8] = "\\b";
        strArr[10] = "\\n";
        strArr[13] = "\\r";
        strArr[12] = "\\f";
    }

    public C1639(InterfaceC3656 interfaceC3656) {
        int[] iArr = new int[32];
        this.f6551 = iArr;
        this.f6548 = interfaceC3656;
        iArr[0] = 6;
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x002b  */
    /* renamed from: ᵛˈᵤ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static void m4694(defpackage.InterfaceC3656 r6, java.lang.String r7) {
        /*
            r0 = 34
            r6.writeByte(r0)
            int r1 = r7.length()
            r2 = 0
            r3 = r2
        Lb:
            if (r2 >= r1) goto L36
            char r4 = r7.charAt(r2)
            r5 = 128(0x80, float:1.794E-43)
            if (r4 >= r5) goto L1c
            java.lang.String[] r5 = defpackage.C1639.f6547
            r4 = r5[r4]
            if (r4 != 0) goto L29
            goto L33
        L1c:
            r5 = 8232(0x2028, float:1.1535E-41)
            if (r4 != r5) goto L23
            java.lang.String r4 = "\\u2028"
            goto L29
        L23:
            r5 = 8233(0x2029, float:1.1537E-41)
            if (r4 != r5) goto L33
            java.lang.String r4 = "\\u2029"
        L29:
            if (r3 >= r2) goto L2e
            r6.mo3274(r3, r2, r7)
        L2e:
            r6.mo3287(r4)
            int r3 = r2 + 1
        L33:
            int r2 = r2 + 1
            goto Lb
        L36:
            if (r3 >= r1) goto L3b
            r6.mo3274(r3, r1, r7)
        L3b:
            r6.writeByte(r0)
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.C1639.m4694(ᵧᵛᵹˉ, java.lang.String):void");
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public final void close() throws IOException {
        this.f6548.close();
        int i = this.f6553;
        if (i > 1 || (i == 1 && this.f6551[i - 1] != 7)) {
            C0910.m3045("Incomplete document");
        } else {
            this.f6553 = 0;
        }
    }

    @Override // java.io.Flushable
    public final void flush() {
        if (this.f6553 != 0) {
            this.f6548.flush();
        } else {
            ᵹˉᵞ.ᵳٴᵶ("JsonWriter is closed.");
        }
    }

    /* renamed from: ˀᵗᵩ, reason: contains not printable characters */
    public final int m4695() {
        int i = this.f6553;
        if (i != 0) {
            return this.f6551[i - 1];
        }
        ᵹˉᵞ.ᵳٴᵶ("JsonWriter is closed.");
        return 0;
    }

    /* renamed from: ˊʽˎ, reason: contains not printable characters */
    public final C1639 m4696(Number number) {
        if (number == null) {
            m4701();
            return this;
        }
        String string = number.toString();
        if (string.equals("-Infinity") || string.equals("Infinity") || string.equals("NaN")) {
            ᵨᴵᵺ.ᵨᵳʝ(number, "Numeric values must be finite, but was ");
            return null;
        }
        if (this.f6552) {
            this.f6552 = false;
            m4703(string);
            return this;
        }
        m4708();
        m4706();
        this.f6548.mo3287(string);
        int[] iArr = this.f6554;
        int i = this.f6553 - 1;
        iArr[i] = iArr[i] + 1;
        return this;
    }

    /* renamed from: ˊᵸˊ, reason: contains not printable characters */
    public final void m4697(int i, int i2, char c) {
        int i3;
        int i4 = this.f6553;
        int i5 = this.f6550;
        if (i4 == i5 && ((i3 = this.f6551[i4 - 1]) == i || i3 == i2)) {
            this.f6550 = ~i5;
            return;
        }
        m4706();
        int i6 = this.f6553;
        int[] iArr = this.f6551;
        if (i6 == iArr.length) {
            if (i6 == 256) {
                throw new JsonDataException("Nesting too deep at " + m4704() + ": circular reference?");
            }
            this.f6551 = Arrays.copyOf(iArr, iArr.length * 2);
            String[] strArr = this.f6555;
            this.f6555 = (String[]) Arrays.copyOf(strArr, strArr.length * 2);
            int[] iArr2 = this.f6554;
            this.f6554 = Arrays.copyOf(iArr2, iArr2.length * 2);
        }
        int[] iArr3 = this.f6551;
        int i7 = this.f6553;
        this.f6553 = i7 + 1;
        iArr3[i7] = i;
        this.f6554[i7] = 0;
        this.f6548.writeByte(c);
    }

    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public final C1639 m4698() {
        if (this.f6552) {
            ᵹˉᵞ.ᵳٴᵶ("Object cannot be used as a map key in JSON at path ".concat(m4704()));
            return null;
        }
        m4708();
        m4697(3, 5, '{');
        return this;
    }

    /* renamed from: ˎᵬˀ, reason: contains not printable characters */
    public final C1639 m4699(String str) {
        if (str == null) {
            m4701();
            return this;
        }
        if (this.f6552) {
            this.f6552 = false;
            m4703(str);
            return this;
        }
        m4708();
        m4706();
        m4694(this.f6548, str);
        int[] iArr = this.f6554;
        int i = this.f6553 - 1;
        iArr[i] = iArr[i] + 1;
        return this;
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final C1639 m4700() {
        if (this.f6552) {
            ᵹˉᵞ.ᵳٴᵶ("Array cannot be used as a map key in JSON at path ".concat(m4704()));
            return null;
        }
        m4708();
        m4697(1, 2, '[');
        return this;
    }

    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public final C1639 m4701() {
        if (this.f6552) {
            ᵹˉᵞ.ᵳٴᵶ("null cannot be used as a map key in JSON at path ".concat(m4704()));
            return null;
        }
        if (this.f6549 != null) {
            this.f6549 = null;
            return this;
        }
        m4706();
        this.f6548.mo3287("null");
        int[] iArr = this.f6554;
        int i = this.f6553 - 1;
        iArr[i] = iArr[i] + 1;
        return this;
    }

    /* renamed from: ᵞʡ, reason: contains not printable characters */
    public final void m4702(int i, int i2, char c) {
        int iM4695 = m4695();
        if (iM4695 != i2 && iM4695 != i) {
            ᵹˉᵞ.ᵳٴᵶ("Nesting problem.");
            return;
        }
        if (this.f6549 != null) {
            C0910.m3052(this.f6549, "Dangling name: ");
            return;
        }
        int i3 = this.f6553;
        int i4 = ~this.f6550;
        if (i3 == i4) {
            this.f6550 = i4;
            return;
        }
        int i5 = i3 - 1;
        this.f6553 = i5;
        this.f6555[i5] = null;
        int[] iArr = this.f6554;
        int i6 = i3 - 2;
        iArr[i6] = iArr[i6] + 1;
        this.f6548.writeByte(c);
    }

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public final C1639 m4703(String str) {
        if (str == null) {
            C1260.m3813("name == null");
            return null;
        }
        if (this.f6553 == 0) {
            ᵹˉᵞ.ᵳٴᵶ("JsonWriter is closed.");
            return null;
        }
        int iM4695 = m4695();
        if ((iM4695 != 3 && iM4695 != 5) || this.f6549 != null || this.f6552) {
            ᵹˉᵞ.ᵳٴᵶ("Nesting problem.");
            return null;
        }
        this.f6549 = str;
        this.f6555[this.f6553 - 1] = str;
        return this;
    }

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public final String m4704() {
        return ˆᴵ.ᵯٴᵦ(this.f6553, this.f6551, this.f6555, this.f6554);
    }

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final C1639 m4705() {
        this.f6552 = false;
        m4702(3, 5, '}');
        return this;
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final void m4706() {
        int iM4695 = m4695();
        int i = 2;
        if (iM4695 != 1) {
            InterfaceC3656 interfaceC3656 = this.f6548;
            if (iM4695 == 2) {
                interfaceC3656.writeByte(44);
            } else if (iM4695 == 4) {
                interfaceC3656.mo3287(":");
                i = 5;
            } else if (iM4695 == 9) {
                ᵹˉᵞ.ᵳٴᵶ("Sink from valueSink() was not closed");
                return;
            } else {
                if (iM4695 != 6) {
                    if (iM4695 == 7) {
                        ᵹˉᵞ.ᵳٴᵶ("JSON must have only one top-level value.");
                        return;
                    } else {
                        ᵹˉᵞ.ᵳٴᵶ("Nesting problem.");
                        return;
                    }
                }
                i = 7;
            }
        }
        this.f6551[this.f6553 - 1] = i;
    }

    /* renamed from: ᵳᵹᵺˋ, reason: contains not printable characters */
    public final C1639 m4707(long j) {
        if (this.f6552) {
            this.f6552 = false;
            m4703(Long.toString(j));
            return this;
        }
        m4708();
        m4706();
        this.f6548.mo3287(Long.toString(j));
        int[] iArr = this.f6554;
        int i = this.f6553 - 1;
        iArr[i] = iArr[i] + 1;
        return this;
    }

    /* renamed from: ᵷᵱ, reason: contains not printable characters */
    public final void m4708() {
        if (this.f6549 != null) {
            int iM4695 = m4695();
            InterfaceC3656 interfaceC3656 = this.f6548;
            if (iM4695 == 5) {
                interfaceC3656.writeByte(44);
            } else if (iM4695 != 3) {
                ᵹˉᵞ.ᵳٴᵶ("Nesting problem.");
                return;
            }
            this.f6551[this.f6553 - 1] = 4;
            m4694(interfaceC3656, this.f6549);
            this.f6549 = null;
        }
    }
}
