package j$.time.format;

import java.text.ParsePosition;
import java.util.Iterator;
import java.util.Set;

/* JADX INFO: loaded from: classes2.dex */
class n {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    protected String f19248b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    protected char f19249c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    protected n f19250d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    protected n f19251e;

    /* synthetic */ n(String str, String str2, n nVar, int i6) {
        this(str, str2, nVar);
    }

    protected boolean c(char c6, char c7) {
        return c6 == c7;
    }

    private n(String str, String str2, n nVar) {
        this.f19247a = str;
        this.f19248b = str2;
        this.f19250d = nVar;
        if (str.isEmpty()) {
            this.f19249c = (char) 65535;
        } else {
            this.f19249c = this.f19247a.charAt(0);
        }
    }

    public static n f(w wVar) {
        return wVar.k() ? new n("", null, null) : new m("", null, null);
    }

    public static n g(Set set, w wVar) {
        n nVarF = f(wVar);
        Iterator it = set.iterator();
        while (it.hasNext()) {
            String str = (String) it.next();
            nVarF.b(str, str);
        }
        return nVarF;
    }

    public final void a(String str, String str2) {
        b(str, str2);
    }

    public final String d(CharSequence charSequence, ParsePosition parsePosition) {
        int index = parsePosition.getIndex();
        int length = charSequence.length();
        if (!h(charSequence, index, length)) {
            return null;
        }
        int length2 = this.f19247a.length() + index;
        n nVar = this.f19250d;
        if (nVar != null && length2 != length) {
            while (true) {
                if (c(nVar.f19249c, charSequence.charAt(length2))) {
                    parsePosition.setIndex(length2);
                    String strD = nVar.d(charSequence, parsePosition);
                    if (strD != null) {
                        return strD;
                    }
                } else {
                    nVar = nVar.f19251e;
                    if (nVar == null) {
                        break;
                    }
                }
            }
        }
        parsePosition.setIndex(length2);
        return this.f19248b;
    }

    protected n e(String str, String str2, n nVar) {
        return new n(str, str2, nVar);
    }

    protected boolean h(CharSequence charSequence, int i6, int i7) {
        if (charSequence instanceof String) {
            return ((String) charSequence).startsWith(this.f19247a, i6);
        }
        int length = this.f19247a.length();
        if (length > i7 - i6) {
            return false;
        }
        int i8 = 0;
        while (true) {
            int i9 = length - 1;
            if (length <= 0) {
                return true;
            }
            int i10 = i8 + 1;
            int i11 = i6 + 1;
            if (!c(this.f19247a.charAt(i8), charSequence.charAt(i6))) {
                return false;
            }
            i6 = i11;
            length = i9;
            i8 = i10;
        }
    }

    private boolean b(String str, String str2) {
        int i6 = 0;
        while (i6 < str.length() && i6 < this.f19247a.length() && c(str.charAt(i6), this.f19247a.charAt(i6))) {
            i6++;
        }
        if (i6 == this.f19247a.length()) {
            if (i6 < str.length()) {
                String strSubstring = str.substring(i6);
                for (n nVar = this.f19250d; nVar != null; nVar = nVar.f19251e) {
                    if (c(nVar.f19249c, strSubstring.charAt(0))) {
                        return nVar.b(strSubstring, str2);
                    }
                }
                n nVarE = e(strSubstring, str2, null);
                nVarE.f19251e = this.f19250d;
                this.f19250d = nVarE;
                return true;
            }
            this.f19248b = str2;
            return true;
        }
        n nVarE2 = e(this.f19247a.substring(i6), this.f19248b, this.f19250d);
        this.f19247a = str.substring(0, i6);
        this.f19250d = nVarE2;
        if (i6 < str.length()) {
            this.f19250d.f19251e = e(str.substring(i6), str2, null);
            this.f19248b = null;
            return true;
        }
        this.f19248b = str2;
        return true;
    }
}
