package kotlin.text;

import com.google.firebase.perf.util.Constants;
import rm.f0;
import rm.h0;
import rm.k0;

/* loaded from: classes3.dex */
public abstract class c0 {
    public static final String a(short s10, int i10) {
        int a10;
        a10 = b.a(i10);
        String num = Integer.toString(s10 & 65535, a10);
        kotlin.jvm.internal.t.f(num, "toString(...)");
        return num;
    }

    public static final byte b(String str) {
        kotlin.jvm.internal.t.g(str, "<this>");
        rm.d0 c10 = c(str);
        if (c10 != null) {
            return c10.s();
        }
        x.l(str);
        throw new rm.k();
    }

    public static final rm.d0 c(String str) {
        kotlin.jvm.internal.t.g(str, "<this>");
        return d(str, 10);
    }

    public static final rm.d0 d(String str, int i10) {
        kotlin.jvm.internal.t.g(str, "<this>");
        f0 g10 = g(str, i10);
        if (g10 == null) {
            return null;
        }
        int s10 = g10.s();
        if (Integer.compareUnsigned(s10, f0.e(Constants.MAX_HOST_LENGTH)) > 0) {
            return null;
        }
        return rm.d0.a(rm.d0.e((byte) s10));
    }

    public static final int e(String str) {
        kotlin.jvm.internal.t.g(str, "<this>");
        f0 f10 = f(str);
        if (f10 != null) {
            return f10.s();
        }
        x.l(str);
        throw new rm.k();
    }

    public static final f0 f(String str) {
        kotlin.jvm.internal.t.g(str, "<this>");
        return g(str, 10);
    }

    public static final f0 g(String str, int i10) {
        int i11;
        kotlin.jvm.internal.t.g(str, "<this>");
        b.a(i10);
        int length = str.length();
        if (length == 0) {
            return null;
        }
        int i12 = 0;
        char charAt = str.charAt(0);
        if (kotlin.jvm.internal.t.i(charAt, 48) < 0) {
            i11 = 1;
            if (length == 1 || charAt != '+') {
                return null;
            }
        } else {
            i11 = 0;
        }
        int e10 = f0.e(i10);
        int i13 = 119304647;
        while (i11 < length) {
            int b10 = b.b(str.charAt(i11), i10);
            if (b10 < 0) {
                return null;
            }
            if (Integer.compareUnsigned(i12, i13) > 0) {
                if (i13 == 119304647) {
                    i13 = Integer.divideUnsigned(-1, e10);
                    if (Integer.compareUnsigned(i12, i13) > 0) {
                    }
                }
                return null;
            }
            int e11 = f0.e(i12 * e10);
            int e12 = f0.e(f0.e(b10) + e11);
            if (Integer.compareUnsigned(e12, e11) < 0) {
                return null;
            }
            i11++;
            i12 = e12;
        }
        return f0.a(i12);
    }

    public static final long h(String str) {
        kotlin.jvm.internal.t.g(str, "<this>");
        h0 i10 = i(str);
        if (i10 != null) {
            return i10.t();
        }
        x.l(str);
        throw new rm.k();
    }

    public static final h0 i(String str) {
        kotlin.jvm.internal.t.g(str, "<this>");
        return j(str, 10);
    }

    public static final h0 j(String str, int i10) {
        kotlin.jvm.internal.t.g(str, "<this>");
        b.a(i10);
        int length = str.length();
        if (length == 0) {
            return null;
        }
        int i11 = 0;
        char charAt = str.charAt(0);
        if (kotlin.jvm.internal.t.i(charAt, 48) < 0) {
            i11 = 1;
            if (length == 1 || charAt != '+') {
                return null;
            }
        }
        long e10 = h0.e(i10);
        long j10 = 0;
        long j11 = 512409557603043100L;
        while (i11 < length) {
            if (b.b(str.charAt(i11), i10) < 0) {
                return null;
            }
            if (Long.compareUnsigned(j10, j11) > 0) {
                if (j11 == 512409557603043100L) {
                    j11 = Long.divideUnsigned(-1L, e10);
                    if (Long.compareUnsigned(j10, j11) > 0) {
                    }
                }
                return null;
            }
            long e11 = h0.e(j10 * e10);
            long e12 = h0.e(h0.e(f0.e(r13) & 4294967295L) + e11);
            if (Long.compareUnsigned(e12, e11) < 0) {
                return null;
            }
            i11++;
            j10 = e12;
        }
        return h0.a(j10);
    }

    public static final short k(String str) {
        kotlin.jvm.internal.t.g(str, "<this>");
        k0 m10 = m(str);
        if (m10 != null) {
            return m10.s();
        }
        x.l(str);
        throw new rm.k();
    }

    public static final short l(String str, int i10) {
        kotlin.jvm.internal.t.g(str, "<this>");
        k0 n10 = n(str, i10);
        if (n10 != null) {
            return n10.s();
        }
        x.l(str);
        throw new rm.k();
    }

    public static final k0 m(String str) {
        kotlin.jvm.internal.t.g(str, "<this>");
        return n(str, 10);
    }

    public static final k0 n(String str, int i10) {
        kotlin.jvm.internal.t.g(str, "<this>");
        f0 g10 = g(str, i10);
        if (g10 == null) {
            return null;
        }
        int s10 = g10.s();
        if (Integer.compareUnsigned(s10, f0.e(65535)) > 0) {
            return null;
        }
        return k0.a(k0.e((short) s10));
    }
}
