package n9; import com.google.android.gms.ads.RequestConfiguration; import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; /* loaded from: classes2.dex */ public final class y { /* renamed from: j, reason: collision with root package name */ private static final char[] f12519j = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; /* renamed from: a, reason: collision with root package name */ final String f12520a; /* renamed from: b, reason: collision with root package name */ private final String f12521b; /* renamed from: c, reason: collision with root package name */ private final String f12522c; /* renamed from: d, reason: collision with root package name */ final String f12523d; /* renamed from: e, reason: collision with root package name */ final int f12524e; /* renamed from: f, reason: collision with root package name */ private final List f12525f; /* renamed from: g, reason: collision with root package name */ private final List f12526g; /* renamed from: h, reason: collision with root package name */ private final String f12527h; /* renamed from: i, reason: collision with root package name */ private final String f12528i; public static final class a { /* renamed from: a, reason: collision with root package name */ String f12529a; /* renamed from: d, reason: collision with root package name */ String f12532d; /* renamed from: f, reason: collision with root package name */ final List f12534f; /* renamed from: g, reason: collision with root package name */ List f12535g; /* renamed from: h, reason: collision with root package name */ String f12536h; /* renamed from: b, reason: collision with root package name */ String f12530b = RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED; /* renamed from: c, reason: collision with root package name */ String f12531c = RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED; /* renamed from: e, reason: collision with root package name */ int f12533e = -1; public a() { ArrayList arrayList = new ArrayList(); this.f12534f = arrayList; arrayList.add(RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED); } private static String c(String str, int i10, int i11) { return o9.e.d(y.t(str, i10, i11, false)); } private boolean g(String str) { return str.equals(".") || str.equalsIgnoreCase("%2e"); } private boolean h(String str) { return str.equals("..") || str.equalsIgnoreCase("%2e.") || str.equalsIgnoreCase(".%2e") || str.equalsIgnoreCase("%2e%2e"); } private static int j(String str, int i10, int i11) { int parseInt; try { parseInt = Integer.parseInt(y.a(str, i10, i11, RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED, false, false, false, true, null)); } catch (NumberFormatException unused) { } if (parseInt <= 0 || parseInt > 65535) { return -1; } return parseInt; } private void l() { if (!((String) this.f12534f.remove(r0.size() - 1)).isEmpty() || this.f12534f.isEmpty()) { this.f12534f.add(RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED); } else { this.f12534f.set(r0.size() - 1, RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED); } } private static int n(String str, int i10, int i11) { while (i10 < i11) { char charAt = str.charAt(i10); if (charAt == ':') { return i10; } if (charAt == '[') { do { i10++; if (i10 < i11) { } } while (str.charAt(i10) != ']'); } i10++; } return i11; } private void o(String str, int i10, int i11, boolean z10, boolean z11) { String a10 = y.a(str, i10, i11, " \"<>^`{}|/\\?#", z11, false, false, true, null); if (g(a10)) { return; } if (h(a10)) { l(); return; } if (((String) this.f12534f.get(r11.size() - 1)).isEmpty()) { this.f12534f.set(r11.size() - 1, a10); } else { this.f12534f.add(a10); } if (z10) { this.f12534f.add(RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED); } } private void q(String str, int i10, int i11) { if (i10 == i11) { return; } char charAt = str.charAt(i10); if (charAt == '/' || charAt == '\\') { this.f12534f.clear(); this.f12534f.add(RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED); i10++; } else { List list = this.f12534f; list.set(list.size() - 1, RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED); } while (true) { int i12 = i10; if (i12 >= i11) { return; } i10 = o9.e.o(str, i12, i11, "/\\"); boolean z10 = i10 < i11; o(str, i12, i10, z10, true); if (z10) { i10++; } } } private static int s(String str, int i10, int i11) { if (i11 - i10 < 2) { return -1; } char charAt = str.charAt(i10); if ((charAt >= 'a' && charAt <= 'z') || (charAt >= 'A' && charAt <= 'Z')) { while (true) { i10++; if (i10 >= i11) { break; } char charAt2 = str.charAt(i10); if (charAt2 < 'a' || charAt2 > 'z') { if (charAt2 < 'A' || charAt2 > 'Z') { if (charAt2 < '0' || charAt2 > '9') { if (charAt2 != '+' && charAt2 != '-' && charAt2 != '.') { if (charAt2 == ':') { return i10; } } } } } } } return -1; } private static int t(String str, int i10, int i11) { int i12 = 0; while (i10 < i11) { char charAt = str.charAt(i10); if (charAt != '\\' && charAt != '/') { break; } i12++; i10++; } return i12; } public a a(String str, String str2) { if (str == null) { throw new NullPointerException("name == null"); } if (this.f12535g == null) { this.f12535g = new ArrayList(); } this.f12535g.add(y.b(str, " !\"#$&'(),/:;<=>?@[]\\^`{|}~", false, false, true, true)); this.f12535g.add(str2 != null ? y.b(str2, " !\"#$&'(),/:;<=>?@[]\\^`{|}~", false, false, true, true) : null); return this; } public y b() { if (this.f12529a == null) { throw new IllegalStateException("scheme == null"); } if (this.f12532d != null) { return new y(this); } throw new IllegalStateException("host == null"); } int d() { int i10 = this.f12533e; return i10 != -1 ? i10 : y.d(this.f12529a); } public a e(String str) { this.f12535g = str != null ? y.A(y.b(str, " \"'<>#", true, false, true, true)) : null; return this; } public a f(String str) { if (str == null) { throw new NullPointerException("host == null"); } String c10 = c(str, 0, str.length()); if (c10 != null) { this.f12532d = c10; return this; } throw new IllegalArgumentException("unexpected host: " + str); } a i(y yVar, String str) { int o10; int i10; int G = o9.e.G(str, 0, str.length()); int H = o9.e.H(str, G, str.length()); int s10 = s(str, G, H); if (s10 != -1) { if (str.regionMatches(true, G, "https:", 0, 6)) { this.f12529a = "https"; G += 6; } else { if (!str.regionMatches(true, G, "http:", 0, 5)) { throw new IllegalArgumentException("Expected URL scheme 'http' or 'https' but was '" + str.substring(0, s10) + "'"); } this.f12529a = "http"; G += 5; } } else { if (yVar == null) { throw new IllegalArgumentException("Expected URL scheme 'http' or 'https' but no colon was found"); } this.f12529a = yVar.f12520a; } int t10 = t(str, G, H); char c10 = '?'; char c11 = '#'; if (t10 >= 2 || yVar == null || !yVar.f12520a.equals(this.f12529a)) { int i11 = G + t10; boolean z10 = false; boolean z11 = false; while (true) { o10 = o9.e.o(str, i11, H, "@/\\?#"); char charAt = o10 != H ? str.charAt(o10) : (char) 65535; if (charAt == 65535 || charAt == c11 || charAt == '/' || charAt == '\\' || charAt == c10) { break; } if (charAt == '@') { if (z10) { i10 = o10; this.f12531c += "%40" + y.a(str, i11, i10, " \"':;<=>@[]^`{}|/\\?#", true, false, false, true, null); } else { int n10 = o9.e.n(str, i11, o10, ':'); i10 = o10; String a10 = y.a(str, i11, n10, " \"':;<=>@[]^`{}|/\\?#", true, false, false, true, null); if (z11) { a10 = this.f12530b + "%40" + a10; } this.f12530b = a10; if (n10 != i10) { this.f12531c = y.a(str, n10 + 1, i10, " \"':;<=>@[]^`{}|/\\?#", true, false, false, true, null); z10 = true; } z11 = true; } i11 = i10 + 1; } c10 = '?'; c11 = '#'; } int n11 = n(str, i11, o10); int i12 = n11 + 1; if (i12 < o10) { this.f12532d = c(str, i11, n11); int j10 = j(str, i12, o10); this.f12533e = j10; if (j10 == -1) { throw new IllegalArgumentException("Invalid URL port: \"" + str.substring(i12, o10) + '\"'); } } else { this.f12532d = c(str, i11, n11); this.f12533e = y.d(this.f12529a); } if (this.f12532d == null) { throw new IllegalArgumentException("Invalid URL host: \"" + str.substring(i11, n11) + '\"'); } G = o10; } else { this.f12530b = yVar.j(); this.f12531c = yVar.f(); this.f12532d = yVar.f12523d; this.f12533e = yVar.f12524e; this.f12534f.clear(); this.f12534f.addAll(yVar.h()); if (G == H || str.charAt(G) == '#') { e(yVar.i()); } } int o11 = o9.e.o(str, G, H, "?#"); q(str, G, o11); if (o11 < H && str.charAt(o11) == '?') { int n12 = o9.e.n(str, o11, H, '#'); this.f12535g = y.A(y.a(str, o11 + 1, n12, " \"'<>#", true, false, true, true, null)); o11 = n12; } if (o11 < H && str.charAt(o11) == '#') { this.f12536h = y.a(str, 1 + o11, H, RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED, true, false, false, false, null); } return this; } public a k(String str) { if (str == null) { throw new NullPointerException("password == null"); } this.f12531c = y.b(str, " \"':;<=>@[]^`{}|/\\?#", false, false, false, true); return this; } public a m(int i10) { if (i10 > 0 && i10 <= 65535) { this.f12533e = i10; return this; } throw new IllegalArgumentException("unexpected port: " + i10); } a p() { int size = this.f12534f.size(); for (int i10 = 0; i10 < size; i10++) { this.f12534f.set(i10, y.b((String) this.f12534f.get(i10), "[]", true, true, false, true)); } List list = this.f12535g; if (list != null) { int size2 = list.size(); for (int i11 = 0; i11 < size2; i11++) { String str = (String) this.f12535g.get(i11); if (str != null) { this.f12535g.set(i11, y.b(str, "\\^`{|}", true, true, true, true)); } } } String str2 = this.f12536h; if (str2 != null) { this.f12536h = y.b(str2, " \"#<>\\^`{|}", true, true, false, false); } return this; } public a r(String str) { if (str == null) { throw new NullPointerException("scheme == null"); } if (str.equalsIgnoreCase("http")) { this.f12529a = "http"; } else { if (!str.equalsIgnoreCase("https")) { throw new IllegalArgumentException("unexpected scheme: " + str); } this.f12529a = "https"; } return this; } public String toString() { StringBuilder sb = new StringBuilder(); String str = this.f12529a; if (str != null) { sb.append(str); sb.append("://"); } else { sb.append("//"); } if (!this.f12530b.isEmpty() || !this.f12531c.isEmpty()) { sb.append(this.f12530b); if (!this.f12531c.isEmpty()) { sb.append(':'); sb.append(this.f12531c); } sb.append('@'); } String str2 = this.f12532d; if (str2 != null) { if (str2.indexOf(58) != -1) { sb.append('['); sb.append(this.f12532d); sb.append(']'); } else { sb.append(this.f12532d); } } if (this.f12533e != -1 || this.f12529a != null) { int d10 = d(); String str3 = this.f12529a; if (str3 == null || d10 != y.d(str3)) { sb.append(':'); sb.append(d10); } } y.s(sb, this.f12534f); if (this.f12535g != null) { sb.append('?'); y.n(sb, this.f12535g); } if (this.f12536h != null) { sb.append('#'); sb.append(this.f12536h); } return sb.toString(); } public a u(String str) { if (str == null) { throw new NullPointerException("username == null"); } this.f12530b = y.b(str, " \"':;<=>@[]^`{}|/\\?#", false, false, false, true); return this; } } y(a aVar) { this.f12520a = aVar.f12529a; this.f12521b = u(aVar.f12530b, false); this.f12522c = u(aVar.f12531c, false); this.f12523d = aVar.f12532d; this.f12524e = aVar.d(); this.f12525f = v(aVar.f12534f, false); List list = aVar.f12535g; this.f12526g = list != null ? v(list, true) : null; String str = aVar.f12536h; this.f12527h = str != null ? u(str, false) : null; this.f12528i = aVar.toString(); } static List A(String str) { ArrayList arrayList = new ArrayList(); int i10 = 0; while (i10 <= str.length()) { int indexOf = str.indexOf(38, i10); if (indexOf == -1) { indexOf = str.length(); } int indexOf2 = str.indexOf(61, i10); if (indexOf2 == -1 || indexOf2 > indexOf) { arrayList.add(str.substring(i10, indexOf)); arrayList.add(null); } else { arrayList.add(str.substring(i10, indexOf2)); arrayList.add(str.substring(indexOf2 + 1, indexOf)); } i10 = indexOf + 1; } return arrayList; } static String a(String str, int i10, int i11, String str2, boolean z10, boolean z11, boolean z12, boolean z13, Charset charset) { int i12 = i10; while (i12 < i11) { int codePointAt = str.codePointAt(i12); if (codePointAt >= 32 && codePointAt != 127 && (codePointAt < 128 || !z13)) { if (str2.indexOf(codePointAt) == -1 && ((codePointAt != 37 || (z10 && (!z11 || x(str, i12, i11)))) && (codePointAt != 43 || !z12))) { i12 += Character.charCount(codePointAt); } } x9.c cVar = new x9.c(); cVar.Q0(str, i10, i12); c(cVar, str, i12, i11, str2, z10, z11, z12, z13, charset); return cVar.m0(); } return str.substring(i10, i11); } static String b(String str, String str2, boolean z10, boolean z11, boolean z12, boolean z13) { return a(str, 0, str.length(), str2, z10, z11, z12, z13, null); } static void c(x9.c cVar, String str, int i10, int i11, String str2, boolean z10, boolean z11, boolean z12, boolean z13, Charset charset) { x9.c cVar2 = null; while (i10 < i11) { int codePointAt = str.codePointAt(i10); if (!z10 || (codePointAt != 9 && codePointAt != 10 && codePointAt != 12 && codePointAt != 13)) { if (codePointAt == 43 && z12) { cVar.j(z10 ? "+" : "%2B"); } else if (codePointAt < 32 || codePointAt == 127 || ((codePointAt >= 128 && z13) || str2.indexOf(codePointAt) != -1 || (codePointAt == 37 && (!z10 || (z11 && !x(str, i10, i11)))))) { if (cVar2 == null) { cVar2 = new x9.c(); } if (charset == null || charset.equals(StandardCharsets.UTF_8)) { cVar2.R0(codePointAt); } else { cVar2.N0(str, i10, Character.charCount(codePointAt) + i10, charset); } while (!cVar2.g()) { int readByte = cVar2.readByte() & 255; cVar.h(37); char[] cArr = f12519j; cVar.h(cArr[(readByte >> 4) & 15]); cVar.h(cArr[readByte & 15]); } } else { cVar.R0(codePointAt); } } i10 += Character.charCount(codePointAt); } } public static int d(String str) { if (str.equals("http")) { return 80; } return str.equals("https") ? 443 : -1; } public static y k(String str) { return new a().i(null, str).b(); } static void n(StringBuilder sb, List list) { int size = list.size(); for (int i10 = 0; i10 < size; i10 += 2) { String str = (String) list.get(i10); String str2 = (String) list.get(i10 + 1); if (i10 > 0) { sb.append('&'); } sb.append(str); if (str2 != null) { sb.append('='); sb.append(str2); } } } public static y q(String str) { try { return k(str); } catch (IllegalArgumentException unused) { return null; } } static void s(StringBuilder sb, List list) { int size = list.size(); for (int i10 = 0; i10 < size; i10++) { sb.append('/'); sb.append((String) list.get(i10)); } } static String t(String str, int i10, int i11, boolean z10) { for (int i12 = i10; i12 < i11; i12++) { char charAt = str.charAt(i12); if (charAt == '%' || (charAt == '+' && z10)) { x9.c cVar = new x9.c(); cVar.Q0(str, i10, i12); w(cVar, str, i12, i11, z10); return cVar.m0(); } } return str.substring(i10, i11); } static String u(String str, boolean z10) { return t(str, 0, str.length(), z10); } private List v(List list, boolean z10) { int size = list.size(); ArrayList arrayList = new ArrayList(size); for (int i10 = 0; i10 < size; i10++) { String str = (String) list.get(i10); arrayList.add(str != null ? u(str, z10) : null); } return Collections.unmodifiableList(arrayList); } static void w(x9.c cVar, String str, int i10, int i11, boolean z10) { int i12; while (i10 < i11) { int codePointAt = str.codePointAt(i10); if (codePointAt != 37 || (i12 = i10 + 2) >= i11) { if (codePointAt == 43 && z10) { cVar.h(32); } cVar.R0(codePointAt); } else { int k10 = o9.e.k(str.charAt(i10 + 1)); int k11 = o9.e.k(str.charAt(i12)); if (k10 != -1 && k11 != -1) { cVar.h((k10 << 4) + k11); i10 = i12; } cVar.R0(codePointAt); } i10 += Character.charCount(codePointAt); } } static boolean x(String str, int i10, int i11) { int i12 = i10 + 2; return i12 < i11 && str.charAt(i10) == '%' && o9.e.k(str.charAt(i10 + 1)) != -1 && o9.e.k(str.charAt(i12)) != -1; } public String B() { return p("/...").u(RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED).k(RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED).b().toString(); } public y C(String str) { a p10 = p(str); if (p10 != null) { return p10.b(); } return null; } public String D() { return this.f12520a; } public URI E() { String aVar = o().p().toString(); try { return new URI(aVar); } catch (URISyntaxException e10) { try { return URI.create(aVar.replaceAll("[\\u0000-\\u001F\\u007F-\\u009F\\p{javaWhitespace}]", RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED)); } catch (Exception unused) { throw new RuntimeException(e10); } } } public String e() { if (this.f12527h == null) { return null; } return this.f12528i.substring(this.f12528i.indexOf(35) + 1); } public boolean equals(Object obj) { return (obj instanceof y) && ((y) obj).f12528i.equals(this.f12528i); } public String f() { if (this.f12522c.isEmpty()) { return RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED; } return this.f12528i.substring(this.f12528i.indexOf(58, this.f12520a.length() + 3) + 1, this.f12528i.indexOf(64)); } public String g() { int indexOf = this.f12528i.indexOf(47, this.f12520a.length() + 3); String str = this.f12528i; return this.f12528i.substring(indexOf, o9.e.o(str, indexOf, str.length(), "?#")); } public List h() { int indexOf = this.f12528i.indexOf(47, this.f12520a.length() + 3); String str = this.f12528i; int o10 = o9.e.o(str, indexOf, str.length(), "?#"); ArrayList arrayList = new ArrayList(); while (indexOf < o10) { int i10 = indexOf + 1; int n10 = o9.e.n(this.f12528i, i10, o10, '/'); arrayList.add(this.f12528i.substring(i10, n10)); indexOf = n10; } return arrayList; } public int hashCode() { return this.f12528i.hashCode(); } public String i() { if (this.f12526g == null) { return null; } int indexOf = this.f12528i.indexOf(63) + 1; String str = this.f12528i; return this.f12528i.substring(indexOf, o9.e.n(str, indexOf, str.length(), '#')); } public String j() { if (this.f12521b.isEmpty()) { return RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED; } int length = this.f12520a.length() + 3; String str = this.f12528i; return this.f12528i.substring(length, o9.e.o(str, length, str.length(), ":@")); } public String l() { return this.f12523d; } public boolean m() { return this.f12520a.equals("https"); } public a o() { a aVar = new a(); aVar.f12529a = this.f12520a; aVar.f12530b = j(); aVar.f12531c = f(); aVar.f12532d = this.f12523d; aVar.f12533e = this.f12524e != d(this.f12520a) ? this.f12524e : -1; aVar.f12534f.clear(); aVar.f12534f.addAll(h()); aVar.e(i()); aVar.f12536h = e(); return aVar; } public a p(String str) { try { return new a().i(this, str); } catch (IllegalArgumentException unused) { return null; } } public List r() { return this.f12525f; } public String toString() { return this.f12528i; } public int y() { return this.f12524e; } public String z() { if (this.f12526g == null) { return null; } StringBuilder sb = new StringBuilder(); n(sb, this.f12526g); return sb.toString(); } }