package n9; import java.nio.charset.Charset; import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; /* loaded from: classes2.dex */ public final class a0 { /* renamed from: e, reason: collision with root package name */ private static final Pattern f12247e = Pattern.compile("([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)/([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)"); /* renamed from: f, reason: collision with root package name */ private static final Pattern f12248f = Pattern.compile(";\\s*(?:([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)=(?:([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)|\"([^\"]*)\"))?"); /* renamed from: a, reason: collision with root package name */ private final String f12249a; /* renamed from: b, reason: collision with root package name */ private final String f12250b; /* renamed from: c, reason: collision with root package name */ private final String f12251c; /* renamed from: d, reason: collision with root package name */ private final String f12252d; private a0(String str, String str2, String str3, String str4) { this.f12249a = str; this.f12250b = str2; this.f12251c = str3; this.f12252d = str4; } public static a0 c(String str) { Matcher matcher = f12247e.matcher(str); if (!matcher.lookingAt()) { throw new IllegalArgumentException("No subtype found for: \"" + str + '\"'); } String group = matcher.group(1); Locale locale = Locale.US; String lowerCase = group.toLowerCase(locale); String lowerCase2 = matcher.group(2).toLowerCase(locale); Matcher matcher2 = f12248f.matcher(str); String str2 = null; for (int end = matcher.end(); end < str.length(); end = matcher2.end()) { matcher2.region(end, str.length()); if (!matcher2.lookingAt()) { throw new IllegalArgumentException("Parameter is not formatted correctly: \"" + str.substring(end) + "\" for: \"" + str + '\"'); } String group2 = matcher2.group(1); if (group2 != null && group2.equalsIgnoreCase("charset")) { String group3 = matcher2.group(2); if (group3 == null) { group3 = matcher2.group(3); } else if (group3.startsWith("'") && group3.endsWith("'") && group3.length() > 2) { group3 = group3.substring(1, group3.length() - 1); } if (str2 != null && !group3.equalsIgnoreCase(str2)) { throw new IllegalArgumentException("Multiple charsets defined: \"" + str2 + "\" and: \"" + group3 + "\" for: \"" + str + '\"'); } str2 = group3; } } return new a0(str, lowerCase, lowerCase2, str2); } public static a0 d(String str) { try { return c(str); } catch (IllegalArgumentException unused) { return null; } } public Charset a() { return b(null); } public Charset b(Charset charset) { try { String str = this.f12252d; return str != null ? Charset.forName(str) : charset; } catch (IllegalArgumentException unused) { return charset; } } public boolean equals(Object obj) { return (obj instanceof a0) && ((a0) obj).f12249a.equals(this.f12249a); } public int hashCode() { return this.f12249a.hashCode(); } public String toString() { return this.f12249a; } }