package vq;

import com.google.android.gms.dynamite.descriptors.com.google.android.gms.measurement.dynamite.ModuleDescriptor;
import com.google.firebase.perf.util.Constants;
import kotlin.jvm.internal.t;
import kotlin.text.y;
import kotlin.text.z;

/* loaded from: classes3.dex */
public abstract class f {

    /* renamed from: a, reason: collision with root package name */
    private static final kotlin.text.l f40458a = new kotlin.text.l("([0-9a-fA-F]*:[0-9a-fA-F:.]*)|([\\d.]+)");

    public static final boolean a(String str) {
        t.g(str, "<this>");
        return f40458a.e(str);
    }

    public static final boolean b(String str) {
        int g02;
        t.g(str, "<this>");
        int length = str.length();
        for (int i10 = 0; i10 < length; i10++) {
            char charAt = str.charAt(i10);
            if (t.i(charAt, 31) <= 0 || t.i(charAt, ModuleDescriptor.MODULE_VERSION) >= 0) {
                return true;
            }
            g02 = z.g0(" #%/:?@[\\]", charAt, 0, false, 6, null);
            if (g02 != -1) {
                return true;
            }
        }
        return false;
    }

    public static final boolean c(String str) {
        int g02;
        t.g(str, "<this>");
        int length = str.length();
        if (!(1 <= length && length < 254)) {
            return true;
        }
        int i10 = 0;
        while (true) {
            g02 = z.g0(str, '.', i10, false, 4, null);
            int length2 = g02 == -1 ? str.length() - i10 : g02 - i10;
            if (!(1 <= length2 && length2 < 64)) {
                return true;
            }
            if (g02 == -1 || g02 == str.length() - 1) {
                break;
            }
            i10 = g02 + 1;
        }
        return false;
    }

    public static final boolean d(String input, int i10, int i11, byte[] address, int i12) {
        t.g(input, "input");
        t.g(address, "address");
        int i13 = i12;
        while (i10 < i11) {
            if (i13 == address.length) {
                return false;
            }
            if (i13 != i12) {
                if (input.charAt(i10) != '.') {
                    return false;
                }
                i10++;
            }
            int i14 = i10;
            int i15 = 0;
            while (i14 < i11) {
                char charAt = input.charAt(i14);
                if (t.i(charAt, 48) < 0 || t.i(charAt, 57) > 0) {
                    break;
                }
                if ((i15 == 0 && i10 != i14) || (i15 = ((i15 * 10) + charAt) - 48) > 255) {
                    return false;
                }
                i14++;
            }
            if (i14 - i10 == 0) {
                return false;
            }
            address[i13] = (byte) i15;
            i13++;
            i10 = i14;
        }
        return i13 == i12 + 4;
    }

    /* JADX WARN: Code restructure failed: missing block: B:25:0x009a, code lost:
    
        return null;
     */
    /* JADX WARN: Removed duplicated region for block: B:15:0x0070  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final byte[] e(String input, int i10, int i11) {
        boolean O;
        boolean O2;
        int i12;
        boolean O3;
        t.g(input, "input");
        byte[] bArr = new byte[16];
        int i13 = i10;
        int i14 = -1;
        int i15 = -1;
        int i16 = 0;
        while (true) {
            if (i13 < i11) {
                if (i16 != 16) {
                    int i17 = i13 + 2;
                    if (i17 <= i11) {
                        O3 = y.O(input, "::", i13, false, 4, null);
                        if (O3) {
                            if (i14 != -1) {
                                return null;
                            }
                            i16 += 2;
                            if (i17 == i11) {
                                i14 = i16;
                                break;
                            }
                            i15 = i17;
                            i14 = i16;
                            i13 = i15;
                            int i18 = 0;
                            while (i13 < i11) {
                                int A = m.A(input.charAt(i13));
                                if (A == -1) {
                                    break;
                                }
                                i18 = (i18 << 4) + A;
                                i13++;
                            }
                            i12 = i13 - i15;
                            if (i12 == 0 || i12 > 4) {
                                break;
                            }
                            int i19 = i16 + 1;
                            bArr[i16] = (byte) ((i18 >>> 8) & Constants.MAX_HOST_LENGTH);
                            i16 = i19 + 1;
                            bArr[i19] = (byte) (i18 & Constants.MAX_HOST_LENGTH);
                        }
                    }
                    if (i16 != 0) {
                        O = y.O(input, ":", i13, false, 4, null);
                        if (O) {
                            i13++;
                        } else {
                            O2 = y.O(input, ".", i13, false, 4, null);
                            if (!O2 || !d(input, i15, i11, bArr, i16 - 2)) {
                                return null;
                            }
                            i16 += 2;
                        }
                    }
                    i15 = i13;
                    i13 = i15;
                    int i182 = 0;
                    while (i13 < i11) {
                    }
                    i12 = i13 - i15;
                    if (i12 == 0) {
                        break;
                    }
                    break;
                }
                return null;
            }
            break;
        }
        if (i16 != 16) {
            if (i14 == -1) {
                return null;
            }
            sm.o.g(bArr, bArr, 16 - (i16 - i14), i14, i16);
            sm.o.s(bArr, (byte) 0, i14, (16 - i16) + i14);
        }
        return bArr;
    }

    public static final String f(byte[] address) {
        t.g(address, "address");
        int i10 = -1;
        int i11 = 0;
        int i12 = 0;
        int i13 = 0;
        while (i12 < address.length) {
            int i14 = i12;
            while (i14 < 16 && address[i14] == 0 && address[i14 + 1] == 0) {
                i14 += 2;
            }
            int i15 = i14 - i12;
            if (i15 > i13 && i15 >= 4) {
                i10 = i12;
                i13 = i15;
            }
            i12 = i14 + 2;
        }
        kr.d dVar = new kr.d();
        while (i11 < address.length) {
            if (i11 == i10) {
                dVar.F(58);
                i11 += i13;
                if (i11 == 16) {
                    dVar.F(58);
                }
            } else {
                if (i11 > 0) {
                    dVar.F(58);
                }
                dVar.h0((m.b(address[i11], Constants.MAX_HOST_LENGTH) << 8) | m.b(address[i11 + 1], Constants.MAX_HOST_LENGTH));
                i11 += 2;
            }
        }
        return dVar.N();
    }
}
