package kotlin.text;

import g.h.a.i;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import kotlin.Metadata;
import kotlin.UInt;
import kotlin.ULong;
import kotlin.collections.IntIterator;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.Lambda;
import kotlin.jvm.internal.o;
import kotlin.ranges.IntProgression;
import kotlin.ranges.IntProgressionIterator;
import kotlin.ranges.IntRange;
import kotlin.reflect.w.internal.y0.n.c2.c;
import kotlin.sequences.Sequence;
import kotlin.sequences.q;

/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u0000\u001e\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u000e\n\u0002\b\u0003\n\u0002\u0010\b\n\u0002\b\u0003\n\u0002\u0010 \n\u0002\b\u000b\u001a!\u0010\u0000\u001a\u000e\u0012\u0004\u0012\u00020\u0002\u0012\u0004\u0012\u00020\u00020\u00012\u0006\u0010\u0003\u001a\u00020\u0002H\u0002¢\u0006\u0002\b\u0004\u001a\u0011\u0010\u0005\u001a\u00020\u0006*\u00020\u0002H\u0002¢\u0006\u0002\b\u0007\u001a\u0014\u0010\b\u001a\u00020\u0002*\u00020\u00022\b\b\u0002\u0010\u0003\u001a\u00020\u0002\u001aJ\u0010\t\u001a\u00020\u0002*\b\u0012\u0004\u0012\u00020\u00020\n2\u0006\u0010\u000b\u001a\u00020\u00062\u0012\u0010\f\u001a\u000e\u0012\u0004\u0012\u00020\u0002\u0012\u0004\u0012\u00020\u00020\u00012\u0014\u0010\r\u001a\u0010\u0012\u0004\u0012\u00020\u0002\u0012\u0006\u0012\u0004\u0018\u00010\u00020\u0001H\u0082\b¢\u0006\u0002\b\u000e\u001a\u0014\u0010\u000f\u001a\u00020\u0002*\u00020\u00022\b\b\u0002\u0010\u0010\u001a\u00020\u0002\u001a\u001e\u0010\u0011\u001a\u00020\u0002*\u00020\u00022\b\b\u0002\u0010\u0010\u001a\u00020\u00022\b\b\u0002\u0010\u0012\u001a\u00020\u0002\u001a\f\u0010\u0013\u001a\u00020\u0002*\u00020\u0002H\u0007\u001a\u0016\u0010\u0014\u001a\u00020\u0002*\u00020\u00022\b\b\u0002\u0010\u0012\u001a\u00020\u0002H\u0007¨\u0006\u0015"}, d2 = {"getIndentFunction", "Lkotlin/Function1;", "", "indent", "getIndentFunction$StringsKt__IndentKt", "indentWidth", "", "indentWidth$StringsKt__IndentKt", "prependIndent", "reindent", "", "resultSizeEstimate", "indentAddFunction", "indentCutFunction", "reindent$StringsKt__IndentKt", "replaceIndent", "newIndent", "replaceIndentByMargin", "marginPrefix", "trimIndent", "trimMargin", "kotlin-stdlib"}, k = 5, mv = {1, 7, 1}, xi = 49, xs = "kotlin/text/StringsKt")
public class j extends i {

    @Metadata(d1 = {"\u0000\n\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0002\u0010\u0000\u001a\u00020\u00012\u0006\u0010\u0002\u001a\u00020\u0001H\n¢\u0006\u0002\b\u0003"}, d2 = {"<anonymous>", "", "line", "invoke"}, k = 3, mv = {1, 7, 1}, xi = 48)
    public static final class a extends Lambda implements Function1<String, String> {

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public static final a f9201f = new a();

        public a() {
            super(1);
        }

        @Override // kotlin.jvm.functions.Function1
        public String invoke(String str) {
            String str2 = str;
            o.f(str2, "line");
            return str2;
        }
    }

    @Metadata(d1 = {"\u0000\n\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0002\u0010\u0000\u001a\u00020\u00012\u0006\u0010\u0002\u001a\u00020\u0001H\n¢\u0006\u0002\b\u0003"}, d2 = {"<anonymous>", "", "line", "invoke"}, k = 3, mv = {1, 7, 1}, xi = 48)
    public static final class b extends Lambda implements Function1<String, String> {

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public final /* synthetic */ String f9202f;

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

        @Override // kotlin.jvm.functions.Function1
        public String invoke(String str) {
            String str2 = str;
            o.f(str2, "line");
            return g.a.a.a.a.A(new StringBuilder(), this.f9202f, str2);
        }
    }

    public static final String A(CharSequence charSequence, int i2) {
        o.f(charSequence, "<this>");
        if (!(i2 >= 0)) {
            throw new IllegalArgumentException(("Count 'n' must be non-negative, but was " + i2 + '.').toString());
        }
        if (i2 != 0) {
            if (i2 == 1) {
                return charSequence.toString();
            }
            int length = charSequence.length();
            if (length != 0) {
                if (length == 1) {
                    char cCharAt = charSequence.charAt(0);
                    char[] cArr = new char[i2];
                    for (int i3 = 0; i3 < i2; i3++) {
                        cArr[i3] = cCharAt;
                    }
                    return new String(cArr);
                }
                StringBuilder sb = new StringBuilder(charSequence.length() * i2);
                IntIterator intIteratorA = new IntRange(1, i2).iterator();
                while (((IntProgressionIterator) intIteratorA).f6204n) {
                    intIteratorA.c();
                    sb.append(charSequence);
                }
                String string = sb.toString();
                o.e(string, "{\n                    va…tring()\n                }");
                return string;
            }
        }
        return "";
    }

    public static String B(String str, char c2, char c3, boolean z2, int i2) {
        String string;
        String str2;
        if ((i2 & 4) != 0) {
            z2 = false;
        }
        o.f(str, "<this>");
        if (z2) {
            StringBuilder sb = new StringBuilder(str.length());
            for (int i3 = 0; i3 < str.length(); i3++) {
                char cCharAt = str.charAt(i3);
                if (c.J(cCharAt, c2, z2)) {
                    cCharAt = c3;
                }
                sb.append(cCharAt);
            }
            string = sb.toString();
            str2 = "StringBuilder(capacity).…builderAction).toString()";
        } else {
            string = str.replace(c2, c3);
            str2 = "this as java.lang.String…replace(oldChar, newChar)";
        }
        o.e(string, str2);
        return string;
    }

    public static String C(String str, String str2, String str3, boolean z2, int i2) {
        int i3 = 0;
        if ((i2 & 4) != 0) {
            z2 = false;
        }
        o.f(str, "<this>");
        o.f(str2, "oldValue");
        o.f(str3, "newValue");
        int iJ = j(str, str2, 0, z2);
        if (iJ < 0) {
            return str;
        }
        int length = str2.length();
        int i4 = length >= 1 ? length : 1;
        int length2 = str3.length() + (str.length() - length);
        if (length2 < 0) {
            throw new OutOfMemoryError();
        }
        StringBuilder sb = new StringBuilder(length2);
        do {
            sb.append((CharSequence) str, i3, iJ);
            sb.append(str3);
            i3 = iJ + length;
            if (iJ >= str.length()) {
                break;
            }
            iJ = j(str, str2, iJ + i4, z2);
        } while (iJ > 0);
        sb.append((CharSequence) str, i3, str.length());
        String string = sb.toString();
        o.e(string, "stringBuilder.append(this, i, length).toString()");
        return string;
    }

    public static final void D(int i2) {
        if (!(i2 >= 0)) {
            throw new IllegalArgumentException(g.a.a.a.a.l("Limit must be non-negative, but was ", i2).toString());
        }
    }

    public static final List<String> E(CharSequence charSequence, String str, boolean z2, int i2) {
        D(i2);
        int length = 0;
        int iJ = j(charSequence, str, 0, z2);
        if (iJ != -1) {
            if (i2 != 1) {
                boolean z3 = i2 > 0;
                int i3 = 10;
                if (z3 && i2 <= 10) {
                    i3 = i2;
                }
                ArrayList arrayList = new ArrayList(i3);
                do {
                    arrayList.add(charSequence.subSequence(length, iJ).toString());
                    length = str.length() + iJ;
                    if (z3 && arrayList.size() == i2 - 1) {
                        break;
                    }
                    iJ = j(charSequence, str, length, z2);
                } while (iJ != -1);
                arrayList.add(charSequence.subSequence(length, charSequence.length()).toString());
                return arrayList;
            }
        }
        return i.H2(charSequence.toString());
    }

    public static List F(CharSequence charSequence, char[] cArr, boolean z2, int i2, int i3) {
        if ((i3 & 2) != 0) {
            z2 = false;
        }
        if ((i3 & 4) != 0) {
            i2 = 0;
        }
        o.f(charSequence, "<this>");
        o.f(cArr, "delimiters");
        if (cArr.length == 1) {
            return E(charSequence, String.valueOf(cArr[0]), z2, i2);
        }
        D(i2);
        Iterable iterableA = q.a(new DelimitedRangesSequence(charSequence, 0, i2, new k(cArr, z2)));
        ArrayList arrayList = new ArrayList(i.H(iterableA, 10));
        Iterator it = ((q.a) iterableA).iterator();
        while (it.hasNext()) {
            arrayList.add(N(charSequence, (IntRange) it.next()));
        }
        return arrayList;
    }

    public static List G(CharSequence charSequence, String[] strArr, boolean z2, int i2, int i3) {
        boolean z3 = (i3 & 2) != 0 ? false : z2;
        int i4 = (i3 & 4) != 0 ? 0 : i2;
        o.f(charSequence, "<this>");
        o.f(strArr, "delimiters");
        if (strArr.length == 1) {
            String str = strArr[0];
            if (!(str.length() == 0)) {
                return E(charSequence, str, z3, i4);
            }
        }
        Iterable iterableA = q.a(v(charSequence, strArr, 0, z3, i4, 2));
        ArrayList arrayList = new ArrayList(i.H(iterableA, 10));
        Iterator it = ((q.a) iterableA).iterator();
        while (it.hasNext()) {
            arrayList.add(N(charSequence, (IntRange) it.next()));
        }
        return arrayList;
    }

    public static final boolean H(String str, String str2, int i2, boolean z2) {
        o.f(str, "<this>");
        o.f(str2, "prefix");
        return !z2 ? str.startsWith(str2, i2) : w(str, i2, str2, 0, str2.length(), z2);
    }

    public static final boolean I(String str, String str2, boolean z2) {
        o.f(str, "<this>");
        o.f(str2, "prefix");
        return !z2 ? str.startsWith(str2) : w(str, 0, str2, 0, str2.length(), z2);
    }

    public static boolean J(CharSequence charSequence, char c2, boolean z2, int i2) {
        if ((i2 & 2) != 0) {
            z2 = false;
        }
        o.f(charSequence, "<this>");
        return charSequence.length() > 0 && c.J(charSequence.charAt(0), c2, z2);
    }

    public static boolean K(CharSequence charSequence, CharSequence charSequence2, boolean z2, int i2) {
        boolean z3 = (i2 & 2) != 0 ? false : z2;
        o.f(charSequence, "<this>");
        o.f(charSequence2, "prefix");
        return (z3 || !(charSequence2 instanceof String)) ? x(charSequence, 0, charSequence2, 0, charSequence2.length(), z3) : M((String) charSequence, (String) charSequence2, false, 2);
    }

    public static /* synthetic */ boolean L(String str, String str2, int i2, boolean z2, int i3) {
        if ((i3 & 4) != 0) {
            z2 = false;
        }
        return H(str, str2, i2, z2);
    }

    public static /* synthetic */ boolean M(String str, String str2, boolean z2, int i2) {
        if ((i2 & 2) != 0) {
            z2 = false;
        }
        return I(str, str2, z2);
    }

    public static final String N(CharSequence charSequence, IntRange intRange) {
        o.f(charSequence, "<this>");
        o.f(intRange, "range");
        return charSequence.subSequence(intRange.d().intValue(), Integer.valueOf(intRange.f6200m).intValue() + 1).toString();
    }

    public static final String O(String str, String str2, String str3) {
        o.f(str, "<this>");
        o.f(str2, "delimiter");
        o.f(str3, "missingDelimiterValue");
        int iN = n(str, str2, 0, false, 6);
        if (iN == -1) {
            return str3;
        }
        String strSubstring = str.substring(str2.length() + iN, str.length());
        o.e(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public static String P(String str, char c2, String str2, int i2) {
        String str3 = (i2 & 2) != 0 ? str : null;
        o.f(str, "<this>");
        o.f(str3, "missingDelimiterValue");
        int iM = m(str, c2, 0, false, 6);
        if (iM == -1) {
            return str3;
        }
        String strSubstring = str.substring(iM + 1, str.length());
        o.e(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public static String R(String str, char c2, String str2, int i2) {
        String str3 = (i2 & 2) != 0 ? str : null;
        o.f(str, "<this>");
        o.f(str3, "missingDelimiterValue");
        int iQ = q(str, c2, 0, false, 6);
        if (iQ == -1) {
            return str3;
        }
        String strSubstring = str.substring(iQ + 1, str.length());
        o.e(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public static String S(String str, char c2, String str2, int i2) {
        String str3 = (i2 & 2) != 0 ? str : null;
        o.f(str, "<this>");
        o.f(str3, "missingDelimiterValue");
        int iM = m(str, c2, 0, false, 6);
        if (iM == -1) {
            return str3;
        }
        String strSubstring = str.substring(0, iM);
        o.e(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public static String T(String str, String str2, String str3, int i2) {
        String str4 = (i2 & 2) != 0 ? str : null;
        o.f(str, "<this>");
        o.f(str2, "delimiter");
        o.f(str4, "missingDelimiterValue");
        int iN = n(str, str2, 0, false, 6);
        if (iN == -1) {
            return str4;
        }
        String strSubstring = str.substring(0, iN);
        o.e(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public static final Integer U(String str) {
        int i2;
        int i3;
        o.f(str, "<this>");
        o.f(str, "<this>");
        c.r(10);
        int length = str.length();
        if (length == 0) {
            return null;
        }
        int i4 = 0;
        char cCharAt = str.charAt(0);
        int i5 = -2147483647;
        boolean z2 = true;
        if (o.h(cCharAt, 48) >= 0) {
            i2 = 0;
            z2 = false;
        } else {
            if (length == 1) {
                return null;
            }
            if (cCharAt == '-') {
                i5 = Integer.MIN_VALUE;
                i2 = 1;
            } else {
                if (cCharAt != '+') {
                    return null;
                }
                i2 = 1;
                z2 = false;
            }
        }
        int i6 = -59652323;
        while (i2 < length) {
            int iDigit = Character.digit((int) str.charAt(i2), 10);
            if (iDigit < 0) {
                return null;
            }
            if ((i4 < i6 && (i6 != -59652323 || i4 < (i6 = i5 / 10))) || (i3 = i4 * 10) < i5 + iDigit) {
                return null;
            }
            i4 = i3 - iDigit;
            i2++;
        }
        return z2 ? Integer.valueOf(i4) : Integer.valueOf(-i4);
    }

    public static final Long V(String str) {
        o.f(str, "<this>");
        o.f(str, "<this>");
        c.r(10);
        int length = str.length();
        if (length == 0) {
            return null;
        }
        int i2 = 0;
        char cCharAt = str.charAt(0);
        long j2 = -9223372036854775807L;
        boolean z2 = true;
        if (o.h(cCharAt, 48) >= 0) {
            z2 = false;
        } else {
            if (length == 1) {
                return null;
            }
            if (cCharAt == '-') {
                j2 = Long.MIN_VALUE;
                i2 = 1;
            } else {
                if (cCharAt != '+') {
                    return null;
                }
                z2 = false;
                i2 = 1;
            }
        }
        long j3 = 0;
        long j4 = -256204778801521550L;
        long j5 = -256204778801521550L;
        while (i2 < length) {
            int iDigit = Character.digit((int) str.charAt(i2), 10);
            if (iDigit < 0) {
                return null;
            }
            if (j3 < j5) {
                if (j5 != j4) {
                    return null;
                }
                j5 = j2 / ((long) 10);
                if (j3 < j5) {
                    return null;
                }
            }
            long j6 = j3 * ((long) 10);
            long j7 = iDigit;
            if (j6 < j2 + j7) {
                return null;
            }
            j3 = j6 - j7;
            i2++;
            j4 = -256204778801521550L;
        }
        return z2 ? Long.valueOf(j3) : Long.valueOf(-j3);
    }

    public static final UInt W(String str, int i2) {
        o.f(str, "<this>");
        c.r(i2);
        int length = str.length();
        if (length == 0) {
            return null;
        }
        int i3 = 0;
        char cCharAt = str.charAt(0);
        int i4 = 1;
        if (o.h(cCharAt, 48) >= 0) {
            i4 = 0;
        } else if (length == 1 || cCharAt != '+') {
            return null;
        }
        int i5 = 119304647;
        while (i4 < length) {
            int iDigit = Character.digit((int) str.charAt(i4), i2);
            if (iDigit < 0) {
                return null;
            }
            if (i.R3(i3, i5) > 0) {
                if (i5 == 119304647) {
                    i5 = (int) ((((long) (-1)) & 4294967295L) / (4294967295L & ((long) i2)));
                    if (i.R3(i3, i5) > 0) {
                    }
                }
                return null;
            }
            int i6 = i3 * i2;
            int i7 = iDigit + i6;
            if (i.R3(i7, i6) < 0) {
                return null;
            }
            i4++;
            i3 = i7;
        }
        return new UInt(i3);
    }

    public static final ULong X(String str) {
        int i2;
        int i3;
        o.f(str, "<this>");
        o.f(str, "<this>");
        int i4 = 10;
        c.r(10);
        int length = str.length();
        if (length != 0) {
            char cCharAt = str.charAt(0);
            if (o.h(cCharAt, 48) >= 0) {
                i2 = 0;
            } else if (length != 1 && cCharAt == '+') {
                i2 = 1;
            }
            long j2 = 10;
            long j3 = 0;
            long j4 = 512409557603043100L;
            while (i2 < length) {
                int iDigit = Character.digit((int) str.charAt(i2), i4);
                if (iDigit >= 0) {
                    if (i.S3(j3, j4) <= 0) {
                        i3 = length;
                    } else if (j4 == 512409557603043100L) {
                        i3 = length;
                        if (j2 < 0) {
                            j4 = i.S3(-1L, j2) < 0 ? 0L : 1L;
                        } else {
                            long j5 = (Long.MAX_VALUE / j2) << 1;
                            j4 = j5 + ((long) (i.S3((-1) - (j5 * j2), j2) >= 0 ? 1 : 0));
                        }
                        if (i.S3(j3, j4) > 0) {
                        }
                    }
                    long j6 = j3 * j2;
                    long j7 = (((long) iDigit) & 4294967295L) + j6;
                    if (i.S3(j7, j6) >= 0) {
                        i2++;
                        j3 = j7;
                        length = i3;
                        i4 = 10;
                    }
                }
            }
            return new ULong(j3);
        }
        return null;
    }

    public static final CharSequence Y(CharSequence charSequence) {
        o.f(charSequence, "<this>");
        int length = charSequence.length() - 1;
        int i2 = 0;
        boolean z2 = false;
        while (i2 <= length) {
            boolean zF0 = c.f0(charSequence.charAt(!z2 ? i2 : length));
            if (z2) {
                if (!zF0) {
                    break;
                }
                length--;
            } else if (zF0) {
                i2++;
            } else {
                z2 = true;
            }
        }
        return charSequence.subSequence(i2, length + 1);
    }

    public static final String Z(String str, char... cArr) {
        o.f(str, "<this>");
        o.f(cArr, "chars");
        int length = str.length() - 1;
        int i2 = 0;
        boolean z2 = false;
        while (i2 <= length) {
            boolean zS = i.S(cArr, str.charAt(!z2 ? i2 : length));
            if (z2) {
                if (!zS) {
                    break;
                }
                length--;
            } else if (zS) {
                i2++;
            } else {
                z2 = true;
            }
        }
        return str.subSequence(i2, length + 1).toString();
    }

    public static final String a(char[] cArr, int i2, int i3) {
        o.f(cArr, "<this>");
        int length = cArr.length;
        if (i2 < 0 || i3 > length) {
            StringBuilder sbI = g.a.a.a.a.I("startIndex: ", i2, ", endIndex: ", i3, ", size: ");
            sbI.append(length);
            throw new IndexOutOfBoundsException(sbI.toString());
        }
        if (i2 <= i3) {
            return new String(cArr, i2, i3 - i2);
        }
        throw new IllegalArgumentException(g.a.a.a.a.o("startIndex: ", i2, " > endIndex: ", i3));
    }

    public static String a0(String str, String str2, int i2) throws IOException {
        String strSubstring;
        String strInvoke;
        String str3 = (i2 & 1) != 0 ? "|" : null;
        o.f(str, "<this>");
        o.f(str3, "marginPrefix");
        o.f(str, "<this>");
        o.f("", "newIndent");
        o.f(str3, "marginPrefix");
        if (!(!p(str3))) {
            throw new IllegalArgumentException("marginPrefix must be non-blank string.".toString());
        }
        List<String> listS = s(str);
        int size = (listS.size() * 0) + str.length();
        Function1<String, String> function1H = h("");
        int iX = kotlin.collections.j.x(listS);
        ArrayList arrayList = new ArrayList();
        int i3 = 0;
        for (Object obj : listS) {
            int i4 = i3 + 1;
            if (i3 < 0) {
                kotlin.collections.j.e0();
                throw null;
            }
            String str4 = (String) obj;
            if ((i3 == 0 || i3 == iX) && p(str4)) {
                str4 = null;
            } else {
                int length = str4.length();
                int i5 = 0;
                while (true) {
                    if (i5 >= length) {
                        i5 = -1;
                        break;
                    }
                    if (!c.f0(str4.charAt(i5))) {
                        break;
                    }
                    i5++;
                }
                if (i5 != -1 && L(str4, str3, i5, false, 4)) {
                    int length2 = str3.length() + i5;
                    o.d(str4, "null cannot be cast to non-null type java.lang.String");
                    strSubstring = str4.substring(length2);
                    o.e(strSubstring, "this as java.lang.String).substring(startIndex)");
                } else {
                    strSubstring = null;
                }
                if (strSubstring != null && (strInvoke = function1H.invoke(strSubstring)) != null) {
                    str4 = strInvoke;
                }
            }
            if (str4 != null) {
                arrayList.add(str4);
            }
            i3 = i4;
        }
        StringBuilder sb = new StringBuilder(size);
        kotlin.collections.j.B(arrayList, sb, "\n", null, null, 0, null, null, 124);
        String string = sb.toString();
        o.e(string, "mapIndexedNotNull { inde…\"\\n\")\n        .toString()");
        return string;
    }

    public static final boolean b(CharSequence charSequence, CharSequence charSequence2, boolean z2) {
        o.f(charSequence, "<this>");
        o.f(charSequence2, "other");
        if (charSequence2 instanceof String) {
            if (n(charSequence, (String) charSequence2, 0, z2, 2) >= 0) {
                return true;
            }
        } else if (l(charSequence, charSequence2, 0, charSequence.length(), z2, false, 16) >= 0) {
            return true;
        }
        return false;
    }

    public static boolean c(CharSequence charSequence, char c2, boolean z2, int i2) {
        if ((i2 & 2) != 0) {
            z2 = false;
        }
        o.f(charSequence, "<this>");
        return m(charSequence, c2, 0, z2, 2) >= 0;
    }

    public static /* synthetic */ boolean d(CharSequence charSequence, CharSequence charSequence2, boolean z2, int i2) {
        if ((i2 & 2) != 0) {
            z2 = false;
        }
        return b(charSequence, charSequence2, z2);
    }

    public static boolean e(CharSequence charSequence, CharSequence charSequence2, boolean z2, int i2) {
        boolean z3 = (i2 & 2) != 0 ? false : z2;
        o.f(charSequence, "<this>");
        o.f(charSequence2, "suffix");
        return (z3 || !(charSequence2 instanceof String)) ? x(charSequence, charSequence.length() - charSequence2.length(), charSequence2, 0, charSequence2.length(), z3) : f((String) charSequence, (String) charSequence2, false, 2);
    }

    public static boolean f(String str, String str2, boolean z2, int i2) {
        if ((i2 & 2) != 0) {
            z2 = false;
        }
        o.f(str, "<this>");
        o.f(str2, "suffix");
        return !z2 ? str.endsWith(str2) : w(str, str.length() - str2.length(), str2, 0, str2.length(), true);
    }

    public static final boolean g(String str, String str2, boolean z2) {
        return str == null ? str2 == null : !z2 ? str.equals(str2) : str.equalsIgnoreCase(str2);
    }

    public static final Function1<String, String> h(String str) {
        return str.length() == 0 ? a.f9201f : new b(str);
    }

    public static final int i(CharSequence charSequence) {
        o.f(charSequence, "<this>");
        return charSequence.length() - 1;
    }

    public static final int j(CharSequence charSequence, String str, int i2, boolean z2) {
        o.f(charSequence, "<this>");
        o.f(str, "string");
        return (z2 || !(charSequence instanceof String)) ? l(charSequence, str, i2, charSequence.length(), z2, false, 16) : ((String) charSequence).indexOf(str, i2);
    }

    public static final int k(CharSequence charSequence, CharSequence charSequence2, int i2, int i3, boolean z2, boolean z3) {
        IntProgression intProgression;
        if (z3) {
            int i4 = i(charSequence);
            if (i2 > i4) {
                i2 = i4;
            }
            if (i3 < 0) {
                i3 = 0;
            }
            intProgression = new IntProgression(i2, i3, -1);
        } else {
            if (i2 < 0) {
                i2 = 0;
            }
            int length = charSequence.length();
            if (i3 > length) {
                i3 = length;
            }
            intProgression = new IntRange(i2, i3);
        }
        if ((charSequence instanceof String) && (charSequence2 instanceof String)) {
            int i5 = intProgression.f6199f;
            int i6 = intProgression.f6200m;
            int i7 = intProgression.f6201n;
            if ((i7 > 0 && i5 <= i6) || (i7 < 0 && i6 <= i5)) {
                while (!w((String) charSequence2, 0, (String) charSequence, i5, charSequence2.length(), z2)) {
                    if (i5 != i6) {
                        i5 += i7;
                    }
                }
                return i5;
            }
        } else {
            int i8 = intProgression.f6199f;
            int i9 = intProgression.f6200m;
            int i10 = intProgression.f6201n;
            if ((i10 > 0 && i8 <= i9) || (i10 < 0 && i9 <= i8)) {
                while (!x(charSequence2, 0, charSequence, i8, charSequence2.length(), z2)) {
                    if (i8 != i9) {
                        i8 += i10;
                    }
                }
                return i8;
            }
        }
        return -1;
    }

    public static /* synthetic */ int l(CharSequence charSequence, CharSequence charSequence2, int i2, int i3, boolean z2, boolean z3, int i4) {
        if ((i4 & 16) != 0) {
            z3 = false;
        }
        return k(charSequence, charSequence2, i2, i3, z2, z3);
    }

    public static int m(CharSequence charSequence, char c2, int i2, boolean z2, int i3) {
        if ((i3 & 2) != 0) {
            i2 = 0;
        }
        if ((i3 & 4) != 0) {
            z2 = false;
        }
        o.f(charSequence, "<this>");
        return (z2 || !(charSequence instanceof String)) ? o(charSequence, new char[]{c2}, i2, z2) : ((String) charSequence).indexOf(c2, i2);
    }

    public static /* synthetic */ int n(CharSequence charSequence, String str, int i2, boolean z2, int i3) {
        if ((i3 & 2) != 0) {
            i2 = 0;
        }
        if ((i3 & 4) != 0) {
            z2 = false;
        }
        return j(charSequence, str, i2, z2);
    }

    public static final int o(CharSequence charSequence, char[] cArr, int i2, boolean z2) {
        boolean z3;
        o.f(charSequence, "<this>");
        o.f(cArr, "chars");
        if (!z2 && cArr.length == 1 && (charSequence instanceof String)) {
            return ((String) charSequence).indexOf(i.u3(cArr), i2);
        }
        if (i2 < 0) {
            i2 = 0;
        }
        IntIterator intIteratorA = new IntRange(i2, i(charSequence)).iterator();
        while (((IntProgressionIterator) intIteratorA).f6204n) {
            int iC = intIteratorA.c();
            char cCharAt = charSequence.charAt(iC);
            int length = cArr.length;
            int i3 = 0;
            while (true) {
                if (i3 >= length) {
                    z3 = false;
                    break;
                }
                if (c.J(cArr[i3], cCharAt, z2)) {
                    z3 = true;
                    break;
                }
                i3++;
            }
            if (z3) {
                return iC;
            }
        }
        return -1;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:22:? A[RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static final boolean p(java.lang.CharSequence r4) {
        /*
            java.lang.String r0 = "<this>"
            kotlin.jvm.internal.o.f(r4, r0)
            int r1 = r4.length()
            r2 = 0
            r3 = 1
            if (r1 == 0) goto L47
            kotlin.jvm.internal.o.f(r4, r0)
            r.h0.f r0 = new r.h0.f
            int r1 = r4.length()
            int r1 = r1 + (-1)
            r0.<init>(r2, r1)
            boolean r1 = r0 instanceof java.util.Collection
            if (r1 == 0) goto L29
            r1 = r0
            java.util.Collection r1 = (java.util.Collection) r1
            boolean r1 = r1.isEmpty()
            if (r1 == 0) goto L29
            goto L44
        L29:
            r.z.z r0 = r0.iterator()
        L2d:
            r1 = r0
            r.h0.e r1 = (kotlin.ranges.IntProgressionIterator) r1
            boolean r1 = r1.f6204n
            if (r1 == 0) goto L44
            int r1 = r0.c()
            char r1 = r4.charAt(r1)
            boolean r1 = kotlin.reflect.w.internal.y0.n.c2.c.f0(r1)
            if (r1 != 0) goto L2d
            r4 = r2
            goto L45
        L44:
            r4 = r3
        L45:
            if (r4 == 0) goto L48
        L47:
            r2 = r3
        L48:
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: kotlin.text.j.p(java.lang.CharSequence):boolean");
    }

    public static int q(CharSequence charSequence, char c2, int i2, boolean z2, int i3) {
        boolean z3;
        if ((i3 & 2) != 0) {
            i2 = i(charSequence);
        }
        if ((i3 & 4) != 0) {
            z2 = false;
        }
        o.f(charSequence, "<this>");
        if (!z2) {
            return ((String) charSequence).lastIndexOf(c2, i2);
        }
        char[] cArr = {c2};
        o.f(charSequence, "<this>");
        o.f(cArr, "chars");
        if (!z2) {
            return ((String) charSequence).lastIndexOf(i.u3(cArr), i2);
        }
        int i4 = i(charSequence);
        if (i2 > i4) {
            i2 = i4;
        }
        while (-1 < i2) {
            char cCharAt = charSequence.charAt(i2);
            int i5 = 0;
            while (true) {
                if (i5 >= 1) {
                    z3 = false;
                    break;
                }
                if (c.J(cArr[i5], cCharAt, z2)) {
                    z3 = true;
                    break;
                }
                i5++;
            }
            if (z3) {
                return i2;
            }
            i2--;
        }
        return -1;
    }

    public static int r(CharSequence charSequence, String str, int i2, boolean z2, int i3) {
        if ((i3 & 2) != 0) {
            i2 = i(charSequence);
        }
        int i4 = i2;
        if ((i3 & 4) != 0) {
            z2 = false;
        }
        boolean z3 = z2;
        o.f(charSequence, "<this>");
        o.f(str, "string");
        return (z3 || !(charSequence instanceof String)) ? k(charSequence, str, i4, 0, z3, true) : ((String) charSequence).lastIndexOf(str, i4);
    }

    public static final List<String> s(CharSequence charSequence) {
        o.f(charSequence, "<this>");
        o.f(charSequence, "<this>");
        String[] strArr = {"\r\n", "\n", "\r"};
        o.f(charSequence, "<this>");
        o.f(strArr, "delimiters");
        return q.j(q.g(v(charSequence, strArr, 0, false, 0, 2), new m(charSequence)));
    }

    public static final Void t(String str) {
        o.f(str, "input");
        throw new NumberFormatException("Invalid number format: '" + str + '\'');
    }

    public static final String u(String str, int i2, char c2) {
        CharSequence charSequenceSubSequence;
        o.f(str, "<this>");
        o.f(str, "<this>");
        if (i2 < 0) {
            throw new IllegalArgumentException(g.a.a.a.a.n("Desired length ", i2, " is less than zero."));
        }
        if (i2 <= str.length()) {
            charSequenceSubSequence = str.subSequence(0, str.length());
        } else {
            StringBuilder sb = new StringBuilder(i2);
            IntIterator intIteratorA = new IntRange(1, i2 - str.length()).iterator();
            while (((IntProgressionIterator) intIteratorA).f6204n) {
                intIteratorA.c();
                sb.append(c2);
            }
            sb.append((CharSequence) str);
            charSequenceSubSequence = sb;
        }
        return charSequenceSubSequence.toString();
    }

    public static Sequence v(CharSequence charSequence, String[] strArr, int i2, boolean z2, int i3, int i4) {
        if ((i4 & 2) != 0) {
            i2 = 0;
        }
        if ((i4 & 4) != 0) {
            z2 = false;
        }
        if ((i4 & 8) != 0) {
            i3 = 0;
        }
        D(i3);
        return new DelimitedRangesSequence(charSequence, i2, i3, new l(kotlin.collections.j.d(strArr), z2));
    }

    public static final boolean w(String str, int i2, String str2, int i3, int i4, boolean z2) {
        o.f(str, "<this>");
        o.f(str2, "other");
        return !z2 ? str.regionMatches(i2, str2, i3, i4) : str.regionMatches(z2, i2, str2, i3, i4);
    }

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

    public static final String y(String str, CharSequence charSequence) {
        o.f(str, "<this>");
        o.f(charSequence, "prefix");
        if (!K(str, charSequence, false, 2)) {
            return str;
        }
        String strSubstring = str.substring(charSequence.length());
        o.e(strSubstring, "this as java.lang.String).substring(startIndex)");
        return strSubstring;
    }

    public static final String z(String str, CharSequence charSequence) {
        o.f(str, "<this>");
        o.f(charSequence, "suffix");
        if (!e(str, charSequence, false, 2)) {
            return str;
        }
        String strSubstring = str.substring(0, str.length() - charSequence.length());
        o.e(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }
}
