package d.s0;

import d.j0.f0;
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 */
@d.n
public class r extends q {

    /* JADX INFO: compiled from: Strings.kt */
    @d.n
    static final class a extends d.n0.c.t implements d.n0.b.p<CharSequence, Integer, d.p<? extends Integer, ? extends Integer>> {

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

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

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

        public final d.p<Integer, Integer> c(CharSequence charSequence, int i) {
            d.n0.c.s.e(charSequence, "$this$$receiver");
            d.p pVarX = r.x(charSequence, this.f2721d, i, this.f2722e, false);
            if (pVarX != null) {
                return d.v.a(pVarX.c(), Integer.valueOf(((String) pVarX.d()).length()));
            }
            return null;
        }

        @Override // d.n0.b.p
        public /* bridge */ /* synthetic */ d.p<? extends Integer, ? extends Integer> g(CharSequence charSequence, Integer num) {
            return c(charSequence, num.intValue());
        }
    }

    /* JADX INFO: compiled from: Strings.kt */
    @d.n
    static final class b extends d.n0.c.t implements d.n0.b.l<d.p0.h, String> {

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        final /* synthetic */ CharSequence f2723d;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        b(CharSequence charSequence) {
            super(1);
            this.f2723d = charSequence;
        }

        @Override // d.n0.b.l
        /* JADX INFO: renamed from: c, reason: merged with bridge method [inline-methods] */
        public final String e(d.p0.h hVar) {
            d.n0.c.s.e(hVar, "it");
            return r.b0(this.f2723d, hVar);
        }
    }

    public static final int A(CharSequence charSequence, char c2, int i, boolean z) {
        d.n0.c.s.e(charSequence, "<this>");
        return (z || !(charSequence instanceof String)) ? G(charSequence, new char[]{c2}, i, z) : ((String) charSequence).indexOf(c2, i);
    }

    public static final int B(CharSequence charSequence, String str, int i, boolean z) {
        d.n0.c.s.e(charSequence, "<this>");
        d.n0.c.s.e(str, "string");
        return (z || !(charSequence instanceof String)) ? D(charSequence, str, i, charSequence.length(), z, false, 16, null) : ((String) charSequence).indexOf(str, i);
    }

    private static final int C(CharSequence charSequence, CharSequence charSequence2, int i, int i2, boolean z, boolean z2) {
        d.p0.f hVar = !z2 ? new d.p0.h(d.p0.n.b(i, 0), d.p0.n.c(i2, charSequence.length())) : d.p0.n.f(d.p0.n.c(i, z(charSequence)), d.p0.n.b(i2, 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 (!q.n((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 (!S(charSequence2, 0, charSequence, iA2, charSequence2.length(), z)) {
            if (iA2 == iB2) {
                return -1;
            }
            iA2 += iC2;
        }
        return iA2;
    }

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

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

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

    public static final int G(CharSequence charSequence, char[] cArr, int i, boolean z) {
        boolean z2;
        d.n0.c.s.e(charSequence, "<this>");
        d.n0.c.s.e(cArr, "chars");
        if (!z && cArr.length == 1 && (charSequence instanceof String)) {
            return ((String) charSequence).indexOf(d.j0.j.s(cArr), i);
        }
        f0 f0VarD = new d.p0.h(d.p0.n.b(i, 0), z(charSequence)).iterator();
        while (f0VarD.hasNext()) {
            int iA = f0VarD.a();
            char cCharAt = charSequence.charAt(iA);
            int length = cArr.length;
            int i2 = 0;
            while (true) {
                if (i2 >= length) {
                    z2 = false;
                    break;
                }
                if (c.d(cArr[i2], cCharAt, z)) {
                    z2 = true;
                    break;
                }
                i2++;
            }
            if (z2) {
                return iA;
            }
        }
        return -1;
    }

    public static final int H(CharSequence charSequence, char c2, int i, boolean z) {
        d.n0.c.s.e(charSequence, "<this>");
        return (z || !(charSequence instanceof String)) ? L(charSequence, new char[]{c2}, i, z) : ((String) charSequence).lastIndexOf(c2, i);
    }

    public static final int I(CharSequence charSequence, String str, int i, boolean z) {
        d.n0.c.s.e(charSequence, "<this>");
        d.n0.c.s.e(str, "string");
        return (z || !(charSequence instanceof String)) ? C(charSequence, str, i, 0, z, true) : ((String) charSequence).lastIndexOf(str, i);
    }

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

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

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

    public static final d.r0.a<String> M(CharSequence charSequence) {
        d.n0.c.s.e(charSequence, "<this>");
        return Y(charSequence, new String[]{"\r\n", "\n", "\r"}, false, 0, 6, null);
    }

    public static final List<String> N(CharSequence charSequence) {
        d.n0.c.s.e(charSequence, "<this>");
        return d.r0.g.d(M(charSequence));
    }

    public static final CharSequence O(CharSequence charSequence, int i, char c2) {
        d.n0.c.s.e(charSequence, "<this>");
        if (i < 0) {
            throw new IllegalArgumentException("Desired length " + i + " is less than zero.");
        }
        if (i <= charSequence.length()) {
            return charSequence.subSequence(0, charSequence.length());
        }
        StringBuilder sb = new StringBuilder(i);
        f0 f0VarD = new d.p0.h(1, i - charSequence.length()).iterator();
        while (f0VarD.hasNext()) {
            f0VarD.a();
            sb.append(c2);
        }
        sb.append(charSequence);
        return sb;
    }

    public static String P(String str, int i, char c2) {
        d.n0.c.s.e(str, "<this>");
        return O(str, i, c2).toString();
    }

    private static final d.r0.a<d.p0.h> Q(CharSequence charSequence, String[] strArr, int i, boolean z, int i2) {
        T(i2);
        return new e(charSequence, i, i2, new a(d.j0.i.b(strArr), z));
    }

    static /* synthetic */ d.r0.a R(CharSequence charSequence, String[] strArr, int i, boolean z, int i2, int i3, Object obj) {
        if ((i3 & 2) != 0) {
            i = 0;
        }
        if ((i3 & 4) != 0) {
            z = false;
        }
        if ((i3 & 8) != 0) {
            i2 = 0;
        }
        return Q(charSequence, strArr, i, z, i2);
    }

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

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

    public static final List<String> U(CharSequence charSequence, String[] strArr, boolean z, int i) {
        d.n0.c.s.e(charSequence, "<this>");
        d.n0.c.s.e(strArr, "delimiters");
        if (strArr.length == 1) {
            String str = strArr[0];
            if (!(str.length() == 0)) {
                return V(charSequence, str, z, i);
            }
        }
        Iterable iterableA = d.r0.g.a(R(charSequence, strArr, 0, z, i, 2, null));
        ArrayList arrayList = new ArrayList(d.j0.q.j(iterableA, 10));
        Iterator it = iterableA.iterator();
        while (it.hasNext()) {
            arrayList.add(b0(charSequence, (d.p0.h) it.next()));
        }
        return arrayList;
    }

    private static final List<String> V(CharSequence charSequence, String str, boolean z, int i) {
        T(i);
        int length = 0;
        int iB = B(charSequence, str, 0, z);
        if (iB == -1 || i == 1) {
            return d.j0.o.b(charSequence.toString());
        }
        boolean z2 = i > 0;
        ArrayList arrayList = new ArrayList(z2 ? d.p0.n.c(i, 10) : 10);
        do {
            arrayList.add(charSequence.subSequence(length, iB).toString());
            length = str.length() + iB;
            if (z2 && arrayList.size() == i - 1) {
                break;
            }
            iB = B(charSequence, str, length, z);
        } while (iB != -1);
        arrayList.add(charSequence.subSequence(length, charSequence.length()).toString());
        return arrayList;
    }

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

    public static final d.r0.a<String> X(CharSequence charSequence, String[] strArr, boolean z, int i) {
        d.n0.c.s.e(charSequence, "<this>");
        d.n0.c.s.e(strArr, "delimiters");
        return d.r0.g.b(R(charSequence, strArr, 0, z, i, 2, null), new b(charSequence));
    }

    public static /* synthetic */ d.r0.a Y(CharSequence charSequence, String[] strArr, boolean z, int i, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            z = false;
        }
        if ((i2 & 4) != 0) {
            i = 0;
        }
        return X(charSequence, strArr, z, i);
    }

    public static final boolean Z(CharSequence charSequence, char c2, boolean z) {
        d.n0.c.s.e(charSequence, "<this>");
        return charSequence.length() > 0 && c.d(charSequence.charAt(0), c2, z);
    }

    public static /* synthetic */ boolean a0(CharSequence charSequence, char c2, boolean z, int i, Object obj) {
        if ((i & 2) != 0) {
            z = false;
        }
        return Z(charSequence, c2, z);
    }

    public static final String b0(CharSequence charSequence, d.p0.h hVar) {
        d.n0.c.s.e(charSequence, "<this>");
        d.n0.c.s.e(hVar, "range");
        return charSequence.subSequence(hVar.h().intValue(), hVar.g().intValue() + 1).toString();
    }

    public static final String c0(String str, char c2, String str2) {
        d.n0.c.s.e(str, "<this>");
        d.n0.c.s.e(str2, "missingDelimiterValue");
        int iE = E(str, c2, 0, false, 6, null);
        if (iE == -1) {
            return str2;
        }
        String strSubstring = str.substring(iE + 1, str.length());
        d.n0.c.s.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public static final String d0(String str, String str2, String str3) {
        d.n0.c.s.e(str, "<this>");
        d.n0.c.s.e(str2, "delimiter");
        d.n0.c.s.e(str3, "missingDelimiterValue");
        int iF = F(str, str2, 0, false, 6, null);
        if (iF == -1) {
            return str3;
        }
        String strSubstring = str.substring(iF + str2.length(), str.length());
        d.n0.c.s.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

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

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

    public static final String g0(String str, char c2, String str2) {
        d.n0.c.s.e(str, "<this>");
        d.n0.c.s.e(str2, "missingDelimiterValue");
        int iJ = J(str, c2, 0, false, 6, null);
        if (iJ == -1) {
            return str2;
        }
        String strSubstring = str.substring(iJ + 1, str.length());
        d.n0.c.s.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

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

    public static final boolean t(CharSequence charSequence, char c2, boolean z) {
        d.n0.c.s.e(charSequence, "<this>");
        return E(charSequence, c2, 0, z, 2, null) >= 0;
    }

    public static final boolean u(CharSequence charSequence, CharSequence charSequence2, boolean z) {
        d.n0.c.s.e(charSequence, "<this>");
        d.n0.c.s.e(charSequence2, "other");
        if (charSequence2 instanceof String) {
            if (F(charSequence, (String) charSequence2, 0, z, 2, null) >= 0) {
                return true;
            }
        } else if (D(charSequence, charSequence2, 0, charSequence.length(), z, false, 16, null) >= 0) {
            return true;
        }
        return false;
    }

    public static /* synthetic */ boolean v(CharSequence charSequence, char c2, boolean z, int i, Object obj) {
        if ((i & 2) != 0) {
            z = false;
        }
        return t(charSequence, c2, z);
    }

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

    /* JADX INFO: Access modifiers changed from: private */
    public static final d.p<Integer, String> x(CharSequence charSequence, Collection<String> collection, int i, boolean z, boolean z2) {
        Object next;
        Object next2;
        if (!z && collection.size() == 1) {
            String str = (String) d.j0.n.w(collection);
            int iF = !z2 ? F(charSequence, str, i, false, 4, null) : K(charSequence, str, i, false, 4, null);
            if (iF < 0) {
                return null;
            }
            return d.v.a(Integer.valueOf(iF), str);
        }
        d.p0.f hVar = !z2 ? new d.p0.h(d.p0.n.b(i, 0), charSequence.length()) : d.p0.n.f(d.p0.n.c(i, z(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 (q.n(str2, 0, (String) charSequence, iA, str2.length(), z)) {
                            break;
                        }
                    }
                    String str3 = (String) next2;
                    if (str3 == null) {
                        if (iA == iB) {
                            break;
                        }
                        iA += iC;
                    } else {
                        return d.v.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 (S(str4, 0, charSequence, iA2, str4.length(), z)) {
                            break;
                        }
                    }
                    String str5 = (String) next;
                    if (str5 == null) {
                        if (iA2 == iB2) {
                            break;
                        }
                        iA2 += iC2;
                    } else {
                        return d.v.a(Integer.valueOf(iA2), str5);
                    }
                }
            }
        }
        return null;
    }

    public static final d.p0.h y(CharSequence charSequence) {
        d.n0.c.s.e(charSequence, "<this>");
        return new d.p0.h(0, charSequence.length() - 1);
    }

    public static int z(CharSequence charSequence) {
        d.n0.c.s.e(charSequence, "<this>");
        return charSequence.length() - 1;
    }
}
