package o;

import com.google.android.gms.common.api.Api;
import java.util.Iterator;
import java.util.NoSuchElementException;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class Fw0 implements Iterator {
    public String l;
    public final String n;

    /* renamed from: o, reason: collision with root package name */
    public final boolean f129o;
    public final /* synthetic */ C2003nu0 r;
    public int m = 2;
    public int p = 0;
    public int q = Api.BaseClientBuilder.API_PRIORITY_OTHER;

    public Fw0(C2160pe c2160pe, String str, C2003nu0 c2003nu0) {
        this.r = c2003nu0;
        this.f129o = c2160pe.l;
        this.n = str;
    }

    @Override // java.util.Iterator
    public final boolean hasNext() {
        int length;
        String str;
        int i;
        int i2 = this.m;
        if (i2 == 4) {
            throw new IllegalStateException();
        }
        int i3 = i2 - 1;
        String string = null;
        if (i2 == 0) {
            throw null;
        }
        if (i3 == 0) {
            return true;
        }
        if (i3 != 2) {
            this.m = 4;
            int i4 = this.p;
            while (true) {
                length = this.p;
                if (length == -1) {
                    this.m = 3;
                    break;
                }
                str = this.n;
                int length2 = str.length();
                AbstractC2798wI.C(length, length2);
                while (true) {
                    if (length >= length2) {
                        length = -1;
                        break;
                    }
                    if (str.charAt(length) == this.r.a) {
                        break;
                    }
                    length++;
                }
                if (length == -1) {
                    length = str.length();
                    this.p = -1;
                    i = -1;
                } else {
                    i = length + 1;
                    this.p = i;
                }
                if (i == i4) {
                    int i5 = i + 1;
                    this.p = i5;
                    if (i5 > str.length()) {
                        this.p = -1;
                    }
                } else {
                    if (i4 < length) {
                        str.charAt(i4);
                    }
                    if (i4 < length) {
                        str.charAt(length - 1);
                    }
                    if (!this.f129o || i4 != length) {
                        break;
                    }
                    i4 = this.p;
                }
            }
            int i6 = this.q;
            if (i6 == 1) {
                length = str.length();
                this.p = -1;
                if (length > i4) {
                    str.charAt(length - 1);
                }
            } else {
                this.q = i6 - 1;
            }
            string = str.subSequence(i4, length).toString();
            this.l = string;
            if (this.m != 3) {
                this.m = 1;
                return true;
            }
        }
        return false;
    }

    @Override // java.util.Iterator
    public final Object next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        this.m = 2;
        String str = this.l;
        this.l = null;
        return str;
    }

    @Override // java.util.Iterator
    public final void remove() {
        throw new UnsupportedOperationException();
    }
}
