package h.c0;

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 q extends p {

    /* JADX INFO: compiled from: Strings.kt */
    static final class a extends h.x.d.l implements h.x.c.p<CharSequence, Integer, h.k<? extends Integer, ? extends Integer>> {
        final /* synthetic */ char[] b;

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

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

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

        public final h.k<Integer, Integer> b(CharSequence charSequence, int i2) {
            h.x.d.k.d(charSequence, "$this$$receiver");
            int iQ = q.Q(charSequence, this.b, i2, this.f960e);
            if (iQ < 0) {
                return null;
            }
            return h.o.a(Integer.valueOf(iQ), 1);
        }
    }

    /* JADX INFO: compiled from: Strings.kt */
    static final class b extends h.x.d.l implements h.x.c.p<CharSequence, Integer, h.k<? extends Integer, ? extends Integer>> {
        final /* synthetic */ List<String> b;

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

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

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

        public final h.k<Integer, Integer> b(CharSequence charSequence, int i2) {
            h.x.d.k.d(charSequence, "$this$$receiver");
            h.k kVarH = q.H(charSequence, this.b, i2, this.f961e, false);
            if (kVarH != null) {
                return h.o.a(kVarH.c(), Integer.valueOf(((String) kVarH.d()).length()));
            }
            return null;
        }
    }

    /* JADX INFO: compiled from: Strings.kt */
    static final class c extends h.x.d.l implements h.x.c.l<h.z.h, String> {
        final /* synthetic */ CharSequence b;

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

        @Override // h.x.c.l
        /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
        public final String invoke(h.z.h hVar) {
            h.x.d.k.d(hVar, "it");
            return q.r0(this.b, hVar);
        }
    }

    public static final boolean B(CharSequence charSequence, char c2, boolean z) {
        h.x.d.k.d(charSequence, "<this>");
        return O(charSequence, c2, 0, z, 2, null) >= 0;
    }

    public static boolean C(CharSequence charSequence, CharSequence charSequence2, boolean z) {
        h.x.d.k.d(charSequence, "<this>");
        h.x.d.k.d(charSequence2, "other");
        if (charSequence2 instanceof String) {
            if (P(charSequence, (String) charSequence2, 0, z, 2, null) >= 0) {
                return true;
            }
        } else if (N(charSequence, charSequence2, 0, charSequence.length(), z, false, 16, null) >= 0) {
            return true;
        }
        return false;
    }

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

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

    public static final boolean F(CharSequence charSequence, CharSequence charSequence2, boolean z) {
        h.x.d.k.d(charSequence, "<this>");
        h.x.d.k.d(charSequence2, "suffix");
        return (!z && (charSequence instanceof String) && (charSequence2 instanceof String)) ? p.l((String) charSequence, (String) charSequence2, false, 2, null) : c0(charSequence, charSequence.length() - charSequence2.length(), charSequence2, 0, charSequence2.length(), z);
    }

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

    /* JADX INFO: Access modifiers changed from: private */
    public static final h.k<Integer, String> H(CharSequence charSequence, Collection<String> collection, int i2, boolean z, boolean z2) {
        Object next;
        Object next2;
        if (!z && collection.size() == 1) {
            String str = (String) h.s.k.E(collection);
            int iP = !z2 ? P(charSequence, str, i2, false, 4, null) : U(charSequence, str, i2, false, 4, null);
            if (iP < 0) {
                return null;
            }
            return h.o.a(Integer.valueOf(iP), str);
        }
        h.z.f hVar = !z2 ? new h.z.h(h.z.n.b(i2, 0), charSequence.length()) : h.z.n.g(h.z.n.d(i2, J(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 (p.p(str2, 0, (String) charSequence, iA, str2.length(), z)) {
                            break;
                        }
                    }
                    String str3 = (String) next2;
                    if (str3 == null) {
                        if (iA == iB) {
                            break;
                        }
                        iA += iC;
                    } else {
                        return h.o.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 (c0(str4, 0, charSequence, iA2, str4.length(), z)) {
                            break;
                        }
                    }
                    String str5 = (String) next;
                    if (str5 == null) {
                        if (iA2 == iB2) {
                            break;
                        }
                        iA2 += iC2;
                    } else {
                        return h.o.a(Integer.valueOf(iA2), str5);
                    }
                }
            }
        }
        return null;
    }

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

    public static final int J(CharSequence charSequence) {
        h.x.d.k.d(charSequence, "<this>");
        return charSequence.length() - 1;
    }

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

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

    private static final int M(CharSequence charSequence, CharSequence charSequence2, int i2, int i3, boolean z, boolean z2) {
        h.z.f hVar = !z2 ? new h.z.h(h.z.n.b(i2, 0), h.z.n.d(i3, charSequence.length())) : h.z.n.g(h.z.n.d(i2, J(charSequence)), h.z.n.b(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 (!p.p((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 (!c0(charSequence2, 0, charSequence, iA2, charSequence2.length(), z)) {
            if (iA2 == iB2) {
                return -1;
            }
            iA2 += iC2;
        }
        return iA2;
    }

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

    public static /* synthetic */ int O(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 K(charSequence, c2, i2, z);
    }

    public static /* synthetic */ int P(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 L(charSequence, str, i2, z);
    }

    public static final int Q(CharSequence charSequence, char[] cArr, int i2, boolean z) {
        boolean z2;
        h.x.d.k.d(charSequence, "<this>");
        h.x.d.k.d(cArr, "chars");
        if (!z && cArr.length == 1 && (charSequence instanceof String)) {
            return ((String) charSequence).indexOf(h.s.h.w(cArr), i2);
        }
        int iB = h.z.n.b(i2, 0);
        int iJ = J(charSequence);
        if (iB > iJ) {
            return -1;
        }
        while (true) {
            char cCharAt = charSequence.charAt(iB);
            int length = cArr.length;
            int i3 = 0;
            while (true) {
                if (i3 >= length) {
                    z2 = false;
                    break;
                }
                if (h.c0.c.d(cArr[i3], cCharAt, z)) {
                    z2 = true;
                    break;
                }
                i3++;
            }
            if (z2) {
                return iB;
            }
            if (iB == iJ) {
                return -1;
            }
            iB++;
        }
    }

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

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

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

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

    public static final int V(CharSequence charSequence, char[] cArr, int i2, boolean z) {
        h.x.d.k.d(charSequence, "<this>");
        h.x.d.k.d(cArr, "chars");
        if (!z && cArr.length == 1 && (charSequence instanceof String)) {
            return ((String) charSequence).lastIndexOf(h.s.h.w(cArr), i2);
        }
        for (int iD = h.z.n.d(i2, J(charSequence)); -1 < iD; iD--) {
            char cCharAt = charSequence.charAt(iD);
            int length = cArr.length;
            boolean z2 = false;
            int i3 = 0;
            while (true) {
                if (i3 >= length) {
                    break;
                }
                if (h.c0.c.d(cArr[i3], cCharAt, z)) {
                    z2 = true;
                    break;
                }
                i3++;
            }
            if (z2) {
                return iD;
            }
        }
        return -1;
    }

    public static final h.b0.d<String> W(CharSequence charSequence) {
        h.x.d.k.d(charSequence, "<this>");
        return o0(charSequence, new String[]{"\r\n", "\n", "\r"}, false, 0, 6, null);
    }

    public static final List<String> X(CharSequence charSequence) {
        h.x.d.k.d(charSequence, "<this>");
        return h.b0.j.j(W(charSequence));
    }

    private static final h.b0.d<h.z.h> Y(CharSequence charSequence, char[] cArr, int i2, boolean z, int i3) {
        h0(i3);
        return new e(charSequence, i2, i3, new a(cArr, z));
    }

    private static final h.b0.d<h.z.h> Z(CharSequence charSequence, String[] strArr, int i2, boolean z, int i3) {
        h0(i3);
        return new e(charSequence, i2, i3, new b(h.s.g.b(strArr), z));
    }

    static /* synthetic */ h.b0.d a0(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 Y(charSequence, cArr, i2, z, i3);
    }

    static /* synthetic */ h.b0.d b0(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 Z(charSequence, strArr, i2, z, i3);
    }

    public static final boolean c0(CharSequence charSequence, int i2, CharSequence charSequence2, int i3, int i4, boolean z) {
        h.x.d.k.d(charSequence, "<this>");
        h.x.d.k.d(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 (!h.c0.c.d(charSequence.charAt(i2 + i5), charSequence2.charAt(i3 + i5), z)) {
                return false;
            }
        }
        return true;
    }

    public static String d0(String str, CharSequence charSequence) {
        h.x.d.k.d(str, "<this>");
        h.x.d.k.d(charSequence, "prefix");
        if (!q0(str, charSequence, false, 2, null)) {
            return str;
        }
        String strSubstring = str.substring(charSequence.length());
        h.x.d.k.c(strSubstring, "this as java.lang.String).substring(startIndex)");
        return strSubstring;
    }

    public static String e0(String str, CharSequence charSequence) {
        h.x.d.k.d(str, "<this>");
        h.x.d.k.d(charSequence, "suffix");
        if (!G(str, charSequence, false, 2, null)) {
            return str;
        }
        String strSubstring = str.substring(0, str.length() - charSequence.length());
        h.x.d.k.c(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public static String f0(String str, CharSequence charSequence) {
        h.x.d.k.d(str, "<this>");
        h.x.d.k.d(charSequence, "delimiter");
        return g0(str, charSequence, charSequence);
    }

    public static final String g0(String str, CharSequence charSequence, CharSequence charSequence2) {
        h.x.d.k.d(str, "<this>");
        h.x.d.k.d(charSequence, "prefix");
        h.x.d.k.d(charSequence2, "suffix");
        if (str.length() < charSequence.length() + charSequence2.length() || !q0(str, charSequence, false, 2, null) || !G(str, charSequence2, false, 2, null)) {
            return str;
        }
        String strSubstring = str.substring(charSequence.length(), str.length() - charSequence2.length());
        h.x.d.k.c(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

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

    public static final List<String> i0(CharSequence charSequence, char[] cArr, boolean z, int i2) {
        h.x.d.k.d(charSequence, "<this>");
        h.x.d.k.d(cArr, "delimiters");
        if (cArr.length == 1) {
            return k0(charSequence, String.valueOf(cArr[0]), z, i2);
        }
        Iterable iterableC = h.b0.j.c(a0(charSequence, cArr, 0, z, i2, 2, null));
        ArrayList arrayList = new ArrayList(h.s.n.o(iterableC, 10));
        Iterator it = iterableC.iterator();
        while (it.hasNext()) {
            arrayList.add(r0(charSequence, (h.z.h) it.next()));
        }
        return arrayList;
    }

    public static final List<String> j0(CharSequence charSequence, String[] strArr, boolean z, int i2) {
        h.x.d.k.d(charSequence, "<this>");
        h.x.d.k.d(strArr, "delimiters");
        if (strArr.length == 1) {
            String str = strArr[0];
            if (!(str.length() == 0)) {
                return k0(charSequence, str, z, i2);
            }
        }
        Iterable iterableC = h.b0.j.c(b0(charSequence, strArr, 0, z, i2, 2, null));
        ArrayList arrayList = new ArrayList(h.s.n.o(iterableC, 10));
        Iterator it = iterableC.iterator();
        while (it.hasNext()) {
            arrayList.add(r0(charSequence, (h.z.h) it.next()));
        }
        return arrayList;
    }

    private static final List<String> k0(CharSequence charSequence, String str, boolean z, int i2) {
        h0(i2);
        int length = 0;
        int iL = L(charSequence, str, 0, z);
        if (iL == -1 || i2 == 1) {
            return h.s.l.b(charSequence.toString());
        }
        boolean z2 = i2 > 0;
        ArrayList arrayList = new ArrayList(z2 ? h.z.n.d(i2, 10) : 10);
        do {
            arrayList.add(charSequence.subSequence(length, iL).toString());
            length = str.length() + iL;
            if (z2 && arrayList.size() == i2 - 1) {
                break;
            }
            iL = L(charSequence, str, length, z);
        } while (iL != -1);
        arrayList.add(charSequence.subSequence(length, charSequence.length()).toString());
        return arrayList;
    }

    public static /* synthetic */ List l0(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 i0(charSequence, cArr, z, i2);
    }

    public static /* synthetic */ List m0(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 j0(charSequence, strArr, z, i2);
    }

    public static final h.b0.d<String> n0(CharSequence charSequence, String[] strArr, boolean z, int i2) {
        h.x.d.k.d(charSequence, "<this>");
        h.x.d.k.d(strArr, "delimiters");
        return h.b0.j.h(b0(charSequence, strArr, 0, z, i2, 2, null), new c(charSequence));
    }

    public static /* synthetic */ h.b0.d o0(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 n0(charSequence, strArr, z, i2);
    }

    public static final boolean p0(CharSequence charSequence, CharSequence charSequence2, boolean z) {
        h.x.d.k.d(charSequence, "<this>");
        h.x.d.k.d(charSequence2, "prefix");
        return (!z && (charSequence instanceof String) && (charSequence2 instanceof String)) ? p.z((String) charSequence, (String) charSequence2, false, 2, null) : c0(charSequence, 0, charSequence2, 0, charSequence2.length(), z);
    }

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

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

    public static final String s0(String str, char c2, String str2) {
        h.x.d.k.d(str, "<this>");
        h.x.d.k.d(str2, "missingDelimiterValue");
        int iT = T(str, c2, 0, false, 6, null);
        if (iT == -1) {
            return str2;
        }
        String strSubstring = str.substring(iT + 1, str.length());
        h.x.d.k.c(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

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

    public static CharSequence u0(CharSequence charSequence) {
        h.x.d.k.d(charSequence, "<this>");
        int length = charSequence.length() - 1;
        int i2 = 0;
        boolean z = false;
        while (i2 <= length) {
            boolean zC = h.c0.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 String v0(String str, char... cArr) {
        h.x.d.k.d(str, "<this>");
        h.x.d.k.d(cArr, "chars");
        int length = str.length() - 1;
        int i2 = 0;
        boolean z = false;
        while (i2 <= length) {
            boolean zO = h.s.h.o(cArr, str.charAt(!z ? i2 : length));
            if (z) {
                if (!zO) {
                    break;
                }
                length--;
            } else if (zO) {
                i2++;
            } else {
                z = true;
            }
        }
        return str.subSequence(i2, length + 1).toString();
    }
}
