package kotlin.text;

import androidx.media3.exoplayer.rtsp.SessionDescription;
import com.google.android.gms.measurement.internal.u1;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import kotlin.Pair;
import kotlin.collections.q;
import kotlin.jvm.functions.Function2;
import sd.l;

/* JADX INFO: loaded from: classes.dex */
public abstract class i extends h {
    public static List A0(CharSequence charSequence, final char[] cArr) {
        nb.g.i(charSequence, "<this>");
        final boolean z10 = false;
        if (cArr.length == 1) {
            return z0(0, charSequence, String.valueOf(cArr[0]), false);
        }
        y0(0);
        c cVar = new c(charSequence, 0, 0, new Function2() { // from class: kotlin.text.StringsKt__StringsKt$rangesDelimitedBy$1
            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            {
                super(2);
            }

            @Override // kotlin.jvm.functions.Function2
            public final Object invoke(Object obj, Object obj2) {
                CharSequence charSequence2 = (CharSequence) obj;
                int iIntValue = ((Number) obj2).intValue();
                nb.g.i(charSequence2, "$this$$receiver");
                int iR0 = i.r0(iIntValue, charSequence2, z10, cArr);
                if (iR0 < 0) {
                    return null;
                }
                return new Pair(Integer.valueOf(iR0), 1);
            }
        });
        ArrayList arrayList = new ArrayList(kotlin.collections.i.Z0(10, new kotlin.sequences.i(cVar)));
        Iterator it = cVar.iterator();
        while (it.hasNext()) {
            arrayList.add(D0(charSequence, (xd.c) it.next()));
        }
        return arrayList;
    }

    public static List B0(String str, String[] strArr) {
        if (strArr.length == 1) {
            String str2 = strArr[0];
            if (str2.length() != 0) {
                return z0(0, str, str2, false);
            }
        }
        c cVarV0 = v0(str, strArr, false, 0);
        ArrayList arrayList = new ArrayList(kotlin.collections.i.Z0(10, new kotlin.sequences.i(cVarV0)));
        Iterator it = cVarV0.iterator();
        while (it.hasNext()) {
            arrayList.add(D0(str, (xd.c) it.next()));
        }
        return arrayList;
    }

    public static boolean C0(CharSequence charSequence, String str) {
        nb.g.i(charSequence, "<this>");
        nb.g.i(str, "prefix");
        return charSequence instanceof String ? h.j0((String) charSequence, str, false) : w0(charSequence, 0, str, 0, str.length(), false);
    }

    public static final String D0(CharSequence charSequence, xd.c cVar) {
        nb.g.i(charSequence, "<this>");
        nb.g.i(cVar, SessionDescription.ATTR_RANGE);
        return charSequence.subSequence(Integer.valueOf(cVar.f34807a).intValue(), Integer.valueOf(cVar.f34808b).intValue() + 1).toString();
    }

    public static String E0(String str, String str2) {
        nb.g.i(str2, "delimiter");
        int iQ0 = q0(str, str2, 0, false, 6);
        if (iQ0 == -1) {
            return str;
        }
        String strSubstring = str.substring(str2.length() + iQ0, str.length());
        nb.g.h(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public static String F0(String str, String str2) {
        nb.g.i(str, "<this>");
        nb.g.i(str2, "missingDelimiterValue");
        int iS0 = s0(str, '.', 0, 6);
        if (iS0 == -1) {
            return str2;
        }
        String strSubstring = str.substring(iS0 + 1, str.length());
        nb.g.h(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public static CharSequence G0(CharSequence charSequence) {
        nb.g.i(charSequence, "<this>");
        int length = charSequence.length() - 1;
        int i10 = 0;
        boolean z10 = false;
        while (i10 <= length) {
            boolean zC = ua.b.C(charSequence.charAt(!z10 ? i10 : length));
            if (z10) {
                if (!zC) {
                    break;
                }
                length--;
            } else if (zC) {
                i10++;
            } else {
                z10 = true;
            }
        }
        return charSequence.subSequence(i10, length + 1);
    }

    public static boolean k0(CharSequence charSequence, char c6) {
        nb.g.i(charSequence, "<this>");
        return p0(charSequence, c6, 0, false, 2) >= 0;
    }

    public static boolean l0(CharSequence charSequence, String str) {
        nb.g.i(charSequence, "<this>");
        return q0(charSequence, str, 0, false, 2) >= 0;
    }

    public static final int m0(CharSequence charSequence) {
        nb.g.i(charSequence, "<this>");
        return charSequence.length() - 1;
    }

    public static final int n0(int i10, CharSequence charSequence, String str, boolean z10) {
        nb.g.i(charSequence, "<this>");
        nb.g.i(str, "string");
        return (z10 || !(charSequence instanceof String)) ? o0(charSequence, str, i10, charSequence.length(), z10, false) : ((String) charSequence).indexOf(str, i10);
    }

    public static final int o0(CharSequence charSequence, CharSequence charSequence2, int i10, int i11, boolean z10, boolean z11) {
        xd.a aVar;
        if (z11) {
            int iM0 = m0(charSequence);
            if (i10 > iM0) {
                i10 = iM0;
            }
            if (i11 < 0) {
                i11 = 0;
            }
            aVar = new xd.a(i10, i11, -1);
        } else {
            if (i10 < 0) {
                i10 = 0;
            }
            int length = charSequence.length();
            if (i11 > length) {
                i11 = length;
            }
            aVar = new xd.c(i10, i11, 1);
        }
        boolean z12 = charSequence instanceof String;
        int i12 = aVar.f34809c;
        int i13 = aVar.f34808b;
        int i14 = aVar.f34807a;
        if (z12 && (charSequence2 instanceof String)) {
            if ((i12 > 0 && i14 <= i13) || (i12 < 0 && i13 <= i14)) {
                while (!h.f0((String) charSequence2, 0, z10, (String) charSequence, i14, charSequence2.length())) {
                    if (i14 != i13) {
                        i14 += i12;
                    }
                }
                return i14;
            }
        } else if ((i12 > 0 && i14 <= i13) || (i12 < 0 && i13 <= i14)) {
            while (!w0(charSequence2, 0, charSequence, i14, charSequence2.length(), z10)) {
                if (i14 != i13) {
                    i14 += i12;
                }
            }
            return i14;
        }
        return -1;
    }

    public static int p0(CharSequence charSequence, char c6, int i10, boolean z10, int i11) {
        if ((i11 & 2) != 0) {
            i10 = 0;
        }
        if ((i11 & 4) != 0) {
            z10 = false;
        }
        nb.g.i(charSequence, "<this>");
        return (z10 || !(charSequence instanceof String)) ? r0(i10, charSequence, z10, new char[]{c6}) : ((String) charSequence).indexOf(c6, i10);
    }

    public static /* synthetic */ int q0(CharSequence charSequence, String str, int i10, boolean z10, int i11) {
        if ((i11 & 2) != 0) {
            i10 = 0;
        }
        if ((i11 & 4) != 0) {
            z10 = false;
        }
        return n0(i10, charSequence, str, z10);
    }

    public static final int r0(int i10, CharSequence charSequence, boolean z10, char[] cArr) {
        nb.g.i(charSequence, "<this>");
        nb.g.i(cArr, "chars");
        if (!z10 && cArr.length == 1 && (charSequence instanceof String)) {
            return ((String) charSequence).indexOf(q.b0(cArr), i10);
        }
        if (i10 < 0) {
            i10 = 0;
        }
        xd.c cVar = new xd.c(i10, m0(charSequence), 1);
        xd.b bVar = new xd.b(i10, cVar.f34808b, cVar.f34809c);
        while (bVar.f34812c) {
            int iB = bVar.b();
            char cCharAt = charSequence.charAt(iB);
            for (char c6 : cArr) {
                if (ua.b.r(c6, cCharAt, z10)) {
                    return iB;
                }
            }
        }
        return -1;
    }

    public static int s0(CharSequence charSequence, char c6, int i10, int i11) {
        if ((i11 & 2) != 0) {
            i10 = m0(charSequence);
        }
        nb.g.i(charSequence, "<this>");
        if (charSequence instanceof String) {
            return ((String) charSequence).lastIndexOf(c6, i10);
        }
        char[] cArr = {c6};
        if (charSequence instanceof String) {
            return ((String) charSequence).lastIndexOf(q.b0(cArr), i10);
        }
        int iM0 = m0(charSequence);
        if (i10 > iM0) {
            i10 = iM0;
        }
        while (-1 < i10) {
            if (ua.b.r(cArr[0], charSequence.charAt(i10), false)) {
                return i10;
            }
            i10--;
        }
        return -1;
    }

    public static int t0(String str, String str2, int i10) {
        int iM0 = (i10 & 2) != 0 ? m0(str) : 0;
        nb.g.i(str, "<this>");
        nb.g.i(str2, "string");
        return str.lastIndexOf(str2, iM0);
    }

    public static final kotlin.sequences.d u0(final CharSequence charSequence) {
        nb.g.i(charSequence, "<this>");
        return new kotlin.sequences.d(v0(charSequence, new String[]{"\r\n", "\n", "\r"}, false, 0), new l() { // from class: kotlin.text.StringsKt__StringsKt$splitToSequence$1
            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            {
                super(1);
            }

            @Override // sd.l
            public final Object invoke(Object obj) {
                xd.c cVar = (xd.c) obj;
                nb.g.i(cVar, "it");
                return i.D0(charSequence, cVar);
            }
        });
    }

    public static c v0(CharSequence charSequence, String[] strArr, final boolean z10, int i10) {
        y0(i10);
        final List listO = q.O(strArr);
        return new c(charSequence, 0, i10, new Function2() { // from class: kotlin.text.StringsKt__StringsKt$rangesDelimitedBy$2
            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            {
                super(2);
            }

            /* JADX WARN: Removed duplicated region for block: B:66:0x0111 A[EDGE_INSN: B:70:0x0111->B:66:0x0111 BREAK  A[LOOP:0: B:38:0x009b->B:49:0x00d1], EDGE_INSN: B:76:0x0111->B:66:0x0111 BREAK  A[LOOP:2: B:54:0x00db->B:65:0x010f]] */
            /* JADX WARN: Removed duplicated region for block: B:66:0x0111 A[EDGE_INSN: B:70:0x0111->B:66:0x0111 BREAK  A[LOOP:0: B:38:0x009b->B:49:0x00d1]] */
            @Override // kotlin.jvm.functions.Function2
            /*
                Code decompiled incorrectly, please refer to instructions dump.
            */
            public final Object invoke(Object obj, Object obj2) {
                Object next;
                Pair pair;
                Object next2;
                Object obj3;
                CharSequence charSequence2 = (CharSequence) obj;
                int iIntValue = ((Number) obj2).intValue();
                nb.g.i(charSequence2, "$this$$receiver");
                List<String> list = listO;
                boolean z11 = z10;
                if (z11 || list.size() != 1) {
                    if (iIntValue < 0) {
                        iIntValue = 0;
                    }
                    xd.c cVar = new xd.c(iIntValue, charSequence2.length(), 1);
                    boolean z12 = charSequence2 instanceof String;
                    int i11 = cVar.f34809c;
                    int i12 = cVar.f34808b;
                    if (!z12) {
                        if ((i11 > 0 && iIntValue <= i12) || (i11 < 0 && i12 <= iIntValue)) {
                            while (true) {
                                Iterator<T> it = list.iterator();
                                while (true) {
                                    if (!it.hasNext()) {
                                        next = null;
                                        break;
                                    }
                                    next = it.next();
                                    String str = (String) next;
                                    if (i.w0(str, 0, charSequence2, iIntValue, str.length(), z11)) {
                                        break;
                                    }
                                }
                                String str2 = (String) next;
                                if (str2 == null) {
                                    if (iIntValue == i12) {
                                        break;
                                    }
                                    iIntValue += i11;
                                } else {
                                    pair = new Pair(Integer.valueOf(iIntValue), str2);
                                    break;
                                }
                            }
                        }
                    } else if ((i11 <= 0 || iIntValue > i12) && (i11 >= 0 || i12 > iIntValue)) {
                        pair = null;
                    } else {
                        while (true) {
                            Iterator<T> it2 = list.iterator();
                            while (true) {
                                if (!it2.hasNext()) {
                                    next2 = null;
                                    break;
                                }
                                next2 = it2.next();
                                String str3 = (String) next2;
                                if (h.f0(str3, 0, z11, (String) charSequence2, iIntValue, str3.length())) {
                                    break;
                                }
                            }
                            String str4 = (String) next2;
                            if (str4 == null) {
                                if (iIntValue == i12) {
                                    break;
                                }
                                iIntValue += i11;
                            } else {
                                pair = new Pair(Integer.valueOf(iIntValue), str4);
                                break;
                            }
                        }
                        pair = null;
                    }
                } else {
                    List<String> list2 = list;
                    if (list2 instanceof List) {
                        List<String> list3 = list2;
                        int size = list3.size();
                        if (size == 0) {
                            throw new NoSuchElementException("List is empty.");
                        }
                        if (size != 1) {
                            throw new IllegalArgumentException("List has more than one element.");
                        }
                        obj3 = list3.get(0);
                    } else {
                        Iterator<T> it3 = list2.iterator();
                        if (!it3.hasNext()) {
                            throw new NoSuchElementException("Collection is empty.");
                        }
                        Object next3 = it3.next();
                        if (it3.hasNext()) {
                            throw new IllegalArgumentException("Collection has more than one element.");
                        }
                        obj3 = next3;
                    }
                    String str5 = (String) obj3;
                    int iQ0 = i.q0(charSequence2, str5, iIntValue, false, 4);
                    if (iQ0 >= 0) {
                        pair = new Pair(Integer.valueOf(iQ0), str5);
                    }
                }
                if (pair != null) {
                    return new Pair(pair.c(), Integer.valueOf(((String) pair.d()).length()));
                }
                return null;
            }
        });
    }

    public static final boolean w0(CharSequence charSequence, int i10, CharSequence charSequence2, int i11, int i12, boolean z10) {
        nb.g.i(charSequence, "<this>");
        nb.g.i(charSequence2, "other");
        if (i11 < 0 || i10 < 0 || i10 > charSequence.length() - i12 || i11 > charSequence2.length() - i12) {
            return false;
        }
        for (int i13 = 0; i13 < i12; i13++) {
            if (!ua.b.r(charSequence.charAt(i10 + i13), charSequence2.charAt(i11 + i13), z10)) {
                return false;
            }
        }
        return true;
    }

    public static String x0(String str, String str2) {
        nb.g.i(str, "<this>");
        nb.g.i(str2, "prefix");
        if (!C0(str, str2)) {
            return str;
        }
        String strSubstring = str.substring(str2.length());
        nb.g.h(strSubstring, "this as java.lang.String).substring(startIndex)");
        return strSubstring;
    }

    public static final void y0(int i10) {
        if (i10 < 0) {
            throw new IllegalArgumentException(u1.g("Limit must be non-negative, but was ", i10).toString());
        }
    }

    public static final List z0(int i10, CharSequence charSequence, String str, boolean z10) {
        y0(i10);
        int length = 0;
        int iN0 = n0(0, charSequence, str, z10);
        if (iN0 == -1 || i10 == 1) {
            return hb.a.l0(charSequence.toString());
        }
        boolean z11 = i10 > 0;
        int i11 = 10;
        if (z11 && i10 <= 10) {
            i11 = i10;
        }
        ArrayList arrayList = new ArrayList(i11);
        do {
            arrayList.add(charSequence.subSequence(length, iN0).toString());
            length = str.length() + iN0;
            if (z11 && arrayList.size() == i10 - 1) {
                break;
            }
            iN0 = n0(length, charSequence, str, z10);
        } while (iN0 != -1);
        arrayList.add(charSequence.subSequence(length, charSequence.length()).toString());
        return arrayList;
    }
}
