package c.u;

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 o extends n {

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

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

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

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

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

        public final c.d<Integer, Integer> b(CharSequence charSequence, int i) {
            c.q.d.j.c(charSequence, "$receiver");
            int I = o.I(charSequence, this.f1486b, i, this.f1487c);
            if (I < 0) {
                return null;
            }
            return c.g.a(Integer.valueOf(I), 1);
        }
    }

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

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ List f1488b;

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

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

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

        public final c.d<Integer, Integer> b(CharSequence charSequence, int i) {
            c.q.d.j.c(charSequence, "$receiver");
            c.d dVarZ = o.z(charSequence, this.f1488b, i, this.f1489c, false);
            if (dVarZ != null) {
                return c.g.a(dVarZ.c(), Integer.valueOf(((String) dVarZ.d()).length()));
            }
            return null;
        }
    }

    /* JADX INFO: compiled from: Strings.kt */
    static final class c extends c.q.d.k implements c.q.c.b<c.r.c, String> {

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

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

        @Override // c.q.c.b
        /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
        public final String invoke(c.r.c cVar) {
            c.q.d.j.c(cVar, "it");
            return o.f0(this.f1490b, cVar);
        }
    }

    /* JADX INFO: compiled from: Strings.kt */
    static final class d extends c.q.d.k implements c.q.c.b<c.r.c, String> {

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

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

        @Override // c.q.c.b
        /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
        public final String invoke(c.r.c cVar) {
            c.q.d.j.c(cVar, "it");
            return o.f0(this.f1491b, cVar);
        }
    }

    public static final c.r.c A(CharSequence charSequence) {
        c.q.d.j.c(charSequence, "$this$indices");
        return new c.r.c(0, charSequence.length() - 1);
    }

    public static final int B(CharSequence charSequence) {
        c.q.d.j.c(charSequence, "$this$lastIndex");
        return charSequence.length() - 1;
    }

    public static final int C(CharSequence charSequence, char c2, int i, boolean z) {
        c.q.d.j.c(charSequence, "$this$indexOf");
        return (z || !(charSequence instanceof String)) ? I(charSequence, new char[]{c2}, i, z) : ((String) charSequence).indexOf(c2, i);
    }

    public static final int D(CharSequence charSequence, String str, int i, boolean z) {
        c.q.d.j.c(charSequence, "$this$indexOf");
        c.q.d.j.c(str, "string");
        return (z || !(charSequence instanceof String)) ? F(charSequence, str, i, charSequence.length(), z, false, 16, null) : ((String) charSequence).indexOf(str, i);
    }

    private static final int E(CharSequence charSequence, CharSequence charSequence2, int i, int i2, boolean z, boolean z2) {
        c.r.a cVar = !z2 ? new c.r.c(c.r.g.b(i, 0), c.r.g.c(i2, charSequence.length())) : c.r.g.e(c.r.g.c(i, B(charSequence)), c.r.g.b(i2, 0));
        if ((charSequence instanceof String) && (charSequence2 instanceof String)) {
            int iA = cVar.a();
            int iB = cVar.b();
            int iC = cVar.c();
            if (iC >= 0) {
                if (iA > iB) {
                    return -1;
                }
            } else if (iA < iB) {
                return -1;
            }
            while (!n.k((String) charSequence2, 0, (String) charSequence, iA, charSequence2.length(), z)) {
                if (iA == iB) {
                    return -1;
                }
                iA += iC;
            }
            return iA;
        }
        int iA2 = cVar.a();
        int iB2 = cVar.b();
        int iC2 = cVar.c();
        if (iC2 >= 0) {
            if (iA2 > iB2) {
                return -1;
            }
        } else if (iA2 < iB2) {
            return -1;
        }
        while (!U(charSequence2, 0, charSequence, iA2, charSequence2.length(), z)) {
            if (iA2 == iB2) {
                return -1;
            }
            iA2 += iC2;
        }
        return iA2;
    }

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

    public static /* synthetic */ int G(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 C(charSequence, c2, i, z);
    }

    public static /* synthetic */ int H(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 D(charSequence, str, i, z);
    }

    public static final int I(CharSequence charSequence, char[] cArr, int i, boolean z) {
        boolean z2;
        c.q.d.j.c(charSequence, "$this$indexOfAny");
        c.q.d.j.c(cArr, "chars");
        if (!z && cArr.length == 1 && (charSequence instanceof String)) {
            return ((String) charSequence).indexOf(c.l.f.i(cArr), i);
        }
        int iB = c.r.g.b(i, 0);
        int iB2 = B(charSequence);
        if (iB > iB2) {
            return -1;
        }
        while (true) {
            char cCharAt = charSequence.charAt(iB);
            int length = cArr.length;
            int i2 = 0;
            while (true) {
                if (i2 >= length) {
                    z2 = false;
                    break;
                }
                if (c.u.b.b(cArr[i2], cCharAt, z)) {
                    z2 = true;
                    break;
                }
                i2++;
            }
            if (z2) {
                return iB;
            }
            if (iB == iB2) {
                return -1;
            }
            iB++;
        }
    }

    public static final int J(CharSequence charSequence, char c2, int i, boolean z) {
        c.q.d.j.c(charSequence, "$this$lastIndexOf");
        return (z || !(charSequence instanceof String)) ? N(charSequence, new char[]{c2}, i, z) : ((String) charSequence).lastIndexOf(c2, i);
    }

    public static final int K(CharSequence charSequence, String str, int i, boolean z) {
        c.q.d.j.c(charSequence, "$this$lastIndexOf");
        c.q.d.j.c(str, "string");
        return (z || !(charSequence instanceof String)) ? E(charSequence, str, i, 0, z, true) : ((String) charSequence).lastIndexOf(str, i);
    }

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

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

    public static final int N(CharSequence charSequence, char[] cArr, int i, boolean z) {
        c.q.d.j.c(charSequence, "$this$lastIndexOfAny");
        c.q.d.j.c(cArr, "chars");
        if (!z && cArr.length == 1 && (charSequence instanceof String)) {
            return ((String) charSequence).lastIndexOf(c.l.f.i(cArr), i);
        }
        for (int iC = c.r.g.c(i, B(charSequence)); iC >= 0; iC--) {
            char cCharAt = charSequence.charAt(iC);
            int length = cArr.length;
            boolean z2 = false;
            int i2 = 0;
            while (true) {
                if (i2 >= length) {
                    break;
                }
                if (c.u.b.b(cArr[i2], cCharAt, z)) {
                    z2 = true;
                    break;
                }
                i2++;
            }
            if (z2) {
                return iC;
            }
        }
        return -1;
    }

    public static final c.t.c<String> O(CharSequence charSequence) {
        c.q.d.j.c(charSequence, "$this$lineSequence");
        return c0(charSequence, new String[]{"\r\n", "\n", "\r"}, false, 0, 6, null);
    }

    public static final List<String> P(CharSequence charSequence) {
        c.q.d.j.c(charSequence, "$this$lines");
        return c.t.i.h(O(charSequence));
    }

    private static final c.t.c<c.r.c> Q(CharSequence charSequence, char[] cArr, int i, boolean z, int i2) {
        if (i2 >= 0) {
            return new c.u.d(charSequence, i, i2, new a(cArr, z));
        }
        throw new IllegalArgumentException(("Limit must be non-negative, but was " + i2 + '.').toString());
    }

    private static final c.t.c<c.r.c> R(CharSequence charSequence, String[] strArr, int i, boolean z, int i2) {
        if (i2 >= 0) {
            return new c.u.d(charSequence, i, i2, new b(c.l.e.a(strArr), z));
        }
        throw new IllegalArgumentException(("Limit must be non-negative, but was " + i2 + '.').toString());
    }

    static /* synthetic */ c.t.c S(CharSequence charSequence, char[] cArr, 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, cArr, i, z, i2);
    }

    static /* synthetic */ c.t.c T(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 R(charSequence, strArr, i, z, i2);
    }

    public static final boolean U(CharSequence charSequence, int i, CharSequence charSequence2, int i2, int i3, boolean z) {
        c.q.d.j.c(charSequence, "$this$regionMatchesImpl");
        c.q.d.j.c(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.u.b.b(charSequence.charAt(i + i4), charSequence2.charAt(i2 + i4), z)) {
                return false;
            }
        }
        return true;
    }

    public static String V(String str, CharSequence charSequence) {
        c.q.d.j.c(str, "$this$removePrefix");
        c.q.d.j.c(charSequence, "prefix");
        if (!e0(str, charSequence, false, 2, null)) {
            return str;
        }
        String strSubstring = str.substring(charSequence.length());
        c.q.d.j.b(strSubstring, "(this as java.lang.String).substring(startIndex)");
        return strSubstring;
    }

    public static final List<String> W(CharSequence charSequence, char[] cArr, boolean z, int i) {
        c.q.d.j.c(charSequence, "$this$split");
        c.q.d.j.c(cArr, "delimiters");
        if (cArr.length == 1) {
            return X(charSequence, String.valueOf(cArr[0]), z, i);
        }
        Iterable iterableA = c.t.i.a(S(charSequence, cArr, 0, z, i, 2, null));
        ArrayList arrayList = new ArrayList(c.l.k.m(iterableA, 10));
        Iterator it = iterableA.iterator();
        while (it.hasNext()) {
            arrayList.add(f0(charSequence, (c.r.c) it.next()));
        }
        return arrayList;
    }

    private static final List<String> X(CharSequence charSequence, String str, boolean z, int i) {
        int length = 0;
        if (!(i >= 0)) {
            throw new IllegalArgumentException(("Limit must be non-negative, but was " + i + '.').toString());
        }
        int iD = D(charSequence, str, 0, z);
        if (iD == -1 || i == 1) {
            return c.l.i.b(charSequence.toString());
        }
        boolean z2 = i > 0;
        ArrayList arrayList = new ArrayList(z2 ? c.r.g.c(i, 10) : 10);
        do {
            arrayList.add(charSequence.subSequence(length, iD).toString());
            length = str.length() + iD;
            if (z2 && arrayList.size() == i - 1) {
                break;
            }
            iD = D(charSequence, str, length, z);
        } while (iD != -1);
        arrayList.add(charSequence.subSequence(length, charSequence.length()).toString());
        return arrayList;
    }

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

    public static final c.t.c<String> Z(CharSequence charSequence, char[] cArr, boolean z, int i) {
        c.q.d.j.c(charSequence, "$this$splitToSequence");
        c.q.d.j.c(cArr, "delimiters");
        return c.t.i.f(S(charSequence, cArr, 0, z, i, 2, null), new d(charSequence));
    }

    public static final c.t.c<String> a0(CharSequence charSequence, String[] strArr, boolean z, int i) {
        c.q.d.j.c(charSequence, "$this$splitToSequence");
        c.q.d.j.c(strArr, "delimiters");
        return c.t.i.f(T(charSequence, strArr, 0, z, i, 2, null), new c(charSequence));
    }

    public static /* synthetic */ c.t.c b0(CharSequence charSequence, char[] cArr, boolean z, int i, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            z = false;
        }
        if ((i2 & 4) != 0) {
            i = 0;
        }
        return Z(charSequence, cArr, z, i);
    }

    public static /* synthetic */ c.t.c c0(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 a0(charSequence, strArr, z, i);
    }

    public static final boolean d0(CharSequence charSequence, CharSequence charSequence2, boolean z) {
        c.q.d.j.c(charSequence, "$this$startsWith");
        c.q.d.j.c(charSequence2, "prefix");
        return (!z && (charSequence instanceof String) && (charSequence2 instanceof String)) ? n.t((String) charSequence, (String) charSequence2, false, 2, null) : U(charSequence, 0, charSequence2, 0, charSequence2.length(), z);
    }

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

    public static final String f0(CharSequence charSequence, c.r.c cVar) {
        c.q.d.j.c(charSequence, "$this$substring");
        c.q.d.j.c(cVar, "range");
        return charSequence.subSequence(cVar.g().intValue(), cVar.f().intValue() + 1).toString();
    }

    public static CharSequence g0(CharSequence charSequence) {
        c.q.d.j.c(charSequence, "$this$trim");
        int length = charSequence.length() - 1;
        int i = 0;
        boolean z = false;
        while (i <= length) {
            boolean zA = c.u.a.a(charSequence.charAt(!z ? i : length));
            if (z) {
                if (!zA) {
                    break;
                }
                length--;
            } else if (zA) {
                i++;
            } else {
                z = true;
            }
        }
        return charSequence.subSequence(i, length + 1);
    }

    public static final boolean v(CharSequence charSequence, char c2, boolean z) {
        c.q.d.j.c(charSequence, "$this$contains");
        return G(charSequence, c2, 0, z, 2, null) >= 0;
    }

    public static final boolean w(CharSequence charSequence, CharSequence charSequence2, boolean z) {
        c.q.d.j.c(charSequence, "$this$contains");
        c.q.d.j.c(charSequence2, "other");
        if (charSequence2 instanceof String) {
            if (H(charSequence, (String) charSequence2, 0, z, 2, null) >= 0) {
                return true;
            }
        } else if (F(charSequence, charSequence2, 0, charSequence.length(), z, false, 16, null) >= 0) {
            return true;
        }
        return false;
    }

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

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

    /* JADX INFO: Access modifiers changed from: private */
    public static final c.d<Integer, String> z(CharSequence charSequence, Collection<String> collection, int i, boolean z, boolean z2) {
        Object next;
        Object next2;
        if (!z && collection.size() == 1) {
            String str = (String) c.l.h.v(collection);
            int iH = !z2 ? H(charSequence, str, i, false, 4, null) : M(charSequence, str, i, false, 4, null);
            if (iH < 0) {
                return null;
            }
            return c.g.a(Integer.valueOf(iH), str);
        }
        c.r.a cVar = !z2 ? new c.r.c(c.r.g.b(i, 0), charSequence.length()) : c.r.g.e(c.r.g.c(i, B(charSequence)), 0);
        if (charSequence instanceof String) {
            int iA = cVar.a();
            int iB = cVar.b();
            int iC = cVar.c();
            if (iC < 0 ? iA >= iB : iA <= iB) {
                while (true) {
                    Iterator<T> it = collection.iterator();
                    while (true) {
                        if (!it.hasNext()) {
                            next2 = null;
                            break;
                        }
                        next2 = it.next();
                        String str2 = (String) next2;
                        if (n.k(str2, 0, (String) charSequence, iA, str2.length(), z)) {
                            break;
                        }
                    }
                    String str3 = (String) next2;
                    if (str3 == null) {
                        if (iA == iB) {
                            break;
                        }
                        iA += iC;
                    } else {
                        return c.g.a(Integer.valueOf(iA), str3);
                    }
                }
            }
        } else {
            int iA2 = cVar.a();
            int iB2 = cVar.b();
            int iC2 = cVar.c();
            if (iC2 < 0 ? iA2 >= iB2 : iA2 <= iB2) {
                while (true) {
                    Iterator<T> it2 = collection.iterator();
                    while (true) {
                        if (!it2.hasNext()) {
                            next = null;
                            break;
                        }
                        next = it2.next();
                        String str4 = (String) next;
                        if (U(str4, 0, charSequence, iA2, str4.length(), z)) {
                            break;
                        }
                    }
                    String str5 = (String) next;
                    if (str5 == null) {
                        if (iA2 == iB2) {
                            break;
                        }
                        iA2 += iC2;
                    } else {
                        return c.g.a(Integer.valueOf(iA2), str5);
                    }
                }
            }
        }
        return null;
    }
}
