package o;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;

/* loaded from: classes.dex */
public abstract class Za0 extends AbstractC1299gb0 {
    public static boolean P(CharSequence charSequence, CharSequence charSequence2, boolean z) {
        if (charSequence2 instanceof String) {
            if (W(charSequence, (String) charSequence2, 0, z, 2) >= 0) {
                return true;
            }
        } else if (U(charSequence, charSequence2, 0, charSequence.length(), z, false) >= 0) {
            return true;
        }
        return false;
    }

    public static boolean Q(CharSequence charSequence, char c) {
        return V(charSequence, c, 0, 2) >= 0;
    }

    public static boolean R(CharSequence charSequence, String str) {
        return charSequence instanceof String ? ((String) charSequence).endsWith(str) : e0(charSequence, charSequence.length() - str.length(), str, 0, str.length(), false);
    }

    public static int S(CharSequence charSequence) {
        return charSequence.length() - 1;
    }

    public static final int T(CharSequence charSequence, String str, int i, boolean z) {
        return (z || !(charSequence instanceof String)) ? U(charSequence, str, i, charSequence.length(), z, false) : ((String) charSequence).indexOf(str, i);
    }

    public static final int U(CharSequence charSequence, CharSequence charSequence2, int i, int i2, boolean z, boolean z2) {
        C0800bI c0800bI;
        CharSequence charSequence3 = charSequence2;
        int i3 = i;
        int i4 = i2;
        if (z2) {
            int iS = S(charSequence);
            if (i3 > iS) {
                i3 = iS;
            }
            if (i4 < 0) {
                i4 = 0;
            }
            c0800bI = new C0800bI(i3, i4, -1);
        } else {
            if (i3 < 0) {
                i3 = 0;
            }
            int length = charSequence.length();
            if (i4 > length) {
                i4 = length;
            }
            c0800bI = new C0991dI(i3, i4, 1);
        }
        boolean z3 = charSequence instanceof String;
        int i5 = c0800bI.n;
        int i6 = c0800bI.m;
        int i7 = c0800bI.l;
        if (z3 && (charSequence3 instanceof String)) {
            if ((i5 > 0 && i7 <= i6) || (i5 < 0 && i6 <= i7)) {
                int i8 = i7;
                while (true) {
                    String str = (String) charSequence3;
                    String str2 = (String) charSequence;
                    int length2 = str.length();
                    if (!(!z ? str.regionMatches(0, str2, i8, length2) : str.regionMatches(z, 0, str2, i8, length2))) {
                        if (i8 == i6) {
                            break;
                        }
                        i8 += i5;
                    } else {
                        return i8;
                    }
                }
            }
        } else if ((i5 > 0 && i7 <= i6) || (i5 < 0 && i6 <= i7)) {
            int i9 = i7;
            while (!e0(charSequence3, 0, charSequence, i9, charSequence3.length(), z)) {
                if (i9 != i6) {
                    i9 += i5;
                    charSequence3 = charSequence2;
                }
            }
            return i9;
        }
        return -1;
    }

    public static int V(CharSequence charSequence, char c, int i, int i2) {
        if ((i2 & 2) != 0) {
            i = 0;
        }
        return !(charSequence instanceof String) ? X(charSequence, new char[]{c}, i, false) : ((String) charSequence).indexOf(c, i);
    }

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

    public static final int X(CharSequence charSequence, char[] cArr, int i, boolean z) {
        if (!z && cArr.length == 1 && (charSequence instanceof String)) {
            int length = cArr.length;
            if (length == 0) {
                throw new NoSuchElementException("Array is empty.");
            }
            if (length != 1) {
                throw new IllegalArgumentException("Array has more than one element.");
            }
            return ((String) charSequence).indexOf(cArr[0], i);
        }
        if (i < 0) {
            i = 0;
        }
        int iS = S(charSequence);
        if (i > iS) {
            return -1;
        }
        while (true) {
            char cCharAt = charSequence.charAt(i);
            for (char c : cArr) {
                if (AbstractC0940cn0.q(c, cCharAt, z)) {
                    return i;
                }
            }
            if (i == iS) {
                return -1;
            }
            i++;
        }
    }

    public static boolean Y(CharSequence charSequence) {
        for (int i = 0; i < charSequence.length(); i++) {
            if (!AbstractC0940cn0.z(charSequence.charAt(i))) {
                return false;
            }
        }
        return true;
    }

    public static char Z(CharSequence charSequence) {
        if (charSequence.length() != 0) {
            return charSequence.charAt(S(charSequence));
        }
        throw new NoSuchElementException("Char sequence is empty.");
    }

    public static int a0(int i, String str, String str2) {
        int iS = (i & 2) != 0 ? S(str) : 0;
        return str == null ? U(str, str2, iS, 0, false, true) : str.lastIndexOf(str2, iS);
    }

    public static int b0(CharSequence charSequence, char c, int i, int i2) {
        if ((i2 & 2) != 0) {
            i = S(charSequence);
        }
        if (charSequence instanceof String) {
            return ((String) charSequence).lastIndexOf(c, i);
        }
        char[] cArr = {c};
        if (charSequence instanceof String) {
            return ((String) charSequence).lastIndexOf(cArr[0], i);
        }
        int iS = S(charSequence);
        if (i > iS) {
            i = iS;
        }
        while (-1 < i) {
            if (AbstractC0940cn0.q(cArr[0], charSequence.charAt(i), false)) {
                return i;
            }
            i--;
        }
        return -1;
    }

    public static final List c0(String str) {
        return H60.H(new GD(d0(str, new String[]{"\r\n", "\n", "\r"}, 0), new J80(1, str)));
    }

    public static C2091or d0(CharSequence charSequence, String[] strArr, int i) {
        h0(i);
        return new C2091or(charSequence, i, new C2959y(8, Arrays.asList(strArr)));
    }

    public static final boolean e0(CharSequence charSequence, int i, CharSequence charSequence2, int i2, int i3, boolean z) {
        if (i2 < 0 || i < 0 || i > charSequence.length() - i3 || i2 > charSequence2.length() - i3) {
            return false;
        }
        for (int i4 = 0; i4 < i3; i4++) {
            if (!AbstractC0940cn0.q(charSequence.charAt(i + i4), charSequence2.charAt(i2 + i4), z)) {
                return false;
            }
        }
        return true;
    }

    public static String f0(String str, String str2) {
        return AbstractC1299gb0.L(str, str2, false) ? str.substring(str2.length()) : str;
    }

    public static StringBuilder g0(CharSequence charSequence, int i, int i2, CharSequence charSequence2) {
        if (i2 >= i) {
            StringBuilder sb = new StringBuilder();
            sb.append(charSequence, 0, i);
            sb.append(charSequence2);
            sb.append(charSequence, i2, charSequence.length());
            return sb;
        }
        throw new IndexOutOfBoundsException("End index (" + i2 + ") is less than start index (" + i + ").");
    }

    public static final void h0(int i) {
        if (i < 0) {
            throw new IllegalArgumentException(AbstractC0126Ew.j(i, "Limit must be non-negative, but was ").toString());
        }
    }

    public static final List i0(int i, CharSequence charSequence, String str) {
        h0(i);
        int iT = T(charSequence, str, 0, false);
        if (iT == -1 || i == 1) {
            return Collections.singletonList(charSequence.toString());
        }
        boolean z = i > 0;
        int i2 = 10;
        if (z && i <= 10) {
            i2 = i;
        }
        ArrayList arrayList = new ArrayList(i2);
        int length = 0;
        do {
            arrayList.add(charSequence.subSequence(length, iT).toString());
            length = str.length() + iT;
            if (z && arrayList.size() == i - 1) {
                break;
            }
            iT = T(charSequence, str, length, false);
        } while (iT != -1);
        arrayList.add(charSequence.subSequence(length, charSequence.length()).toString());
        return arrayList;
    }

    public static List j0(CharSequence charSequence, String[] strArr, int i, int i2) {
        if ((i2 & 4) != 0) {
            i = 0;
        }
        if (strArr.length == 1) {
            String str = strArr[0];
            if (str.length() != 0) {
                return i0(i, charSequence, str);
            }
        }
        J60 j60 = new J60(d0(charSequence, strArr, i));
        ArrayList arrayList = new ArrayList(AbstractC0034Bi.W(j60, 10));
        Iterator it = j60.iterator();
        while (true) {
            C1996nr c1996nr = (C1996nr) it;
            if (!c1996nr.hasNext()) {
                return arrayList;
            }
            C0991dI c0991dI = (C0991dI) c1996nr.next();
            arrayList.add(charSequence.subSequence(c0991dI.l, c0991dI.m + 1).toString());
        }
    }

    public static List k0(String str, char[] cArr) {
        if (cArr.length == 1) {
            return i0(0, str, String.valueOf(cArr[0]));
        }
        h0(0);
        J60 j60 = new J60(new C2091or(str, 0, new C2959y(7, cArr)));
        ArrayList arrayList = new ArrayList(AbstractC0034Bi.W(j60, 10));
        Iterator it = j60.iterator();
        while (true) {
            C1996nr c1996nr = (C1996nr) it;
            if (!c1996nr.hasNext()) {
                return arrayList;
            }
            C0991dI c0991dI = (C0991dI) c1996nr.next();
            arrayList.add(str.subSequence(c0991dI.l, c0991dI.m + 1).toString());
        }
    }

    public static String l0(String str, String str2) {
        int iW = W(str, str2, 0, false, 6);
        return iW == -1 ? str : str.substring(str2.length() + iW, str.length());
    }

    public static String m0(String str, char c, String str2) {
        int iB0 = b0(str, c, 0, 6);
        return iB0 == -1 ? str2 : str.substring(iB0 + 1, str.length());
    }

    public static String n0(int i, String str) {
        if (i < 0) {
            throw new IllegalArgumentException(AbstractC0126Ew.k(i, "Requested character count ", " is less than zero.").toString());
        }
        int length = str.length();
        if (i > length) {
            i = length;
        }
        return str.substring(0, i);
    }

    public static CharSequence o0(CharSequence charSequence) {
        int length = charSequence.length() - 1;
        int i = 0;
        boolean z = false;
        while (i <= length) {
            boolean z2 = AbstractC0940cn0.z(charSequence.charAt(!z ? i : length));
            if (z) {
                if (!z2) {
                    break;
                }
                length--;
            } else if (z2) {
                i++;
            } else {
                z = true;
            }
        }
        return charSequence.subSequence(i, length + 1);
    }
}
