package f.e0;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: Access modifiers changed from: package-private */
/* JADX INFO: compiled from: Strings.kt */
/* JADX INFO: loaded from: classes.dex */
public class t extends s {

    /* JADX INFO: compiled from: Strings.kt */
    static final class a extends f.z.d.l implements f.z.c.p<CharSequence, Integer, f.k<? extends Integer, ? extends Integer>> {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ char[] f3934b;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        final /* synthetic */ boolean f3935f;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        a(char[] cArr, boolean z) {
            super(2);
            this.f3934b = cArr;
            this.f3935f = z;
        }

        public final f.k<Integer, Integer> b(CharSequence charSequence, int i2) {
            f.z.d.k.e(charSequence, "$this$$receiver");
            int iW = t.w(charSequence, this.f3934b, i2, this.f3935f);
            if (iW < 0) {
                return null;
            }
            return f.p.a(Integer.valueOf(iW), 1);
        }

        @Override // f.z.c.p
        public /* bridge */ /* synthetic */ f.k<? extends Integer, ? extends Integer> invoke(CharSequence charSequence, Integer num) {
            return b(charSequence, num.intValue());
        }
    }

    /* JADX INFO: compiled from: Strings.kt */
    static final class b extends f.z.d.l implements f.z.c.p<CharSequence, Integer, f.k<? extends Integer, ? extends Integer>> {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ List<String> f3936b;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        final /* synthetic */ boolean f3937f;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        b(List<String> list, boolean z) {
            super(2);
            this.f3936b = list;
            this.f3937f = z;
        }

        public final f.k<Integer, Integer> b(CharSequence charSequence, int i2) {
            f.z.d.k.e(charSequence, "$this$$receiver");
            f.k kVarN = t.n(charSequence, this.f3936b, i2, this.f3937f, false);
            if (kVarN != null) {
                return f.p.a(kVarN.c(), Integer.valueOf(((String) kVarN.d()).length()));
            }
            return null;
        }

        @Override // f.z.c.p
        public /* bridge */ /* synthetic */ f.k<? extends Integer, ? extends Integer> invoke(CharSequence charSequence, Integer num) {
            return b(charSequence, num.intValue());
        }
    }

    public static /* synthetic */ int A(CharSequence charSequence, String str, int i2, boolean z, int i3, Object obj) {
        if ((i3 & 2) != 0) {
            i2 = p(charSequence);
        }
        if ((i3 & 4) != 0) {
            z = false;
        }
        return y(charSequence, str, i2, z);
    }

    public static final int B(CharSequence charSequence, char[] cArr, int i2, boolean z) {
        f.z.d.k.e(charSequence, "<this>");
        f.z.d.k.e(cArr, "chars");
        if (!z && cArr.length == 1 && (charSequence instanceof String)) {
            return ((String) charSequence).lastIndexOf(f.u.f.j(cArr), i2);
        }
        for (int iC = f.b0.n.c(i2, p(charSequence)); -1 < iC; iC--) {
            char cCharAt = charSequence.charAt(iC);
            int length = cArr.length;
            boolean z2 = false;
            int i3 = 0;
            while (true) {
                if (i3 >= length) {
                    break;
                }
                if (c.d(cArr[i3], cCharAt, z)) {
                    z2 = true;
                    break;
                }
                i3++;
            }
            if (z2) {
                return iC;
            }
        }
        return -1;
    }

    private static final f.d0.b<f.b0.h> C(CharSequence charSequence, char[] cArr, int i2, boolean z, int i3) {
        I(i3);
        return new e(charSequence, i2, i3, new a(cArr, z));
    }

    private static final f.d0.b<f.b0.h> D(CharSequence charSequence, String[] strArr, int i2, boolean z, int i3) {
        I(i3);
        return new e(charSequence, i2, i3, new b(f.u.e.a(strArr), z));
    }

    static /* synthetic */ f.d0.b E(CharSequence charSequence, char[] cArr, int i2, boolean z, int i3, int i4, Object obj) {
        if ((i4 & 2) != 0) {
            i2 = 0;
        }
        if ((i4 & 4) != 0) {
            z = false;
        }
        if ((i4 & 8) != 0) {
            i3 = 0;
        }
        return C(charSequence, cArr, i2, z, i3);
    }

    static /* synthetic */ f.d0.b F(CharSequence charSequence, String[] strArr, int i2, boolean z, int i3, int i4, Object obj) {
        if ((i4 & 2) != 0) {
            i2 = 0;
        }
        if ((i4 & 4) != 0) {
            z = false;
        }
        if ((i4 & 8) != 0) {
            i3 = 0;
        }
        return D(charSequence, strArr, i2, z, i3);
    }

    public static final boolean G(CharSequence charSequence, int i2, CharSequence charSequence2, int i3, int i4, boolean z) {
        f.z.d.k.e(charSequence, "<this>");
        f.z.d.k.e(charSequence2, "other");
        if (i3 < 0 || i2 < 0 || i2 > charSequence.length() - i4 || i3 > charSequence2.length() - i4) {
            return false;
        }
        for (int i5 = 0; i5 < i4; i5++) {
            if (!c.d(charSequence.charAt(i2 + i5), charSequence2.charAt(i3 + i5), z)) {
                return false;
            }
        }
        return true;
    }

    public static String H(String str, CharSequence charSequence) {
        f.z.d.k.e(str, "<this>");
        f.z.d.k.e(charSequence, "prefix");
        if (!P(str, charSequence, false, 2, null)) {
            return str;
        }
        String strSubstring = str.substring(charSequence.length());
        f.z.d.k.d(strSubstring, "this as java.lang.String).substring(startIndex)");
        return strSubstring;
    }

    public static final void I(int i2) {
        if (i2 >= 0) {
            return;
        }
        throw new IllegalArgumentException(("Limit must be non-negative, but was " + i2).toString());
    }

    public static final List<String> J(CharSequence charSequence, char[] cArr, boolean z, int i2) {
        f.z.d.k.e(charSequence, "<this>");
        f.z.d.k.e(cArr, "delimiters");
        if (cArr.length == 1) {
            return L(charSequence, String.valueOf(cArr[0]), z, i2);
        }
        Iterable iterableC = f.d0.h.c(E(charSequence, cArr, 0, z, i2, 2, null));
        ArrayList arrayList = new ArrayList(f.u.l.j(iterableC, 10));
        Iterator it = iterableC.iterator();
        while (it.hasNext()) {
            arrayList.add(Q(charSequence, (f.b0.h) it.next()));
        }
        return arrayList;
    }

    public static final List<String> K(CharSequence charSequence, String[] strArr, boolean z, int i2) {
        f.z.d.k.e(charSequence, "<this>");
        f.z.d.k.e(strArr, "delimiters");
        if (strArr.length == 1) {
            String str = strArr[0];
            if (!(str.length() == 0)) {
                return L(charSequence, str, z, i2);
            }
        }
        Iterable iterableC = f.d0.h.c(F(charSequence, strArr, 0, z, i2, 2, null));
        ArrayList arrayList = new ArrayList(f.u.l.j(iterableC, 10));
        Iterator it = iterableC.iterator();
        while (it.hasNext()) {
            arrayList.add(Q(charSequence, (f.b0.h) it.next()));
        }
        return arrayList;
    }

    private static final List<String> L(CharSequence charSequence, String str, boolean z, int i2) {
        I(i2);
        int length = 0;
        int iR = r(charSequence, str, 0, z);
        if (iR == -1 || i2 == 1) {
            return f.u.j.b(charSequence.toString());
        }
        boolean z2 = i2 > 0;
        ArrayList arrayList = new ArrayList(z2 ? f.b0.n.c(i2, 10) : 10);
        do {
            arrayList.add(charSequence.subSequence(length, iR).toString());
            length = str.length() + iR;
            if (z2 && arrayList.size() == i2 - 1) {
                break;
            }
            iR = r(charSequence, str, length, z);
        } while (iR != -1);
        arrayList.add(charSequence.subSequence(length, charSequence.length()).toString());
        return arrayList;
    }

    public static /* synthetic */ List M(CharSequence charSequence, char[] cArr, boolean z, int i2, int i3, Object obj) {
        if ((i3 & 2) != 0) {
            z = false;
        }
        if ((i3 & 4) != 0) {
            i2 = 0;
        }
        return J(charSequence, cArr, z, i2);
    }

    public static /* synthetic */ List N(CharSequence charSequence, String[] strArr, boolean z, int i2, int i3, Object obj) {
        if ((i3 & 2) != 0) {
            z = false;
        }
        if ((i3 & 4) != 0) {
            i2 = 0;
        }
        return K(charSequence, strArr, z, i2);
    }

    public static final boolean O(CharSequence charSequence, CharSequence charSequence2, boolean z) {
        f.z.d.k.e(charSequence, "<this>");
        f.z.d.k.e(charSequence2, "prefix");
        return (!z && (charSequence instanceof String) && (charSequence2 instanceof String)) ? s.j((String) charSequence, (String) charSequence2, false, 2, null) : G(charSequence, 0, charSequence2, 0, charSequence2.length(), z);
    }

    public static /* synthetic */ boolean P(CharSequence charSequence, CharSequence charSequence2, boolean z, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            z = false;
        }
        return O(charSequence, charSequence2, z);
    }

    public static final String Q(CharSequence charSequence, f.b0.h hVar) {
        f.z.d.k.e(charSequence, "<this>");
        f.z.d.k.e(hVar, "range");
        return charSequence.subSequence(hVar.g().intValue(), hVar.f().intValue() + 1).toString();
    }

    public static final String R(String str, char c2, String str2) {
        f.z.d.k.e(str, "<this>");
        f.z.d.k.e(str2, "missingDelimiterValue");
        int iU = u(str, c2, 0, false, 6, null);
        if (iU == -1) {
            return str2;
        }
        String strSubstring = str.substring(iU + 1, str.length());
        f.z.d.k.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public static final String S(String str, String str2, String str3) {
        f.z.d.k.e(str, "<this>");
        f.z.d.k.e(str2, "delimiter");
        f.z.d.k.e(str3, "missingDelimiterValue");
        int iV = v(str, str2, 0, false, 6, null);
        if (iV == -1) {
            return str3;
        }
        String strSubstring = str.substring(iV + str2.length(), str.length());
        f.z.d.k.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public static /* synthetic */ String T(String str, char c2, String str2, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            str2 = str;
        }
        return R(str, c2, str2);
    }

    public static /* synthetic */ String U(String str, String str2, String str3, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            str3 = str;
        }
        return S(str, str2, str3);
    }

    public static final String V(String str, char c2, String str2) {
        f.z.d.k.e(str, "<this>");
        f.z.d.k.e(str2, "missingDelimiterValue");
        int iZ = z(str, c2, 0, false, 6, null);
        if (iZ == -1) {
            return str2;
        }
        String strSubstring = str.substring(iZ + 1, str.length());
        f.z.d.k.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public static /* synthetic */ String W(String str, char c2, String str2, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            str2 = str;
        }
        return V(str, c2, str2);
    }

    public static final String X(String str, char c2, String str2) {
        f.z.d.k.e(str, "<this>");
        f.z.d.k.e(str2, "missingDelimiterValue");
        int iU = u(str, c2, 0, false, 6, null);
        if (iU == -1) {
            return str2;
        }
        String strSubstring = str.substring(0, iU);
        f.z.d.k.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public static final String Y(String str, String str2, String str3) {
        f.z.d.k.e(str, "<this>");
        f.z.d.k.e(str2, "delimiter");
        f.z.d.k.e(str3, "missingDelimiterValue");
        int iV = v(str, str2, 0, false, 6, null);
        if (iV == -1) {
            return str3;
        }
        String strSubstring = str.substring(0, iV);
        f.z.d.k.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public static /* synthetic */ String Z(String str, char c2, String str2, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            str2 = str;
        }
        return X(str, c2, str2);
    }

    public static /* synthetic */ String a0(String str, String str2, String str3, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            str3 = str;
        }
        return Y(str, str2, str3);
    }

    public static final String b0(String str, String str2, String str3) {
        f.z.d.k.e(str, "<this>");
        f.z.d.k.e(str2, "delimiter");
        f.z.d.k.e(str3, "missingDelimiterValue");
        int iA = A(str, str2, 0, false, 6, null);
        if (iA == -1) {
            return str3;
        }
        String strSubstring = str.substring(0, iA);
        f.z.d.k.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public static /* synthetic */ String c0(String str, String str2, String str3, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            str3 = str;
        }
        return b0(str, str2, str3);
    }

    public static CharSequence d0(CharSequence charSequence) {
        f.z.d.k.e(charSequence, "<this>");
        int length = charSequence.length() - 1;
        int i2 = 0;
        boolean z = false;
        while (i2 <= length) {
            boolean zC = f.e0.b.c(charSequence.charAt(!z ? i2 : length));
            if (z) {
                if (!zC) {
                    break;
                }
                length--;
            } else if (zC) {
                i2++;
            } else {
                z = true;
            }
        }
        return charSequence.subSequence(i2, length + 1);
    }

    public static CharSequence e0(CharSequence charSequence) {
        f.z.d.k.e(charSequence, "<this>");
        int length = charSequence.length() - 1;
        if (length >= 0) {
            while (true) {
                int i2 = length - 1;
                if (!f.e0.b.c(charSequence.charAt(length))) {
                    return charSequence.subSequence(0, length + 1);
                }
                if (i2 < 0) {
                    break;
                }
                length = i2;
            }
        }
        return "";
    }

    public static final boolean l(CharSequence charSequence, CharSequence charSequence2, boolean z) {
        f.z.d.k.e(charSequence, "<this>");
        f.z.d.k.e(charSequence2, "other");
        if (charSequence2 instanceof String) {
            if (v(charSequence, (String) charSequence2, 0, z, 2, null) >= 0) {
                return true;
            }
        } else if (t(charSequence, charSequence2, 0, charSequence.length(), z, false, 16, null) >= 0) {
            return true;
        }
        return false;
    }

    public static /* synthetic */ boolean m(CharSequence charSequence, CharSequence charSequence2, boolean z, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            z = false;
        }
        return l(charSequence, charSequence2, z);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final f.k<Integer, String> n(CharSequence charSequence, Collection<String> collection, int i2, boolean z, boolean z2) {
        Object next;
        Object next2;
        if (!z && collection.size() == 1) {
            String str = (String) f.u.i.x(collection);
            int iV = !z2 ? v(charSequence, str, i2, false, 4, null) : A(charSequence, str, i2, false, 4, null);
            if (iV < 0) {
                return null;
            }
            return f.p.a(Integer.valueOf(iV), str);
        }
        f.b0.f hVar = !z2 ? new f.b0.h(f.b0.n.a(i2, 0), charSequence.length()) : f.b0.n.f(f.b0.n.c(i2, p(charSequence)), 0);
        if (charSequence instanceof String) {
            int iA = hVar.a();
            int iB = hVar.b();
            int iC = hVar.c();
            if ((iC > 0 && iA <= iB) || (iC < 0 && iB <= iA)) {
                while (true) {
                    Iterator<T> it = collection.iterator();
                    while (true) {
                        if (!it.hasNext()) {
                            next2 = null;
                            break;
                        }
                        next2 = it.next();
                        String str2 = (String) next2;
                        if (s.f(str2, 0, (String) charSequence, iA, str2.length(), z)) {
                            break;
                        }
                    }
                    String str3 = (String) next2;
                    if (str3 == null) {
                        if (iA == iB) {
                            break;
                        }
                        iA += iC;
                    } else {
                        return f.p.a(Integer.valueOf(iA), str3);
                    }
                }
            }
        } else {
            int iA2 = hVar.a();
            int iB2 = hVar.b();
            int iC2 = hVar.c();
            if ((iC2 > 0 && iA2 <= iB2) || (iC2 < 0 && iB2 <= iA2)) {
                while (true) {
                    Iterator<T> it2 = collection.iterator();
                    while (true) {
                        if (!it2.hasNext()) {
                            next = null;
                            break;
                        }
                        next = it2.next();
                        String str4 = (String) next;
                        if (G(str4, 0, charSequence, iA2, str4.length(), z)) {
                            break;
                        }
                    }
                    String str5 = (String) next;
                    if (str5 == null) {
                        if (iA2 == iB2) {
                            break;
                        }
                        iA2 += iC2;
                    } else {
                        return f.p.a(Integer.valueOf(iA2), str5);
                    }
                }
            }
        }
        return null;
    }

    public static final f.b0.h o(CharSequence charSequence) {
        f.z.d.k.e(charSequence, "<this>");
        return new f.b0.h(0, charSequence.length() - 1);
    }

    public static final int p(CharSequence charSequence) {
        f.z.d.k.e(charSequence, "<this>");
        return charSequence.length() - 1;
    }

    public static final int q(CharSequence charSequence, char c2, int i2, boolean z) {
        f.z.d.k.e(charSequence, "<this>");
        return (z || !(charSequence instanceof String)) ? w(charSequence, new char[]{c2}, i2, z) : ((String) charSequence).indexOf(c2, i2);
    }

    public static final int r(CharSequence charSequence, String str, int i2, boolean z) {
        f.z.d.k.e(charSequence, "<this>");
        f.z.d.k.e(str, "string");
        return (z || !(charSequence instanceof String)) ? t(charSequence, str, i2, charSequence.length(), z, false, 16, null) : ((String) charSequence).indexOf(str, i2);
    }

    private static final int s(CharSequence charSequence, CharSequence charSequence2, int i2, int i3, boolean z, boolean z2) {
        f.b0.f hVar = !z2 ? new f.b0.h(f.b0.n.a(i2, 0), f.b0.n.c(i3, charSequence.length())) : f.b0.n.f(f.b0.n.c(i2, p(charSequence)), f.b0.n.a(i3, 0));
        if ((charSequence instanceof String) && (charSequence2 instanceof String)) {
            int iA = hVar.a();
            int iB = hVar.b();
            int iC = hVar.c();
            if ((iC <= 0 || iA > iB) && (iC >= 0 || iB > iA)) {
                return -1;
            }
            while (!s.f((String) charSequence2, 0, (String) charSequence, iA, charSequence2.length(), z)) {
                if (iA == iB) {
                    return -1;
                }
                iA += iC;
            }
            return iA;
        }
        int iA2 = hVar.a();
        int iB2 = hVar.b();
        int iC2 = hVar.c();
        if ((iC2 <= 0 || iA2 > iB2) && (iC2 >= 0 || iB2 > iA2)) {
            return -1;
        }
        while (!G(charSequence2, 0, charSequence, iA2, charSequence2.length(), z)) {
            if (iA2 == iB2) {
                return -1;
            }
            iA2 += iC2;
        }
        return iA2;
    }

    static /* synthetic */ int t(CharSequence charSequence, CharSequence charSequence2, int i2, int i3, boolean z, boolean z2, int i4, Object obj) {
        if ((i4 & 16) != 0) {
            z2 = false;
        }
        return s(charSequence, charSequence2, i2, i3, z, z2);
    }

    public static /* synthetic */ int u(CharSequence charSequence, char c2, int i2, boolean z, int i3, Object obj) {
        if ((i3 & 2) != 0) {
            i2 = 0;
        }
        if ((i3 & 4) != 0) {
            z = false;
        }
        return q(charSequence, c2, i2, z);
    }

    public static /* synthetic */ int v(CharSequence charSequence, String str, int i2, boolean z, int i3, Object obj) {
        if ((i3 & 2) != 0) {
            i2 = 0;
        }
        if ((i3 & 4) != 0) {
            z = false;
        }
        return r(charSequence, str, i2, z);
    }

    public static final int w(CharSequence charSequence, char[] cArr, int i2, boolean z) {
        boolean z2;
        f.z.d.k.e(charSequence, "<this>");
        f.z.d.k.e(cArr, "chars");
        if (!z && cArr.length == 1 && (charSequence instanceof String)) {
            return ((String) charSequence).indexOf(f.u.f.j(cArr), i2);
        }
        int iA = f.b0.n.a(i2, 0);
        int iP = p(charSequence);
        if (iA > iP) {
            return -1;
        }
        while (true) {
            char cCharAt = charSequence.charAt(iA);
            int length = cArr.length;
            int i3 = 0;
            while (true) {
                if (i3 >= length) {
                    z2 = false;
                    break;
                }
                if (c.d(cArr[i3], cCharAt, z)) {
                    z2 = true;
                    break;
                }
                i3++;
            }
            if (z2) {
                return iA;
            }
            if (iA == iP) {
                return -1;
            }
            iA++;
        }
    }

    public static final int x(CharSequence charSequence, char c2, int i2, boolean z) {
        f.z.d.k.e(charSequence, "<this>");
        return (z || !(charSequence instanceof String)) ? B(charSequence, new char[]{c2}, i2, z) : ((String) charSequence).lastIndexOf(c2, i2);
    }

    public static final int y(CharSequence charSequence, String str, int i2, boolean z) {
        f.z.d.k.e(charSequence, "<this>");
        f.z.d.k.e(str, "string");
        return (z || !(charSequence instanceof String)) ? s(charSequence, str, i2, 0, z, true) : ((String) charSequence).lastIndexOf(str, i2);
    }

    public static /* synthetic */ int z(CharSequence charSequence, char c2, int i2, boolean z, int i3, Object obj) {
        if ((i3 & 2) != 0) {
            i2 = p(charSequence);
        }
        if ((i3 & 4) != 0) {
            z = false;
        }
        return x(charSequence, c2, i2, z);
    }
}
