package defpackage;

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

/* JADX INFO: renamed from: ᵩᵞᵖ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C3829 implements Closeable, Flushable {

    /* JADX INFO: renamed from: ᵸˆˁ, reason: contains not printable characters */
    public static final String[] f14620 = new String[128];

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public final InterfaceC0048 f14621;

    /* JADX INFO: renamed from: ˌᵨʠᵫ, reason: contains not printable characters */
    public String f14623;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public int[] f14625;

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public boolean f14627;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public String[] f14624 = new String[32];

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public int[] f14626 = new int[32];

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public int f14628 = -1;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public int f14622 = 1;

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

    public C3829(InterfaceC0048 interfaceC0048) {
        int[] iArr = new int[32];
        this.f14625 = iArr;
        this.f14621 = interfaceC0048;
        iArr[0] = 6;
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x002b  */
    /* JADX INFO: renamed from: ᵨˈʼﹶ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static void m8528(InterfaceC0048 interfaceC0048, String str) {
        String str2;
        interfaceC0048.writeByte(34);
        int length = str.length();
        int i = 0;
        for (int i2 = 0; i2 < length; i2++) {
            char cCharAt = str.charAt(i2);
            if (cCharAt < 128) {
                str2 = f14620[cCharAt];
                if (str2 != null) {
                    if (i < i2) {
                        interfaceC0048.mo1038(i, i2, str);
                    }
                    interfaceC0048.mo1039(str2);
                    i = i2 + 1;
                }
            } else {
                if (cCharAt == 8232) {
                    str2 = "\\u2028";
                } else if (cCharAt == 8233) {
                    str2 = "\\u2029";
                }
                if (i < i2) {
                }
                interfaceC0048.mo1039(str2);
                i = i2 + 1;
            }
        }
        if (i < length) {
            interfaceC0048.mo1038(i, length, str);
        }
        interfaceC0048.writeByte(34);
    }

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

    @Override // java.io.Flushable
    public final void flush() {
        if (this.f14622 != 0) {
            this.f14621.flush();
        } else {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("JsonWriter is closed.");
        }
    }

    /* JADX INFO: renamed from: ˀᵗ, reason: contains not printable characters */
    public final C3829 m8529(Number number) {
        if (number == null) {
            m8542();
            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.f14627) {
            this.f14627 = false;
            m8530(string);
            return this;
        }
        m8532();
        m8541();
        this.f14621.mo1039(string);
        int[] iArr = this.f14626;
        int i = this.f14622 - 1;
        iArr[i] = iArr[i] + 1;
        return this;
    }

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public final C3829 m8530(String str) {
        if (str == null) {
            C4935.m10233("name == null");
            return null;
        }
        if (this.f14622 == 0) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("JsonWriter is closed.");
            return null;
        }
        int iM8531 = m8531();
        if ((iM8531 != 3 && iM8531 != 5) || this.f14623 != null || this.f14627) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Nesting problem.");
            return null;
        }
        this.f14623 = str;
        this.f14624[this.f14622 - 1] = str;
        return this;
    }

    /* JADX INFO: renamed from: ˈⁱᵡ, reason: contains not printable characters */
    public final int m8531() {
        int i = this.f14622;
        if (i != 0) {
            return this.f14625[i - 1];
        }
        ᵕᵩʽᵲ.ᵪᵹᵥᵻ("JsonWriter is closed.");
        return 0;
    }

    /* JADX INFO: renamed from: ˉˆᵗ, reason: contains not printable characters */
    public final void m8532() {
        if (this.f14623 != null) {
            int iM8531 = m8531();
            InterfaceC0048 interfaceC0048 = this.f14621;
            if (iM8531 == 5) {
                interfaceC0048.writeByte(44);
            } else if (iM8531 != 3) {
                ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Nesting problem.");
                return;
            }
            this.f14625[this.f14622 - 1] = 4;
            m8528(interfaceC0048, this.f14623);
            this.f14623 = null;
        }
    }

    /* JADX INFO: renamed from: ˊˌˊ, reason: contains not printable characters */
    public final C3829 m8533(long j) {
        if (this.f14627) {
            this.f14627 = false;
            m8530(Long.toString(j));
            return this;
        }
        m8532();
        m8541();
        this.f14621.mo1039(Long.toString(j));
        int[] iArr = this.f14626;
        int i = this.f14622 - 1;
        iArr[i] = iArr[i] + 1;
        return this;
    }

    /* JADX INFO: renamed from: ˏːˆ, reason: contains not printable characters */
    public final C3829 m8534() {
        this.f14627 = false;
        m8540(3, 5, '}');
        return this;
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final C3829 m8535() {
        if (this.f14627) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Array cannot be used as a map key in JSON at path ".concat(m8537()));
            return null;
        }
        m8532();
        m8536(1, 2, '[');
        return this;
    }

    /* JADX INFO: renamed from: ˑˊᵲ, reason: contains not printable characters */
    public final void m8536(int i, int i2, char c) {
        int i3;
        int i4 = this.f14622;
        int i5 = this.f14628;
        if (i4 == i5 && ((i3 = this.f14625[i4 - 1]) == i || i3 == i2)) {
            this.f14628 = ~i5;
            return;
        }
        m8541();
        int i6 = this.f14622;
        int[] iArr = this.f14625;
        if (i6 == iArr.length) {
            if (i6 == 256) {
                throw new JsonDataException("Nesting too deep at " + m8537() + ": circular reference?");
            }
            this.f14625 = Arrays.copyOf(iArr, iArr.length * 2);
            String[] strArr = this.f14624;
            this.f14624 = (String[]) Arrays.copyOf(strArr, strArr.length * 2);
            int[] iArr2 = this.f14626;
            this.f14626 = Arrays.copyOf(iArr2, iArr2.length * 2);
        }
        int[] iArr3 = this.f14625;
        int i7 = this.f14622;
        this.f14622 = i7 + 1;
        iArr3[i7] = i;
        this.f14626[i7] = 0;
        this.f14621.writeByte(c);
    }

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public final String m8537() {
        return ˀᵳˎᵹ.ˋˈ(this.f14622, this.f14625, this.f14624, this.f14626);
    }

    /* JADX INFO: renamed from: ᵛˀˊ, reason: contains not printable characters */
    public final C3829 m8538(String str) {
        if (str == null) {
            m8542();
            return this;
        }
        if (this.f14627) {
            this.f14627 = false;
            m8530(str);
            return this;
        }
        m8532();
        m8541();
        m8528(this.f14621, str);
        int[] iArr = this.f14626;
        int i = this.f14622 - 1;
        iArr[i] = iArr[i] + 1;
        return this;
    }

    /* JADX INFO: renamed from: ᵟᵹᵙ, reason: contains not printable characters */
    public final C3829 m8539() {
        if (this.f14627) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Object cannot be used as a map key in JSON at path ".concat(m8537()));
            return null;
        }
        m8532();
        m8536(3, 5, '{');
        return this;
    }

    /* JADX INFO: renamed from: ᵱʡˏ, reason: contains not printable characters */
    public final void m8540(int i, int i2, char c) {
        int iM8531 = m8531();
        if (iM8531 != i2 && iM8531 != i) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Nesting problem.");
            return;
        }
        if (this.f14623 != null) {
            C1685.m4559(this.f14623, "Dangling name: ");
            return;
        }
        int i3 = this.f14622;
        int i4 = ~this.f14628;
        if (i3 == i4) {
            this.f14628 = i4;
            return;
        }
        int i5 = i3 - 1;
        this.f14622 = i5;
        this.f14624[i5] = null;
        int[] iArr = this.f14626;
        int i6 = i3 - 2;
        iArr[i6] = iArr[i6] + 1;
        this.f14621.writeByte(c);
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final void m8541() {
        int iM8531 = m8531();
        int i = 2;
        if (iM8531 != 1) {
            InterfaceC0048 interfaceC0048 = this.f14621;
            if (iM8531 == 2) {
                interfaceC0048.writeByte(44);
            } else if (iM8531 == 4) {
                interfaceC0048.mo1039(":");
                i = 5;
            } else if (iM8531 == 9) {
                ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Sink from valueSink() was not closed");
                return;
            } else {
                if (iM8531 != 6) {
                    if (iM8531 == 7) {
                        ᵕᵩʽᵲ.ᵪᵹᵥᵻ("JSON must have only one top-level value.");
                        return;
                    } else {
                        ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Nesting problem.");
                        return;
                    }
                }
                i = 7;
            }
        }
        this.f14625[this.f14622 - 1] = i;
    }

    /* JADX INFO: renamed from: ᵸˆˁ, reason: contains not printable characters */
    public final C3829 m8542() {
        if (this.f14627) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("null cannot be used as a map key in JSON at path ".concat(m8537()));
            return null;
        }
        if (this.f14623 != null) {
            this.f14623 = null;
            return this;
        }
        m8541();
        this.f14621.mo1039("null");
        int[] iArr = this.f14626;
        int i = this.f14622 - 1;
        iArr[i] = iArr[i] + 1;
        return this;
    }
}
