package p057s1;

import p009c1.AbstractC0515t;
import p009c1.C0499d;
import p039m1.C1470g;
import p048p1.C1537a;
import p048p1.C1540c;
import p048p1.C1543e;

/* renamed from: s1.m */
/* loaded from: classes.dex */
public class C1631m extends C1630l {
    /* renamed from: f */
    public static final int m779f(CharSequence charSequence) {
        C1470g.m1292e(charSequence, "<this>");
        return charSequence.length() - 1;
    }

    /* renamed from: g */
    public static final int m778g(CharSequence charSequence, char c, int i, boolean z) {
        C1470g.m1292e(charSequence, "<this>");
        return (z || !(charSequence instanceof String)) ? m772m(charSequence, new char[]{c}, i, z) : ((String) charSequence).indexOf(c, i);
    }

    /* renamed from: h */
    public static final int m777h(CharSequence charSequence, String str, int i, boolean z) {
        C1470g.m1292e(charSequence, "<this>");
        C1470g.m1292e(str, "string");
        return (z || !(charSequence instanceof String)) ? m775j(charSequence, str, i, charSequence.length(), z, false, 16, null) : ((String) charSequence).indexOf(str, i);
    }

    /* renamed from: i */
    public static final int m776i(CharSequence charSequence, CharSequence charSequence2, int i, int i2, boolean z, boolean z2) {
        C1537a c1540c = !z2 ? new C1540c(C1543e.m1092a(i, 0), C1543e.m1090c(i2, charSequence.length())) : C1543e.m1088e(C1543e.m1090c(i, m779f(charSequence)), C1543e.m1092a(i2, 0));
        if ((charSequence instanceof String) && (charSequence2 instanceof String)) {
            int m1098a = c1540c.m1098a();
            int m1097b = c1540c.m1097b();
            int m1096c = c1540c.m1096c();
            if ((m1096c <= 0 || m1098a > m1097b) && (m1096c >= 0 || m1097b > m1098a)) {
                return -1;
            }
            while (!C1630l.m782c((String) charSequence2, 0, (String) charSequence, m1098a, charSequence2.length(), z)) {
                if (m1098a == m1097b) {
                    return -1;
                }
                m1098a += m1096c;
            }
            return m1098a;
        }
        int m1098a2 = c1540c.m1098a();
        int m1097b2 = c1540c.m1097b();
        int m1096c2 = c1540c.m1096c();
        if ((m1096c2 <= 0 || m1098a2 > m1097b2) && (m1096c2 >= 0 || m1097b2 > m1098a2)) {
            return -1;
        }
        while (!m768q(charSequence2, 0, charSequence, m1098a2, charSequence2.length(), z)) {
            if (m1098a2 == m1097b2) {
                return -1;
            }
            m1098a2 += m1096c2;
        }
        return m1098a2;
    }

    /* renamed from: j */
    public static /* synthetic */ int m775j(CharSequence charSequence, CharSequence charSequence2, int i, int i2, boolean z, boolean z2, int i3, Object obj) {
        return m776i(charSequence, charSequence2, i, i2, z, (i3 & 16) != 0 ? false : z2);
    }

    /* renamed from: k */
    public static /* synthetic */ int m774k(CharSequence charSequence, char c, int i, boolean z, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            i = 0;
        }
        if ((i2 & 4) != 0) {
            z = false;
        }
        return m778g(charSequence, c, i, z);
    }

    /* renamed from: l */
    public static /* synthetic */ int m773l(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 m777h(charSequence, str, i, z);
    }

    /* renamed from: m */
    public static final int m772m(CharSequence charSequence, char[] cArr, int i, boolean z) {
        boolean z2;
        C1470g.m1292e(charSequence, "<this>");
        C1470g.m1292e(cArr, "chars");
        if (!z && cArr.length == 1 && (charSequence instanceof String)) {
            return ((String) charSequence).indexOf(C0499d.m3613f(cArr), i);
        }
        AbstractC0515t it = new C1540c(C1543e.m1092a(i, 0), m779f(charSequence)).iterator();
        while (it.hasNext()) {
            int nextInt = it.nextInt();
            char charAt = charSequence.charAt(nextInt);
            int length = cArr.length;
            int i2 = 0;
            while (true) {
                if (i2 >= length) {
                    z2 = false;
                    continue;
                    break;
                } else if (C1620b.m785d(cArr[i2], charAt, z)) {
                    z2 = true;
                    continue;
                    break;
                } else {
                    i2++;
                }
            }
            if (z2) {
                return nextInt;
            }
        }
        return -1;
    }

    /* renamed from: n */
    public static final int m771n(CharSequence charSequence, char c, int i, boolean z) {
        C1470g.m1292e(charSequence, "<this>");
        return (z || !(charSequence instanceof String)) ? m769p(charSequence, new char[]{c}, i, z) : ((String) charSequence).lastIndexOf(c, i);
    }

    /* renamed from: o */
    public static /* synthetic */ int m770o(CharSequence charSequence, char c, int i, boolean z, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            i = m779f(charSequence);
        }
        if ((i2 & 4) != 0) {
            z = false;
        }
        return m771n(charSequence, c, i, z);
    }

    /* renamed from: p */
    public static final int m769p(CharSequence charSequence, char[] cArr, int i, boolean z) {
        C1470g.m1292e(charSequence, "<this>");
        C1470g.m1292e(cArr, "chars");
        if (!z && cArr.length == 1 && (charSequence instanceof String)) {
            return ((String) charSequence).lastIndexOf(C0499d.m3613f(cArr), i);
        }
        for (int m1090c = C1543e.m1090c(i, m779f(charSequence)); -1 < m1090c; m1090c--) {
            char charAt = charSequence.charAt(m1090c);
            int length = cArr.length;
            boolean z2 = false;
            int i2 = 0;
            while (true) {
                if (i2 >= length) {
                    break;
                } else if (C1620b.m785d(cArr[i2], charAt, z)) {
                    z2 = true;
                    break;
                } else {
                    i2++;
                }
            }
            if (z2) {
                return m1090c;
            }
        }
        return -1;
    }

    /* renamed from: q */
    public static final boolean m768q(CharSequence charSequence, int i, CharSequence charSequence2, int i2, int i3, boolean z) {
        C1470g.m1292e(charSequence, "<this>");
        C1470g.m1292e(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 (!C1620b.m785d(charSequence.charAt(i + i4), charSequence2.charAt(i2 + i4), z)) {
                return false;
            }
        }
        return true;
    }

    /* renamed from: r */
    public static final String m767r(String str, String str2, String str3) {
        C1470g.m1292e(str, "<this>");
        C1470g.m1292e(str2, "delimiter");
        C1470g.m1292e(str3, "missingDelimiterValue");
        int m773l = m773l(str, str2, 0, false, 6, null);
        if (m773l == -1) {
            return str3;
        }
        String substring = str.substring(m773l + str2.length(), str.length());
        C1470g.m1293d(substring, "this as java.lang.String\u2026ing(startIndex, endIndex)");
        return substring;
    }

    /* renamed from: s */
    public static /* synthetic */ String m766s(String str, String str2, String str3, int i, Object obj) {
        if ((i & 2) != 0) {
            str3 = str;
        }
        return m767r(str, str2, str3);
    }

    /* renamed from: t */
    public static final String m765t(String str, char c, String str2) {
        C1470g.m1292e(str, "<this>");
        C1470g.m1292e(str2, "missingDelimiterValue");
        int m770o = m770o(str, c, 0, false, 6, null);
        if (m770o == -1) {
            return str2;
        }
        String substring = str.substring(m770o + 1, str.length());
        C1470g.m1293d(substring, "this as java.lang.String\u2026ing(startIndex, endIndex)");
        return substring;
    }

    /* renamed from: u */
    public static /* synthetic */ String m764u(String str, char c, String str2, int i, Object obj) {
        if ((i & 2) != 0) {
            str2 = str;
        }
        return m765t(str, c, str2);
    }

    /* renamed from: v */
    public static final String m763v(String str, char c, String str2) {
        C1470g.m1292e(str, "<this>");
        C1470g.m1292e(str2, "missingDelimiterValue");
        int m774k = m774k(str, c, 0, false, 6, null);
        if (m774k == -1) {
            return str2;
        }
        String substring = str.substring(0, m774k);
        C1470g.m1293d(substring, "this as java.lang.String\u2026ing(startIndex, endIndex)");
        return substring;
    }

    /* renamed from: w */
    public static final String m762w(String str, String str2, String str3) {
        C1470g.m1292e(str, "<this>");
        C1470g.m1292e(str2, "delimiter");
        C1470g.m1292e(str3, "missingDelimiterValue");
        int m773l = m773l(str, str2, 0, false, 6, null);
        if (m773l == -1) {
            return str3;
        }
        String substring = str.substring(0, m773l);
        C1470g.m1293d(substring, "this as java.lang.String\u2026ing(startIndex, endIndex)");
        return substring;
    }

    /* renamed from: x */
    public static /* synthetic */ String m761x(String str, char c, String str2, int i, Object obj) {
        if ((i & 2) != 0) {
            str2 = str;
        }
        return m763v(str, c, str2);
    }

    /* renamed from: y */
    public static /* synthetic */ String m760y(String str, String str2, String str3, int i, Object obj) {
        if ((i & 2) != 0) {
            str3 = str;
        }
        return m762w(str, str2, str3);
    }

    /* renamed from: z */
    public static final CharSequence m759z(CharSequence charSequence) {
        C1470g.m1292e(charSequence, "<this>");
        int length = charSequence.length() - 1;
        int i = 0;
        boolean z = false;
        while (i <= length) {
            boolean m786c = C1619a.m786c(charSequence.charAt(!z ? i : length));
            if (z) {
                if (!m786c) {
                    break;
                }
                length--;
            } else if (m786c) {
                i++;
            } else {
                z = true;
            }
        }
        return charSequence.subSequence(i, length + 1);
    }
}