package okhttp3;

import A0.a;
import P4.e;
import S4.p;
import S4.w;
import androidx.media3.extractor.ts.PsExtractor;
import java.io.EOFException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.regex.Pattern;
import kotlin.jvm.internal.o;
import okhttp3.internal.HostnamesKt;
import okhttp3.internal.Util;
import p5.C2740j;
import q.AbstractC2761L;
import x4.AbstractC3253s;

/* JADX INFO: loaded from: classes3.dex */
public final class HttpUrl {

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public static final Companion f22023k = new Companion(0);
    public static final char[] l = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final String f22024a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final String f22025b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final String f22026c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final String f22027d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final int f22028e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final ArrayList f22029f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final ArrayList f22030g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final String f22031h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final String f22032i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final boolean f22033j;

    public static final class Builder {

        /* JADX INFO: renamed from: i, reason: collision with root package name */
        public static final Companion f22034i = new Companion(0);

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public String f22035a;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public String f22038d;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public final ArrayList f22040f;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        public ArrayList f22041g;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        public String f22042h;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public String f22036b = "";

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public String f22037c = "";

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        public int f22039e = -1;

        public static final class Companion {
            public /* synthetic */ Companion(int i6) {
                this();
            }

            private Companion() {
            }
        }

        public Builder() {
            ArrayList arrayList = new ArrayList();
            this.f22040f = arrayList;
            arrayList.add("");
        }

        public final HttpUrl a() {
            ArrayList arrayList;
            String str = this.f22035a;
            if (str == null) {
                throw new IllegalStateException("scheme == null");
            }
            Companion companion = HttpUrl.f22023k;
            String strD = Companion.d(companion, this.f22036b, 0, 0, 7);
            String strD2 = Companion.d(companion, this.f22037c, 0, 0, 7);
            String str2 = this.f22038d;
            if (str2 == null) {
                throw new IllegalStateException("host == null");
            }
            int iB = this.f22039e;
            if (iB == -1) {
                String str3 = this.f22035a;
                o.e(str3);
                companion.getClass();
                iB = Companion.b(str3);
            }
            ArrayList arrayList2 = this.f22040f;
            ArrayList arrayList3 = new ArrayList(AbstractC3253s.G(arrayList2, 10));
            Iterator it = arrayList2.iterator();
            while (it.hasNext()) {
                arrayList3.add(Companion.d(HttpUrl.f22023k, (String) it.next(), 0, 0, 7));
            }
            ArrayList<String> arrayList4 = this.f22041g;
            if (arrayList4 != null) {
                arrayList = new ArrayList(AbstractC3253s.G(arrayList4, 10));
                for (String str4 : arrayList4) {
                    arrayList.add(str4 != null ? Companion.d(HttpUrl.f22023k, str4, 0, 0, 3) : null);
                }
            } else {
                arrayList = null;
            }
            String str5 = this.f22042h;
            return new HttpUrl(str, strD, strD2, str2, iB, arrayList3, arrayList, str5 != null ? Companion.d(HttpUrl.f22023k, str5, 0, 0, 7) : null, toString());
        }

        /* JADX WARN: Removed duplicated region for block: B:39:0x0085  */
        /* JADX WARN: Removed duplicated region for block: B:74:0x013c  */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final void b(HttpUrl httpUrl, String str) throws EOFException {
            int i6;
            char c6;
            int iE;
            int i7;
            int i8;
            int i9;
            char cCharAt;
            String input = str;
            o.h(input, "input");
            byte[] bArr = Util.f22179a;
            int iM = Util.m(0, input.length(), input);
            int iN = Util.n(iM, input.length(), input);
            f22034i.getClass();
            if (iN - iM < 2) {
                i6 = -1;
            } else {
                char cCharAt2 = input.charAt(iM);
                char c7 = 'a';
                if ((o.i(cCharAt2, 97) >= 0 && o.i(cCharAt2, 122) <= 0) || (o.i(cCharAt2, 65) >= 0 && o.i(cCharAt2, 90) <= 0)) {
                    i6 = iM + 1;
                    while (true) {
                        if (i6 >= iN) {
                            break;
                        }
                        char cCharAt3 = input.charAt(i6);
                        if ((c7 <= cCharAt3 && cCharAt3 < '{') || (('A' <= cCharAt3 && cCharAt3 < '[') || (('0' <= cCharAt3 && cCharAt3 < ':') || cCharAt3 == '+' || cCharAt3 == '-' || cCharAt3 == '.'))) {
                            i6++;
                            c7 = 'a';
                        } else if (cCharAt3 != ':') {
                            break;
                        }
                    }
                    i6 = -1;
                }
            }
            if (i6 != -1) {
                if (w.z0(input, "https:", iM, true)) {
                    this.f22035a = "https";
                    iM += 6;
                } else {
                    if (!w.z0(input, "http:", iM, true)) {
                        StringBuilder sb = new StringBuilder("Expected URL scheme 'http' or 'https' but was '");
                        String strSubstring = input.substring(0, i6);
                        o.g(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
                        sb.append(strSubstring);
                        sb.append('\'');
                        throw new IllegalArgumentException(sb.toString());
                    }
                    this.f22035a = "http";
                    iM += 5;
                }
            } else {
                if (httpUrl == null) {
                    throw new IllegalArgumentException(a.n("Expected URL scheme 'http' or 'https' but no scheme was found for ", input.length() > 6 ? p.m1(6, input).concat("...") : input));
                }
                this.f22035a = httpUrl.f22024a;
            }
            int i10 = iM;
            int i11 = 0;
            while (true) {
                c6 = '\\';
                if (i10 >= iN || !((cCharAt = input.charAt(i10)) == '\\' || cCharAt == '/')) {
                    break;
                }
                i11++;
                i10++;
            }
            ArrayList arrayList = this.f22040f;
            char c8 = '?';
            char c9 = '#';
            if (i11 >= 2 || httpUrl == null) {
                int i12 = iM + i11;
                boolean z6 = false;
                boolean z7 = false;
                while (true) {
                    iE = Util.e(i12, iN, input, "@/\\?#");
                    byte bCharAt = iE != iN ? input.charAt(iE) : (byte) -1;
                    if (bCharAt == -1 || bCharAt == c9 || bCharAt == 47 || bCharAt == c6 || bCharAt == c8) {
                        break;
                    }
                    if (bCharAt == 64) {
                        if (z6) {
                            int i13 = i12;
                            i9 = iE;
                            StringBuilder sb2 = new StringBuilder();
                            sb2.append(this.f22037c);
                            sb2.append("%40");
                            input = str;
                            sb2.append(Companion.a(HttpUrl.f22023k, input, i13, i9, " \"':;<=>@[]^`{}|/\\?#", PsExtractor.VIDEO_STREAM_MASK));
                            this.f22037c = sb2.toString();
                        } else {
                            int i14 = i12;
                            int iF = Util.f(input, ':', i14, iE);
                            Companion companion = HttpUrl.f22023k;
                            String strA = Companion.a(companion, input, i14, iF, " \"':;<=>@[]^`{}|/\\?#", PsExtractor.VIDEO_STREAM_MASK);
                            if (z7) {
                                strA = this.f22036b + "%40" + strA;
                            }
                            this.f22036b = strA;
                            if (iF != iE) {
                                int i15 = iF + 1;
                                i9 = iE;
                                this.f22037c = Companion.a(companion, str, i15, i9, " \"':;<=>@[]^`{}|/\\?#", PsExtractor.VIDEO_STREAM_MASK);
                                z6 = true;
                            } else {
                                i9 = iE;
                            }
                            input = str;
                            z7 = true;
                        }
                        i12 = i9 + 1;
                        c8 = '?';
                        c9 = '#';
                        c6 = '\\';
                    }
                }
                int i16 = i12;
                iM = iE;
                int i17 = i16;
                while (true) {
                    if (i17 >= iM) {
                        i7 = iM;
                        break;
                    }
                    char cCharAt4 = input.charAt(i17);
                    if (cCharAt4 == '[') {
                        do {
                            i17++;
                            if (i17 < iM) {
                            }
                        } while (input.charAt(i17) != ']');
                    } else if (cCharAt4 == ':') {
                        i7 = i17;
                        break;
                    }
                    i17++;
                }
                int i18 = i7 + 1;
                if (i18 < iM) {
                    Companion companion2 = HttpUrl.f22023k;
                    this.f22038d = HostnamesKt.b(Companion.d(companion2, input, i16, i7, 4));
                    try {
                        i8 = Integer.parseInt(Companion.a(companion2, input, i18, iM, "", 248));
                    } catch (NumberFormatException unused) {
                    }
                    if (1 > i8 || i8 >= 65536) {
                        i8 = -1;
                    }
                    this.f22039e = i8;
                    if (i8 == -1) {
                        StringBuilder sb3 = new StringBuilder("Invalid URL port: \"");
                        String strSubstring2 = input.substring(i18, iM);
                        o.g(strSubstring2, "this as java.lang.String…ing(startIndex, endIndex)");
                        sb3.append(strSubstring2);
                        sb3.append('\"');
                        throw new IllegalArgumentException(sb3.toString().toString());
                    }
                } else {
                    this.f22038d = HostnamesKt.b(Companion.d(HttpUrl.f22023k, input, i16, i7, 4));
                    String str2 = this.f22035a;
                    o.e(str2);
                    this.f22039e = Companion.b(str2);
                }
                if (this.f22038d == null) {
                    StringBuilder sb4 = new StringBuilder("Invalid URL host: \"");
                    String strSubstring3 = input.substring(i16, i7);
                    o.g(strSubstring3, "this as java.lang.String…ing(startIndex, endIndex)");
                    sb4.append(strSubstring3);
                    sb4.append('\"');
                    throw new IllegalArgumentException(sb4.toString().toString());
                }
            } else if (o.c(httpUrl.f22024a, this.f22035a)) {
                this.f22036b = httpUrl.e();
                this.f22037c = httpUrl.a();
                this.f22038d = httpUrl.f22027d;
                this.f22039e = httpUrl.f22028e;
                arrayList.clear();
                arrayList.addAll(httpUrl.c());
                if (iM == iN || input.charAt(iM) == '#') {
                    String strD = httpUrl.d();
                    this.f22041g = strD != null ? Companion.e(Companion.a(HttpUrl.f22023k, strD, 0, 0, " \"'<>#", 211)) : null;
                }
            }
            int iE2 = Util.e(iM, iN, input, "?#");
            if (iM != iE2) {
                char cCharAt5 = input.charAt(iM);
                if (cCharAt5 == '/' || cCharAt5 == '\\') {
                    arrayList.clear();
                    arrayList.add("");
                    iM++;
                } else {
                    arrayList.set(arrayList.size() - 1, "");
                }
                loop2: while (true) {
                    int i19 = iM;
                    while (i19 < iE2) {
                        iM = Util.e(i19, iE2, input, "/\\");
                        boolean z8 = iM < iE2;
                        String strA2 = Companion.a(HttpUrl.f22023k, input, i19, iM, " \"<>^`{}|/\\?#", PsExtractor.VIDEO_STREAM_MASK);
                        if (!strA2.equals(".") && !strA2.equalsIgnoreCase("%2e")) {
                            if (!strA2.equals("..") && !strA2.equalsIgnoreCase("%2e.") && !strA2.equalsIgnoreCase(".%2e") && !strA2.equalsIgnoreCase("%2e%2e")) {
                                if (((CharSequence) AbstractC2761L.f(1, arrayList)).length() == 0) {
                                    arrayList.set(arrayList.size() - 1, strA2);
                                } else {
                                    arrayList.add(strA2);
                                }
                                if (z8) {
                                    arrayList.add("");
                                }
                            } else if (((String) arrayList.remove(arrayList.size() - 1)).length() != 0 || arrayList.isEmpty()) {
                                arrayList.add("");
                            } else {
                                arrayList.set(arrayList.size() - 1, "");
                            }
                        }
                        if (z8) {
                            i19 = iM + 1;
                        }
                    }
                }
            }
            if (iE2 < iN && input.charAt(iE2) == '?') {
                int iF2 = Util.f(input, '#', iE2, iN);
                this.f22041g = Companion.e(Companion.a(HttpUrl.f22023k, input, iE2 + 1, iF2, " \"'<>#", 208));
                iE2 = iF2;
            }
            if (iE2 >= iN || input.charAt(iE2) != '#') {
                return;
            }
            this.f22042h = Companion.a(HttpUrl.f22023k, input, iE2 + 1, iN, "", 176);
        }

        /* JADX WARN: Removed duplicated region for block: B:32:0x008c  */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final String toString() {
            StringBuilder sb = new StringBuilder();
            String str = this.f22035a;
            if (str != null) {
                sb.append(str);
                sb.append("://");
            } else {
                sb.append("//");
            }
            if (this.f22036b.length() > 0 || this.f22037c.length() > 0) {
                sb.append(this.f22036b);
                if (this.f22037c.length() > 0) {
                    sb.append(':');
                    sb.append(this.f22037c);
                }
                sb.append('@');
            }
            String str2 = this.f22038d;
            if (str2 != null) {
                if (p.E0(str2, ':')) {
                    sb.append('[');
                    sb.append(this.f22038d);
                    sb.append(']');
                } else {
                    sb.append(this.f22038d);
                }
            }
            int iB = this.f22039e;
            if (iB != -1 || this.f22035a != null) {
                if (iB == -1) {
                    Companion companion = HttpUrl.f22023k;
                    String str3 = this.f22035a;
                    o.e(str3);
                    companion.getClass();
                    iB = Companion.b(str3);
                }
                String str4 = this.f22035a;
                if (str4 != null) {
                    HttpUrl.f22023k.getClass();
                    if (iB != Companion.b(str4)) {
                        sb.append(':');
                        sb.append(iB);
                    }
                }
            }
            Companion companion2 = HttpUrl.f22023k;
            ArrayList arrayList = this.f22040f;
            companion2.getClass();
            o.h(arrayList, "<this>");
            int size = arrayList.size();
            for (int i6 = 0; i6 < size; i6++) {
                sb.append('/');
                sb.append((String) arrayList.get(i6));
            }
            if (this.f22041g != null) {
                sb.append('?');
                Companion companion3 = HttpUrl.f22023k;
                ArrayList arrayList2 = this.f22041g;
                o.e(arrayList2);
                companion3.getClass();
                Companion.f(arrayList2, sb);
            }
            if (this.f22042h != null) {
                sb.append('#');
                sb.append(this.f22042h);
            }
            String string = sb.toString();
            o.g(string, "StringBuilder().apply(builderAction).toString()");
            return string;
        }
    }

    public static final class Companion {
        public /* synthetic */ Companion(int i6) {
            this();
        }

        public static String a(Companion companion, String str, int i6, int i7, String str2, int i8) throws EOFException {
            int i9 = (i8 & 1) != 0 ? 0 : i6;
            int length = (i8 & 2) != 0 ? str.length() : i7;
            boolean z6 = (i8 & 8) == 0;
            boolean z7 = (i8 & 16) == 0;
            boolean z8 = (i8 & 32) == 0;
            boolean z9 = (i8 & 64) == 0;
            companion.getClass();
            o.h(str, "<this>");
            int iCharCount = i9;
            while (iCharCount < length) {
                int iCodePointAt = str.codePointAt(iCharCount);
                int i10 = 32;
                int i11 = 128;
                if (iCodePointAt < 32 || iCodePointAt == 127 || ((iCodePointAt >= 128 && !z9) || p.E0(str2, (char) iCodePointAt) || ((iCodePointAt == 37 && (!z6 || (z7 && !c(iCharCount, length, str)))) || (iCodePointAt == 43 && z8)))) {
                    C2740j c2740j = new C2740j();
                    c2740j.V(i9, iCharCount, str);
                    C2740j c2740j2 = null;
                    while (iCharCount < length) {
                        int iCodePointAt2 = str.codePointAt(iCharCount);
                        if (!z6 || (iCodePointAt2 != 9 && iCodePointAt2 != 10 && iCodePointAt2 != 12 && iCodePointAt2 != 13)) {
                            if (iCodePointAt2 == 43 && z8) {
                                c2740j.W(z6 ? "+" : "%2B");
                            } else if (iCodePointAt2 < i10 || iCodePointAt2 == 127 || ((iCodePointAt2 >= i11 && !z9) || p.E0(str2, (char) iCodePointAt2) || (iCodePointAt2 == 37 && (!z6 || (z7 && !c(iCharCount, length, str)))))) {
                                if (c2740j2 == null) {
                                    c2740j2 = new C2740j();
                                }
                                c2740j2.X(iCodePointAt2);
                                while (!c2740j2.d()) {
                                    byte bY = c2740j2.y();
                                    c2740j.Q(37);
                                    char[] cArr = HttpUrl.l;
                                    c2740j.Q(cArr[((bY & 255) >> 4) & 15]);
                                    c2740j.Q(cArr[bY & 15]);
                                }
                            } else {
                                c2740j.X(iCodePointAt2);
                            }
                        }
                        iCharCount += Character.charCount(iCodePointAt2);
                        i10 = 32;
                        i11 = 128;
                    }
                    return c2740j.H();
                }
                iCharCount += Character.charCount(iCodePointAt);
            }
            String strSubstring = str.substring(i9, length);
            o.g(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
            return strSubstring;
        }

        public static int b(String scheme) {
            o.h(scheme, "scheme");
            if (scheme.equals("http")) {
                return 80;
            }
            return scheme.equals("https") ? 443 : -1;
        }

        public static boolean c(int i6, int i7, String str) {
            int i8 = i6 + 2;
            return i8 < i7 && str.charAt(i6) == '%' && Util.q(str.charAt(i6 + 1)) != -1 && Util.q(str.charAt(i8)) != -1;
        }

        public static String d(Companion companion, String str, int i6, int i7, int i8) {
            int i9;
            if ((i8 & 1) != 0) {
                i6 = 0;
            }
            if ((i8 & 2) != 0) {
                i7 = str.length();
            }
            boolean z6 = (i8 & 4) == 0;
            companion.getClass();
            o.h(str, "<this>");
            int iCharCount = i6;
            while (iCharCount < i7) {
                char cCharAt = str.charAt(iCharCount);
                if (cCharAt == '%' || (cCharAt == '+' && z6)) {
                    C2740j c2740j = new C2740j();
                    c2740j.V(i6, iCharCount, str);
                    while (iCharCount < i7) {
                        int iCodePointAt = str.codePointAt(iCharCount);
                        if (iCodePointAt == 37 && (i9 = iCharCount + 2) < i7) {
                            int iQ = Util.q(str.charAt(iCharCount + 1));
                            int iQ2 = Util.q(str.charAt(i9));
                            if (iQ == -1 || iQ2 == -1) {
                                c2740j.X(iCodePointAt);
                                iCharCount += Character.charCount(iCodePointAt);
                            } else {
                                c2740j.Q((iQ << 4) + iQ2);
                                iCharCount = Character.charCount(iCodePointAt) + i9;
                            }
                        } else if (iCodePointAt == 43 && z6) {
                            c2740j.Q(32);
                            iCharCount++;
                        } else {
                            c2740j.X(iCodePointAt);
                            iCharCount += Character.charCount(iCodePointAt);
                        }
                    }
                    return c2740j.H();
                }
                iCharCount++;
            }
            String strSubstring = str.substring(i6, i7);
            o.g(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
            return strSubstring;
        }

        public static ArrayList e(String str) {
            ArrayList arrayList = new ArrayList();
            int i6 = 0;
            while (i6 <= str.length()) {
                int iN0 = p.N0(str, '&', i6, 4);
                if (iN0 == -1) {
                    iN0 = str.length();
                }
                int iN02 = p.N0(str, '=', i6, 4);
                if (iN02 == -1 || iN02 > iN0) {
                    String strSubstring = str.substring(i6, iN0);
                    o.g(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
                    arrayList.add(strSubstring);
                    arrayList.add(null);
                } else {
                    String strSubstring2 = str.substring(i6, iN02);
                    o.g(strSubstring2, "this as java.lang.String…ing(startIndex, endIndex)");
                    arrayList.add(strSubstring2);
                    String strSubstring3 = str.substring(iN02 + 1, iN0);
                    o.g(strSubstring3, "this as java.lang.String…ing(startIndex, endIndex)");
                    arrayList.add(strSubstring3);
                }
                i6 = iN0 + 1;
            }
            return arrayList;
        }

        public static void f(ArrayList arrayList, StringBuilder sb) {
            o.h(arrayList, "<this>");
            e eVarI0 = L4.a.i0(2, L4.a.l0(0, arrayList.size()));
            int i6 = eVarI0.f5676a;
            int i7 = eVarI0.f5677b;
            int i8 = eVarI0.f5678c;
            if ((i8 <= 0 || i6 > i7) && (i8 >= 0 || i7 > i6)) {
                return;
            }
            while (true) {
                String str = (String) arrayList.get(i6);
                String str2 = (String) arrayList.get(i6 + 1);
                if (i6 > 0) {
                    sb.append('&');
                }
                sb.append(str);
                if (str2 != null) {
                    sb.append('=');
                    sb.append(str2);
                }
                if (i6 == i7) {
                    return;
                } else {
                    i6 += i8;
                }
            }
        }

        private Companion() {
        }
    }

    public HttpUrl(String scheme, String str, String str2, String host, int i6, ArrayList arrayList, ArrayList arrayList2, String str3, String str4) {
        o.h(scheme, "scheme");
        o.h(host, "host");
        this.f22024a = scheme;
        this.f22025b = str;
        this.f22026c = str2;
        this.f22027d = host;
        this.f22028e = i6;
        this.f22029f = arrayList;
        this.f22030g = arrayList2;
        this.f22031h = str3;
        this.f22032i = str4;
        this.f22033j = scheme.equals("https");
    }

    public final String a() {
        if (this.f22026c.length() == 0) {
            return "";
        }
        int length = this.f22024a.length() + 3;
        String str = this.f22032i;
        String strSubstring = str.substring(p.N0(str, ':', length, 4) + 1, p.N0(str, '@', 0, 6));
        o.g(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public final String b() {
        int length = this.f22024a.length() + 3;
        String str = this.f22032i;
        int iN0 = p.N0(str, '/', length, 4);
        String strSubstring = str.substring(iN0, Util.e(iN0, str.length(), str, "?#"));
        o.g(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public final ArrayList c() {
        int length = this.f22024a.length() + 3;
        String str = this.f22032i;
        int iN0 = p.N0(str, '/', length, 4);
        int iE = Util.e(iN0, str.length(), str, "?#");
        ArrayList arrayList = new ArrayList();
        while (iN0 < iE) {
            int i6 = iN0 + 1;
            int iF = Util.f(str, '/', i6, iE);
            String strSubstring = str.substring(i6, iF);
            o.g(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
            arrayList.add(strSubstring);
            iN0 = iF;
        }
        return arrayList;
    }

    public final String d() {
        if (this.f22030g == null) {
            return null;
        }
        String str = this.f22032i;
        int iN0 = p.N0(str, '?', 0, 6) + 1;
        String strSubstring = str.substring(iN0, Util.f(str, '#', iN0, str.length()));
        o.g(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public final String e() {
        if (this.f22025b.length() == 0) {
            return "";
        }
        int length = this.f22024a.length() + 3;
        String str = this.f22032i;
        String strSubstring = str.substring(length, Util.e(length, str.length(), str, ":@"));
        o.g(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public final boolean equals(Object obj) {
        return (obj instanceof HttpUrl) && o.c(((HttpUrl) obj).f22032i, this.f22032i);
    }

    public final String f() throws EOFException {
        Builder builder;
        try {
            builder = new Builder();
            builder.b(this, "/...");
        } catch (IllegalArgumentException unused) {
            builder = null;
        }
        o.e(builder);
        Companion companion = f22023k;
        builder.f22036b = Companion.a(companion, "", 0, 0, " \"':;<=>@[]^`{}|/\\?#", 251);
        builder.f22037c = Companion.a(companion, "", 0, 0, " \"':;<=>@[]^`{}|/\\?#", 251);
        return builder.a().f22032i;
    }

    public final URI g() {
        String strSubstring;
        String strReplaceAll;
        Builder builder = new Builder();
        String str = this.f22024a;
        builder.f22035a = str;
        builder.f22036b = e();
        builder.f22037c = a();
        builder.f22038d = this.f22027d;
        Companion companion = f22023k;
        companion.getClass();
        int iB = Companion.b(str);
        int i6 = this.f22028e;
        if (i6 == iB) {
            i6 = -1;
        }
        builder.f22039e = i6;
        ArrayList arrayList = builder.f22040f;
        arrayList.clear();
        arrayList.addAll(c());
        String strD = d();
        builder.f22041g = strD != null ? Companion.e(Companion.a(companion, strD, 0, 0, " \"'<>#", 211)) : null;
        if (this.f22031h == null) {
            strSubstring = null;
        } else {
            String str2 = this.f22032i;
            strSubstring = str2.substring(p.N0(str2, '#', 0, 6) + 1);
            o.g(strSubstring, "this as java.lang.String).substring(startIndex)");
        }
        builder.f22042h = strSubstring;
        String str3 = builder.f22038d;
        if (str3 != null) {
            Pattern patternCompile = Pattern.compile("[\"<>^`{|}]");
            o.g(patternCompile, "compile(...)");
            strReplaceAll = patternCompile.matcher(str3).replaceAll("");
            o.g(strReplaceAll, "replaceAll(...)");
        } else {
            strReplaceAll = null;
        }
        builder.f22038d = strReplaceAll;
        int size = arrayList.size();
        for (int i7 = 0; i7 < size; i7++) {
            arrayList.set(i7, Companion.a(f22023k, (String) arrayList.get(i7), 0, 0, "[]", 227));
        }
        ArrayList arrayList2 = builder.f22041g;
        if (arrayList2 != null) {
            int size2 = arrayList2.size();
            for (int i8 = 0; i8 < size2; i8++) {
                String str4 = (String) arrayList2.get(i8);
                arrayList2.set(i8, str4 != null ? Companion.a(f22023k, str4, 0, 0, "\\^`{|}", 195) : null);
            }
        }
        String str5 = builder.f22042h;
        builder.f22042h = str5 != null ? Companion.a(f22023k, str5, 0, 0, " \"#<>\\^`{|}", 163) : null;
        String string = builder.toString();
        try {
            return new URI(string);
        } catch (URISyntaxException e6) {
            try {
                Pattern patternCompile2 = Pattern.compile("[\\u0000-\\u001F\\u007F-\\u009F\\p{javaWhitespace}]");
                o.g(patternCompile2, "compile(...)");
                String strReplaceAll2 = patternCompile2.matcher(string).replaceAll("");
                o.g(strReplaceAll2, "replaceAll(...)");
                URI uriCreate = URI.create(strReplaceAll2);
                o.g(uriCreate, "{\n      // Unlikely edge…Unexpected!\n      }\n    }");
                return uriCreate;
            } catch (Exception unused) {
                throw new RuntimeException(e6);
            }
        }
    }

    public final int hashCode() {
        return this.f22032i.hashCode();
    }

    public final String toString() {
        return this.f22032i;
    }
}
