158 lines
6.9 KiB
Java
158 lines
6.9 KiB
Java
package okhttp3;
|
|
|
|
import d0.d0.f;
|
|
import d0.g0.t;
|
|
import d0.t.k;
|
|
import d0.z.d.m;
|
|
import java.nio.charset.Charset;
|
|
import java.util.ArrayList;
|
|
import java.util.Locale;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import kotlin.TypeCastException;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.ranges.IntProgression;
|
|
/* compiled from: MediaType.kt */
|
|
public final class MediaType {
|
|
public static final Pattern a = Pattern.compile("([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)/([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)");
|
|
public static final Pattern b = Pattern.compile(";\\s*(?:([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)=(?:([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)|\"([^\"]*)\"))?");
|
|
|
|
/* renamed from: c reason: collision with root package name */
|
|
public static final a f2851c = null;
|
|
public final String d;
|
|
public final String e;
|
|
public final String f;
|
|
public final String[] g;
|
|
|
|
/* compiled from: MediaType.kt */
|
|
public static final class a {
|
|
public static final MediaType a(String str) {
|
|
m.checkParameterIsNotNull(str, "$this$toMediaType");
|
|
Matcher matcher = MediaType.a.matcher(str);
|
|
if (matcher.lookingAt()) {
|
|
String group = matcher.group(1);
|
|
m.checkExpressionValueIsNotNull(group, "typeSubtype.group(1)");
|
|
Locale locale = Locale.US;
|
|
m.checkExpressionValueIsNotNull(locale, "Locale.US");
|
|
if (group != null) {
|
|
String lowerCase = group.toLowerCase(locale);
|
|
m.checkExpressionValueIsNotNull(lowerCase, "(this as java.lang.String).toLowerCase(locale)");
|
|
String group2 = matcher.group(2);
|
|
m.checkExpressionValueIsNotNull(group2, "typeSubtype.group(2)");
|
|
m.checkExpressionValueIsNotNull(locale, "Locale.US");
|
|
if (group2 != null) {
|
|
String lowerCase2 = group2.toLowerCase(locale);
|
|
m.checkExpressionValueIsNotNull(lowerCase2, "(this as java.lang.String).toLowerCase(locale)");
|
|
ArrayList arrayList = new ArrayList();
|
|
Matcher matcher2 = MediaType.b.matcher(str);
|
|
int end = matcher.end();
|
|
while (end < str.length()) {
|
|
matcher2.region(end, str.length());
|
|
if (matcher2.lookingAt()) {
|
|
String group3 = matcher2.group(1);
|
|
if (group3 == null) {
|
|
end = matcher2.end();
|
|
} else {
|
|
String group4 = matcher2.group(2);
|
|
if (group4 == null) {
|
|
group4 = matcher2.group(3);
|
|
} else if (t.startsWith$default(group4, "'", false, 2, null) && t.endsWith$default(group4, "'", false, 2, null) && group4.length() > 2) {
|
|
group4 = group4.substring(1, group4.length() - 1);
|
|
m.checkExpressionValueIsNotNull(group4, "(this as java.lang.Strin…ing(startIndex, endIndex)");
|
|
}
|
|
arrayList.add(group3);
|
|
arrayList.add(group4);
|
|
end = matcher2.end();
|
|
}
|
|
} else {
|
|
StringBuilder L = c.d.b.a.a.L("Parameter is not formatted correctly: \"");
|
|
String substring = str.substring(end);
|
|
m.checkExpressionValueIsNotNull(substring, "(this as java.lang.String).substring(startIndex)");
|
|
L.append(substring);
|
|
L.append("\" for: \"");
|
|
L.append(str);
|
|
L.append('\"');
|
|
throw new IllegalArgumentException(L.toString().toString());
|
|
}
|
|
}
|
|
Object[] array = arrayList.toArray(new String[0]);
|
|
if (array != null) {
|
|
return new MediaType(str, lowerCase, lowerCase2, (String[]) array, null);
|
|
}
|
|
throw new TypeCastException("null cannot be cast to non-null type kotlin.Array<T>");
|
|
}
|
|
throw new TypeCastException("null cannot be cast to non-null type java.lang.String");
|
|
}
|
|
throw new TypeCastException("null cannot be cast to non-null type java.lang.String");
|
|
}
|
|
throw new IllegalArgumentException(("No subtype found for: \"" + str + '\"').toString());
|
|
}
|
|
|
|
public static final MediaType b(String str) {
|
|
m.checkParameterIsNotNull(str, "$this$toMediaTypeOrNull");
|
|
try {
|
|
return a(str);
|
|
} catch (IllegalArgumentException unused) {
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public MediaType(String str, String str2, String str3, String[] strArr, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this.d = str;
|
|
this.e = str2;
|
|
this.f = str3;
|
|
this.g = strArr;
|
|
}
|
|
|
|
public static final MediaType b(String str) {
|
|
return a.a(str);
|
|
}
|
|
|
|
/* JADX WARNING: Removed duplicated region for block: B:11:0x003d A[SYNTHETIC, Splitter:B:11:0x003d] */
|
|
/* JADX WARNING: Removed duplicated region for block: B:19:? A[RETURN, SYNTHETIC] */
|
|
public final Charset a(Charset charset) {
|
|
String str;
|
|
m.checkParameterIsNotNull("charset", "name");
|
|
IntProgression step = f.step(k.getIndices(this.g), 2);
|
|
int first = step.getFirst();
|
|
int last = step.getLast();
|
|
int step2 = step.getStep();
|
|
if (step2 < 0 ? first >= last : first <= last) {
|
|
while (true) {
|
|
if (!t.equals(this.g[first], "charset", true)) {
|
|
if (first == last) {
|
|
break;
|
|
}
|
|
first += step2;
|
|
} else {
|
|
str = this.g[first + 1];
|
|
break;
|
|
}
|
|
}
|
|
if (str != null) {
|
|
return charset;
|
|
}
|
|
try {
|
|
return Charset.forName(str);
|
|
} catch (IllegalArgumentException unused) {
|
|
return charset;
|
|
}
|
|
}
|
|
str = null;
|
|
if (str != null) {
|
|
}
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
return (obj instanceof MediaType) && m.areEqual(((MediaType) obj).d, this.d);
|
|
}
|
|
|
|
public int hashCode() {
|
|
return this.d.hashCode();
|
|
}
|
|
|
|
public String toString() {
|
|
return this.d;
|
|
}
|
|
}
|