package kotlin.text;

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

/* loaded from: classes3.dex */
public abstract class z extends y {

    /* loaded from: classes3.dex */
    public static final class a extends kotlin.jvm.internal.v implements dn.p {

        /* renamed from: p */
        final /* synthetic */ char[] f26538p;

        /* renamed from: q */
        final /* synthetic */ boolean f26539q;

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

        public final rm.v a(CharSequence $receiver, int i10) {
            kotlin.jvm.internal.t.g($receiver, "$this$$receiver");
            int i02 = z.i0($receiver, this.f26538p, i10, this.f26539q);
            if (i02 < 0) {
                return null;
            }
            return rm.c0.a(Integer.valueOf(i02), 1);
        }

        @Override // dn.p
        public /* bridge */ /* synthetic */ Object invoke(Object obj, Object obj2) {
            return a((CharSequence) obj, ((Number) obj2).intValue());
        }
    }

    /* loaded from: classes3.dex */
    public static final class b extends kotlin.jvm.internal.v implements dn.p {

        /* renamed from: p */
        final /* synthetic */ List f26540p;

        /* renamed from: q */
        final /* synthetic */ boolean f26541q;

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

        public final rm.v a(CharSequence $receiver, int i10) {
            kotlin.jvm.internal.t.g($receiver, "$this$$receiver");
            rm.v Z = z.Z($receiver, this.f26540p, i10, this.f26541q, false);
            if (Z != null) {
                return rm.c0.a(Z.c(), Integer.valueOf(((String) Z.d()).length()));
            }
            return null;
        }

        @Override // dn.p
        public /* bridge */ /* synthetic */ Object invoke(Object obj, Object obj2) {
            return a((CharSequence) obj, ((Number) obj2).intValue());
        }
    }

    /* loaded from: classes3.dex */
    public static final class c extends kotlin.jvm.internal.v implements dn.l {

        /* renamed from: p */
        final /* synthetic */ CharSequence f26542p;

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

        @Override // dn.l
        /* renamed from: a */
        public final String invoke(jn.i it) {
            kotlin.jvm.internal.t.g(it, "it");
            return z.P0(this.f26542p, it);
        }
    }

    public static String A0(String str, CharSequence delimiter) {
        kotlin.jvm.internal.t.g(str, "<this>");
        kotlin.jvm.internal.t.g(delimiter, "delimiter");
        return B0(str, delimiter, delimiter);
    }

    public static final String B0(String str, CharSequence prefix, CharSequence suffix) {
        boolean Y;
        kotlin.jvm.internal.t.g(str, "<this>");
        kotlin.jvm.internal.t.g(prefix, "prefix");
        kotlin.jvm.internal.t.g(suffix, "suffix");
        if (str.length() < prefix.length() + suffix.length() || !O0(str, prefix, false, 2, null)) {
            return str;
        }
        Y = Y(str, suffix, false, 2, null);
        if (!Y) {
            return str;
        }
        String substring = str.substring(prefix.length(), str.length() - suffix.length());
        kotlin.jvm.internal.t.f(substring, "substring(...)");
        return substring;
    }

    public static CharSequence C0(CharSequence charSequence, int i10, int i11, CharSequence replacement) {
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        kotlin.jvm.internal.t.g(replacement, "replacement");
        if (i11 >= i10) {
            StringBuilder sb2 = new StringBuilder();
            sb2.append(charSequence, 0, i10);
            kotlin.jvm.internal.t.f(sb2, "append(...)");
            sb2.append(replacement);
            sb2.append(charSequence, i11, charSequence.length());
            kotlin.jvm.internal.t.f(sb2, "append(...)");
            return sb2;
        }
        throw new IndexOutOfBoundsException("End index (" + i11 + ") is less than start index (" + i10 + ").");
    }

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

    public static final List E0(CharSequence charSequence, char[] delimiters, boolean z10, int i10) {
        Iterable l10;
        int v10;
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        kotlin.jvm.internal.t.g(delimiters, "delimiters");
        if (delimiters.length == 1) {
            return G0(charSequence, String.valueOf(delimiters[0]), z10, i10);
        }
        l10 = rp.p.l(u0(charSequence, delimiters, 0, z10, i10, 2, null));
        v10 = sm.v.v(l10, 10);
        ArrayList arrayList = new ArrayList(v10);
        Iterator it = l10.iterator();
        while (it.hasNext()) {
            arrayList.add(P0(charSequence, (jn.i) it.next()));
        }
        return arrayList;
    }

    public static final List F0(CharSequence charSequence, String[] delimiters, boolean z10, int i10) {
        Iterable l10;
        int v10;
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        kotlin.jvm.internal.t.g(delimiters, "delimiters");
        if (delimiters.length == 1) {
            String str = delimiters[0];
            if (!(str.length() == 0)) {
                return G0(charSequence, str, z10, i10);
            }
        }
        l10 = rp.p.l(v0(charSequence, delimiters, 0, z10, i10, 2, null));
        v10 = sm.v.v(l10, 10);
        ArrayList arrayList = new ArrayList(v10);
        Iterator it = l10.iterator();
        while (it.hasNext()) {
            arrayList.add(P0(charSequence, (jn.i) it.next()));
        }
        return arrayList;
    }

    private static final List G0(CharSequence charSequence, String str, boolean z10, int i10) {
        List e10;
        D0(i10);
        int i11 = 0;
        int d02 = d0(charSequence, str, 0, z10);
        if (d02 == -1 || i10 == 1) {
            e10 = sm.t.e(charSequence.toString());
            return e10;
        }
        boolean z11 = i10 > 0;
        ArrayList arrayList = new ArrayList(z11 ? jn.o.g(i10, 10) : 10);
        do {
            arrayList.add(charSequence.subSequence(i11, d02).toString());
            i11 = str.length() + d02;
            if (z11 && arrayList.size() == i10 - 1) {
                break;
            }
            d02 = d0(charSequence, str, i11, z10);
        } while (d02 != -1);
        arrayList.add(charSequence.subSequence(i11, charSequence.length()).toString());
        return arrayList;
    }

    public static /* synthetic */ List H0(CharSequence charSequence, char[] cArr, boolean z10, int i10, int i11, Object obj) {
        if ((i11 & 2) != 0) {
            z10 = false;
        }
        if ((i11 & 4) != 0) {
            i10 = 0;
        }
        return E0(charSequence, cArr, z10, i10);
    }

    public static /* synthetic */ List I0(CharSequence charSequence, String[] strArr, boolean z10, int i10, int i11, Object obj) {
        if ((i11 & 2) != 0) {
            z10 = false;
        }
        if ((i11 & 4) != 0) {
            i10 = 0;
        }
        return F0(charSequence, strArr, z10, i10);
    }

    public static final rp.h J0(CharSequence charSequence, String[] delimiters, boolean z10, int i10) {
        rp.h x10;
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        kotlin.jvm.internal.t.g(delimiters, "delimiters");
        x10 = rp.p.x(v0(charSequence, delimiters, 0, z10, i10, 2, null), new c(charSequence));
        return x10;
    }

    public static /* synthetic */ rp.h K0(CharSequence charSequence, String[] strArr, boolean z10, int i10, int i11, Object obj) {
        if ((i11 & 2) != 0) {
            z10 = false;
        }
        if ((i11 & 4) != 0) {
            i10 = 0;
        }
        return J0(charSequence, strArr, z10, i10);
    }

    public static final boolean L0(CharSequence charSequence, char c10, boolean z10) {
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        return charSequence.length() > 0 && kotlin.text.c.d(charSequence.charAt(0), c10, z10);
    }

    public static final boolean M0(CharSequence charSequence, CharSequence prefix, boolean z10) {
        boolean P;
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        kotlin.jvm.internal.t.g(prefix, "prefix");
        if (z10 || !(charSequence instanceof String) || !(prefix instanceof String)) {
            return w0(charSequence, 0, prefix, 0, prefix.length(), z10);
        }
        P = y.P((String) charSequence, (String) prefix, false, 2, null);
        return P;
    }

    public static /* synthetic */ boolean N0(CharSequence charSequence, char c10, boolean z10, int i10, Object obj) {
        if ((i10 & 2) != 0) {
            z10 = false;
        }
        return L0(charSequence, c10, z10);
    }

    public static /* synthetic */ boolean O0(CharSequence charSequence, CharSequence charSequence2, boolean z10, int i10, Object obj) {
        if ((i10 & 2) != 0) {
            z10 = false;
        }
        return M0(charSequence, charSequence2, z10);
    }

    public static final String P0(CharSequence charSequence, jn.i range) {
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        kotlin.jvm.internal.t.g(range, "range");
        return charSequence.subSequence(range.D().intValue(), range.C().intValue() + 1).toString();
    }

    public static final String Q0(String str, char c10, String missingDelimiterValue) {
        int g02;
        kotlin.jvm.internal.t.g(str, "<this>");
        kotlin.jvm.internal.t.g(missingDelimiterValue, "missingDelimiterValue");
        g02 = g0(str, c10, 0, false, 6, null);
        if (g02 == -1) {
            return missingDelimiterValue;
        }
        String substring = str.substring(g02 + 1, str.length());
        kotlin.jvm.internal.t.f(substring, "substring(...)");
        return substring;
    }

    public static final boolean R(CharSequence charSequence, char c10, boolean z10) {
        int g02;
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        g02 = g0(charSequence, c10, 0, z10, 2, null);
        return g02 >= 0;
    }

    public static String R0(String str, String delimiter, String missingDelimiterValue) {
        int h02;
        kotlin.jvm.internal.t.g(str, "<this>");
        kotlin.jvm.internal.t.g(delimiter, "delimiter");
        kotlin.jvm.internal.t.g(missingDelimiterValue, "missingDelimiterValue");
        h02 = h0(str, delimiter, 0, false, 6, null);
        if (h02 == -1) {
            return missingDelimiterValue;
        }
        String substring = str.substring(h02 + delimiter.length(), str.length());
        kotlin.jvm.internal.t.f(substring, "substring(...)");
        return substring;
    }

    public static boolean S(CharSequence charSequence, CharSequence other, boolean z10) {
        int h02;
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        kotlin.jvm.internal.t.g(other, "other");
        if (other instanceof String) {
            h02 = h0(charSequence, (String) other, 0, z10, 2, null);
            if (h02 >= 0) {
                return true;
            }
        } else if (f0(charSequence, other, 0, charSequence.length(), z10, false, 16, null) >= 0) {
            return true;
        }
        return false;
    }

    public static /* synthetic */ String S0(String str, char c10, String str2, int i10, Object obj) {
        if ((i10 & 2) != 0) {
            str2 = str;
        }
        return Q0(str, c10, str2);
    }

    public static /* synthetic */ boolean T(CharSequence charSequence, char c10, boolean z10, int i10, Object obj) {
        if ((i10 & 2) != 0) {
            z10 = false;
        }
        return R(charSequence, c10, z10);
    }

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

    public static /* synthetic */ boolean U(CharSequence charSequence, CharSequence charSequence2, boolean z10, int i10, Object obj) {
        boolean S;
        if ((i10 & 2) != 0) {
            z10 = false;
        }
        S = S(charSequence, charSequence2, z10);
        return S;
    }

    public static String U0(String str, char c10, String missingDelimiterValue) {
        int l02;
        kotlin.jvm.internal.t.g(str, "<this>");
        kotlin.jvm.internal.t.g(missingDelimiterValue, "missingDelimiterValue");
        l02 = l0(str, c10, 0, false, 6, null);
        if (l02 == -1) {
            return missingDelimiterValue;
        }
        String substring = str.substring(l02 + 1, str.length());
        kotlin.jvm.internal.t.f(substring, "substring(...)");
        return substring;
    }

    public static final boolean V(CharSequence charSequence, char c10, boolean z10) {
        int b02;
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        if (charSequence.length() > 0) {
            b02 = b0(charSequence);
            if (kotlin.text.c.d(charSequence.charAt(b02), c10, z10)) {
                return true;
            }
        }
        return false;
    }

    public static final String V0(String str, String delimiter, String missingDelimiterValue) {
        int m02;
        kotlin.jvm.internal.t.g(str, "<this>");
        kotlin.jvm.internal.t.g(delimiter, "delimiter");
        kotlin.jvm.internal.t.g(missingDelimiterValue, "missingDelimiterValue");
        m02 = m0(str, delimiter, 0, false, 6, null);
        if (m02 == -1) {
            return missingDelimiterValue;
        }
        String substring = str.substring(m02 + delimiter.length(), str.length());
        kotlin.jvm.internal.t.f(substring, "substring(...)");
        return substring;
    }

    public static final boolean W(CharSequence charSequence, CharSequence suffix, boolean z10) {
        boolean y10;
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        kotlin.jvm.internal.t.g(suffix, "suffix");
        if (z10 || !(charSequence instanceof String) || !(suffix instanceof String)) {
            return w0(charSequence, charSequence.length() - suffix.length(), suffix, 0, suffix.length(), z10);
        }
        y10 = y.y((String) charSequence, (String) suffix, false, 2, null);
        return y10;
    }

    public static /* synthetic */ String W0(String str, char c10, String str2, int i10, Object obj) {
        String U0;
        if ((i10 & 2) != 0) {
            str2 = str;
        }
        U0 = U0(str, c10, str2);
        return U0;
    }

    public static /* synthetic */ boolean X(CharSequence charSequence, char c10, boolean z10, int i10, Object obj) {
        if ((i10 & 2) != 0) {
            z10 = false;
        }
        return V(charSequence, c10, z10);
    }

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

    public static /* synthetic */ boolean Y(CharSequence charSequence, CharSequence charSequence2, boolean z10, int i10, Object obj) {
        if ((i10 & 2) != 0) {
            z10 = false;
        }
        return W(charSequence, charSequence2, z10);
    }

    public static final String Y0(String str, char c10, String missingDelimiterValue) {
        int g02;
        kotlin.jvm.internal.t.g(str, "<this>");
        kotlin.jvm.internal.t.g(missingDelimiterValue, "missingDelimiterValue");
        g02 = g0(str, c10, 0, false, 6, null);
        if (g02 == -1) {
            return missingDelimiterValue;
        }
        String substring = str.substring(0, g02);
        kotlin.jvm.internal.t.f(substring, "substring(...)");
        return substring;
    }

    public static final rm.v Z(CharSequence charSequence, Collection collection, int i10, boolean z10, boolean z11) {
        int b02;
        int g10;
        jn.g m10;
        Object obj;
        Object obj2;
        boolean D;
        int d10;
        Object C0;
        if (!z10 && collection.size() == 1) {
            C0 = sm.c0.C0(collection);
            String str = (String) C0;
            int h02 = !z11 ? h0(charSequence, str, i10, false, 4, null) : m0(charSequence, str, i10, false, 4, null);
            if (h02 < 0) {
                return null;
            }
            return rm.c0.a(Integer.valueOf(h02), str);
        }
        if (z11) {
            b02 = b0(charSequence);
            g10 = jn.o.g(i10, b02);
            m10 = jn.o.m(g10, 0);
        } else {
            d10 = jn.o.d(i10, 0);
            m10 = new jn.i(d10, charSequence.length());
        }
        if (charSequence instanceof String) {
            int g11 = m10.g();
            int m11 = m10.m();
            int r10 = m10.r();
            if ((r10 > 0 && g11 <= m11) || (r10 < 0 && m11 <= g11)) {
                while (true) {
                    Iterator it = collection.iterator();
                    while (true) {
                        if (!it.hasNext()) {
                            obj2 = null;
                            break;
                        }
                        obj2 = it.next();
                        String str2 = (String) obj2;
                        D = y.D(str2, 0, (String) charSequence, g11, str2.length(), z10);
                        if (D) {
                            break;
                        }
                    }
                    String str3 = (String) obj2;
                    if (str3 == null) {
                        if (g11 == m11) {
                            break;
                        }
                        g11 += r10;
                    } else {
                        return rm.c0.a(Integer.valueOf(g11), str3);
                    }
                }
            }
        } else {
            int g12 = m10.g();
            int m12 = m10.m();
            int r11 = m10.r();
            if ((r11 > 0 && g12 <= m12) || (r11 < 0 && m12 <= g12)) {
                while (true) {
                    Iterator it2 = collection.iterator();
                    while (true) {
                        if (!it2.hasNext()) {
                            obj = null;
                            break;
                        }
                        obj = it2.next();
                        String str4 = (String) obj;
                        if (w0(str4, 0, charSequence, g12, str4.length(), z10)) {
                            break;
                        }
                    }
                    String str5 = (String) obj;
                    if (str5 == null) {
                        if (g12 == m12) {
                            break;
                        }
                        g12 += r11;
                    } else {
                        return rm.c0.a(Integer.valueOf(g12), str5);
                    }
                }
            }
        }
        return null;
    }

    public static final String Z0(String str, String delimiter, String missingDelimiterValue) {
        int h02;
        kotlin.jvm.internal.t.g(str, "<this>");
        kotlin.jvm.internal.t.g(delimiter, "delimiter");
        kotlin.jvm.internal.t.g(missingDelimiterValue, "missingDelimiterValue");
        h02 = h0(str, delimiter, 0, false, 6, null);
        if (h02 == -1) {
            return missingDelimiterValue;
        }
        String substring = str.substring(0, h02);
        kotlin.jvm.internal.t.f(substring, "substring(...)");
        return substring;
    }

    public static jn.i a0(CharSequence charSequence) {
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        return new jn.i(0, charSequence.length() - 1);
    }

    public static /* synthetic */ String a1(String str, char c10, String str2, int i10, Object obj) {
        if ((i10 & 2) != 0) {
            str2 = str;
        }
        return Y0(str, c10, str2);
    }

    public static int b0(CharSequence charSequence) {
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        return charSequence.length() - 1;
    }

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

    public static final int c0(CharSequence charSequence, char c10, int i10, boolean z10) {
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        return (z10 || !(charSequence instanceof String)) ? i0(charSequence, new char[]{c10}, i10, z10) : ((String) charSequence).indexOf(c10, i10);
    }

    public static String c1(String str, String delimiter, String missingDelimiterValue) {
        int m02;
        kotlin.jvm.internal.t.g(str, "<this>");
        kotlin.jvm.internal.t.g(delimiter, "delimiter");
        kotlin.jvm.internal.t.g(missingDelimiterValue, "missingDelimiterValue");
        m02 = m0(str, delimiter, 0, false, 6, null);
        if (m02 == -1) {
            return missingDelimiterValue;
        }
        String substring = str.substring(0, m02);
        kotlin.jvm.internal.t.f(substring, "substring(...)");
        return substring;
    }

    public static final int d0(CharSequence charSequence, String string, int i10, boolean z10) {
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        kotlin.jvm.internal.t.g(string, "string");
        return (z10 || !(charSequence instanceof String)) ? f0(charSequence, string, i10, charSequence.length(), z10, false, 16, null) : ((String) charSequence).indexOf(string, i10);
    }

    public static /* synthetic */ String d1(String str, String str2, String str3, int i10, Object obj) {
        String c12;
        if ((i10 & 2) != 0) {
            str3 = str;
        }
        c12 = c1(str, str2, str3);
        return c12;
    }

    private static final int e0(CharSequence charSequence, CharSequence charSequence2, int i10, int i11, boolean z10, boolean z11) {
        int b02;
        int g10;
        int d10;
        jn.g m10;
        boolean D;
        int d11;
        int g11;
        if (z11) {
            b02 = b0(charSequence);
            g10 = jn.o.g(i10, b02);
            d10 = jn.o.d(i11, 0);
            m10 = jn.o.m(g10, d10);
        } else {
            d11 = jn.o.d(i10, 0);
            g11 = jn.o.g(i11, charSequence.length());
            m10 = new jn.i(d11, g11);
        }
        if (!(charSequence instanceof String) || !(charSequence2 instanceof String)) {
            int g12 = m10.g();
            int m11 = m10.m();
            int r10 = m10.r();
            if ((r10 <= 0 || g12 > m11) && (r10 >= 0 || m11 > g12)) {
                return -1;
            }
            while (!w0(charSequence2, 0, charSequence, g12, charSequence2.length(), z10)) {
                if (g12 == m11) {
                    return -1;
                }
                g12 += r10;
            }
            return g12;
        }
        int g13 = m10.g();
        int m12 = m10.m();
        int r11 = m10.r();
        if ((r11 <= 0 || g13 > m12) && (r11 >= 0 || m12 > g13)) {
            return -1;
        }
        while (true) {
            D = y.D((String) charSequence2, 0, (String) charSequence, g13, charSequence2.length(), z10);
            if (D) {
                return g13;
            }
            if (g13 == m12) {
                return -1;
            }
            g13 += r11;
        }
    }

    public static CharSequence e1(CharSequence charSequence) {
        boolean c10;
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        int length = charSequence.length() - 1;
        int i10 = 0;
        boolean z10 = false;
        while (i10 <= length) {
            c10 = kotlin.text.b.c(charSequence.charAt(!z10 ? i10 : length));
            if (z10) {
                if (!c10) {
                    break;
                }
                length--;
            } else if (c10) {
                i10++;
            } else {
                z10 = true;
            }
        }
        return charSequence.subSequence(i10, length + 1);
    }

    static /* synthetic */ int f0(CharSequence charSequence, CharSequence charSequence2, int i10, int i11, boolean z10, boolean z11, int i12, Object obj) {
        if ((i12 & 16) != 0) {
            z11 = false;
        }
        return e0(charSequence, charSequence2, i10, i11, z10, z11);
    }

    public static CharSequence f1(CharSequence charSequence, char... chars) {
        boolean K;
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        kotlin.jvm.internal.t.g(chars, "chars");
        int length = charSequence.length() - 1;
        if (length >= 0) {
            while (true) {
                int i10 = length - 1;
                K = sm.p.K(chars, charSequence.charAt(length));
                if (!K) {
                    return charSequence.subSequence(0, length + 1);
                }
                if (i10 < 0) {
                    break;
                }
                length = i10;
            }
        }
        return "";
    }

    public static /* synthetic */ int g0(CharSequence charSequence, char c10, int i10, boolean z10, int i11, Object obj) {
        if ((i11 & 2) != 0) {
            i10 = 0;
        }
        if ((i11 & 4) != 0) {
            z10 = false;
        }
        return c0(charSequence, c10, i10, z10);
    }

    public static String g1(String str, char... chars) {
        CharSequence charSequence;
        boolean K;
        kotlin.jvm.internal.t.g(str, "<this>");
        kotlin.jvm.internal.t.g(chars, "chars");
        int length = str.length() - 1;
        if (length >= 0) {
            while (true) {
                int i10 = length - 1;
                K = sm.p.K(chars, str.charAt(length));
                if (!K) {
                    charSequence = str.subSequence(0, length + 1);
                    break;
                }
                if (i10 < 0) {
                    break;
                }
                length = i10;
            }
            return charSequence.toString();
        }
        charSequence = "";
        return charSequence.toString();
    }

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

    public static CharSequence h1(CharSequence charSequence) {
        boolean c10;
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        int length = charSequence.length();
        for (int i10 = 0; i10 < length; i10++) {
            c10 = kotlin.text.b.c(charSequence.charAt(i10));
            if (!c10) {
                return charSequence.subSequence(i10, charSequence.length());
            }
        }
        return "";
    }

    public static final int i0(CharSequence charSequence, char[] chars, int i10, boolean z10) {
        int d10;
        int b02;
        boolean z11;
        char u02;
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        kotlin.jvm.internal.t.g(chars, "chars");
        if (!z10 && chars.length == 1 && (charSequence instanceof String)) {
            u02 = sm.p.u0(chars);
            return ((String) charSequence).indexOf(u02, i10);
        }
        d10 = jn.o.d(i10, 0);
        b02 = b0(charSequence);
        k0 it = new jn.i(d10, b02).iterator();
        while (it.hasNext()) {
            int a10 = it.a();
            char charAt = charSequence.charAt(a10);
            int length = chars.length;
            int i11 = 0;
            while (true) {
                if (i11 >= length) {
                    z11 = false;
                    break;
                }
                if (kotlin.text.c.d(chars[i11], charAt, z10)) {
                    z11 = true;
                    break;
                }
                i11++;
            }
            if (z11) {
                return a10;
            }
        }
        return -1;
    }

    public static final int j0(CharSequence charSequence, char c10, int i10, boolean z10) {
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        return (z10 || !(charSequence instanceof String)) ? n0(charSequence, new char[]{c10}, i10, z10) : ((String) charSequence).lastIndexOf(c10, i10);
    }

    public static final int k0(CharSequence charSequence, String string, int i10, boolean z10) {
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        kotlin.jvm.internal.t.g(string, "string");
        return (z10 || !(charSequence instanceof String)) ? e0(charSequence, string, i10, 0, z10, true) : ((String) charSequence).lastIndexOf(string, i10);
    }

    public static /* synthetic */ int l0(CharSequence charSequence, char c10, int i10, boolean z10, int i11, Object obj) {
        if ((i11 & 2) != 0) {
            i10 = b0(charSequence);
        }
        if ((i11 & 4) != 0) {
            z10 = false;
        }
        return j0(charSequence, c10, i10, z10);
    }

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

    public static final int n0(CharSequence charSequence, char[] chars, int i10, boolean z10) {
        int b02;
        int g10;
        char u02;
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        kotlin.jvm.internal.t.g(chars, "chars");
        if (!z10 && chars.length == 1 && (charSequence instanceof String)) {
            u02 = sm.p.u0(chars);
            return ((String) charSequence).lastIndexOf(u02, i10);
        }
        b02 = b0(charSequence);
        for (g10 = jn.o.g(i10, b02); -1 < g10; g10--) {
            char charAt = charSequence.charAt(g10);
            int length = chars.length;
            boolean z11 = false;
            int i11 = 0;
            while (true) {
                if (i11 >= length) {
                    break;
                }
                if (kotlin.text.c.d(chars[i11], charAt, z10)) {
                    z11 = true;
                    break;
                }
                i11++;
            }
            if (z11) {
                return g10;
            }
        }
        return -1;
    }

    public static final rp.h o0(CharSequence charSequence) {
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        return K0(charSequence, new String[]{"\r\n", "\n", "\r"}, false, 0, 6, null);
    }

    public static final List p0(CharSequence charSequence) {
        List E;
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        E = rp.p.E(o0(charSequence));
        return E;
    }

    public static final CharSequence q0(CharSequence charSequence, int i10, char c10) {
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        if (i10 < 0) {
            throw new IllegalArgumentException("Desired length " + i10 + " is less than zero.");
        }
        if (i10 <= charSequence.length()) {
            return charSequence.subSequence(0, charSequence.length());
        }
        StringBuilder sb2 = new StringBuilder(i10);
        k0 it = new jn.i(1, i10 - charSequence.length()).iterator();
        while (it.hasNext()) {
            it.a();
            sb2.append(c10);
        }
        sb2.append(charSequence);
        return sb2;
    }

    public static String r0(String str, int i10, char c10) {
        kotlin.jvm.internal.t.g(str, "<this>");
        return q0(str, i10, c10).toString();
    }

    private static final rp.h s0(CharSequence charSequence, char[] cArr, int i10, boolean z10, int i11) {
        D0(i11);
        return new e(charSequence, i10, i11, new a(cArr, z10));
    }

    private static final rp.h t0(CharSequence charSequence, String[] strArr, int i10, boolean z10, int i11) {
        List d10;
        D0(i11);
        d10 = sm.o.d(strArr);
        return new e(charSequence, i10, i11, new b(d10, z10));
    }

    static /* synthetic */ rp.h u0(CharSequence charSequence, char[] cArr, int i10, boolean z10, int i11, int i12, Object obj) {
        if ((i12 & 2) != 0) {
            i10 = 0;
        }
        if ((i12 & 4) != 0) {
            z10 = false;
        }
        if ((i12 & 8) != 0) {
            i11 = 0;
        }
        return s0(charSequence, cArr, i10, z10, i11);
    }

    static /* synthetic */ rp.h v0(CharSequence charSequence, String[] strArr, int i10, boolean z10, int i11, int i12, Object obj) {
        if ((i12 & 2) != 0) {
            i10 = 0;
        }
        if ((i12 & 4) != 0) {
            z10 = false;
        }
        if ((i12 & 8) != 0) {
            i11 = 0;
        }
        return t0(charSequence, strArr, i10, z10, i11);
    }

    public static final boolean w0(CharSequence charSequence, int i10, CharSequence other, int i11, int i12, boolean z10) {
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        kotlin.jvm.internal.t.g(other, "other");
        if (i11 < 0 || i10 < 0 || i10 > charSequence.length() - i12 || i11 > other.length() - i12) {
            return false;
        }
        for (int i13 = 0; i13 < i12; i13++) {
            if (!kotlin.text.c.d(charSequence.charAt(i10 + i13), other.charAt(i11 + i13), z10)) {
                return false;
            }
        }
        return true;
    }

    public static String x0(String str, CharSequence prefix) {
        kotlin.jvm.internal.t.g(str, "<this>");
        kotlin.jvm.internal.t.g(prefix, "prefix");
        if (!O0(str, prefix, false, 2, null)) {
            return str;
        }
        String substring = str.substring(prefix.length());
        kotlin.jvm.internal.t.f(substring, "substring(...)");
        return substring;
    }

    public static CharSequence y0(CharSequence charSequence, int i10, int i11) {
        kotlin.jvm.internal.t.g(charSequence, "<this>");
        if (i11 < i10) {
            throw new IndexOutOfBoundsException("End index (" + i11 + ") is less than start index (" + i10 + ").");
        }
        if (i11 == i10) {
            return charSequence.subSequence(0, charSequence.length());
        }
        StringBuilder sb2 = new StringBuilder(charSequence.length() - (i11 - i10));
        sb2.append(charSequence, 0, i10);
        kotlin.jvm.internal.t.f(sb2, "append(...)");
        sb2.append(charSequence, i11, charSequence.length());
        kotlin.jvm.internal.t.f(sb2, "append(...)");
        return sb2;
    }

    public static String z0(String str, CharSequence suffix) {
        boolean Y;
        kotlin.jvm.internal.t.g(str, "<this>");
        kotlin.jvm.internal.t.g(suffix, "suffix");
        Y = Y(str, suffix, false, 2, null);
        if (!Y) {
            return str;
        }
        String substring = str.substring(0, str.length() - suffix.length());
        kotlin.jvm.internal.t.f(substring, "substring(...)");
        return substring;
    }
}
