package p447;

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 p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p251.C4303;
import p402.InterfaceC6540;
import p402.p411.p413.C6635;
import p402.p417.C6659;
import p402.p417.C6662;
import p402.p417.C6664;
import p402.p420.C6703;

/* JADX INFO: renamed from: ސ.ޖ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@InterfaceC6540
public final class C6914 {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final String f20035;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final String f20036;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final String[] f20037;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public static final C6915 f20034 = new C6915(null);

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public static final Pattern f20032 = Pattern.compile("([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)/([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)");

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public static final Pattern f20033 = Pattern.compile(";\\s*(?:([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)=(?:([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)|\"([^\"]*)\"))?");

    /* JADX INFO: renamed from: ސ.ޖ$֏, reason: contains not printable characters */
    public static final class C6915 {
        public C6915() {
        }

        public /* synthetic */ C6915(DefaultConstructorMarker defaultConstructorMarker) {
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final C6914 m10105(String str) {
            if (str == null) {
                C6635.m9824("$this$toMediaType");
                throw null;
            }
            Matcher matcher = C6914.f20032.matcher(str);
            if (!matcher.lookingAt()) {
                throw new IllegalArgumentException(("No subtype found for: \"" + str + '\"').toString());
            }
            String strGroup = matcher.group(1);
            C6635.m9823((Object) strGroup, "typeSubtype.group(1)");
            Locale locale = Locale.US;
            C6635.m9823((Object) locale, "Locale.US");
            String lowerCase = strGroup.toLowerCase(locale);
            C6635.m9823((Object) lowerCase, "(this as java.lang.String).toLowerCase(locale)");
            String strGroup2 = matcher.group(2);
            C6635.m9823((Object) strGroup2, "typeSubtype.group(2)");
            Locale locale2 = Locale.US;
            C6635.m9823((Object) locale2, "Locale.US");
            String lowerCase2 = strGroup2.toLowerCase(locale2);
            C6635.m9823((Object) lowerCase2, "(this as java.lang.String).toLowerCase(locale)");
            ArrayList arrayList = new ArrayList();
            Matcher matcher2 = C6914.f20033.matcher(str);
            int iEnd = matcher.end();
            while (iEnd < str.length()) {
                matcher2.region(iEnd, str.length());
                if (!matcher2.lookingAt()) {
                    StringBuilder sbM4889 = C2803.m4889("Parameter is not formatted correctly: \"");
                    String strSubstring = str.substring(iEnd);
                    C6635.m9823((Object) strSubstring, "(this as java.lang.String).substring(startIndex)");
                    sbM4889.append(strSubstring);
                    sbM4889.append("\" for: \"");
                    sbM4889.append(str);
                    sbM4889.append('\"');
                    throw new IllegalArgumentException(sbM4889.toString().toString());
                }
                String strGroup3 = matcher2.group(1);
                if (strGroup3 == null) {
                    iEnd = matcher2.end();
                } else {
                    String strGroup4 = matcher2.group(2);
                    if (strGroup4 == null) {
                        strGroup4 = matcher2.group(3);
                    } else if (C6703.m9899(strGroup4, "'", false, 2) && C6703.m9885(strGroup4, "'", false, 2) && strGroup4.length() > 2) {
                        strGroup4 = strGroup4.substring(1, strGroup4.length() - 1);
                        C6635.m9823((Object) strGroup4, "(this as java.lang.Strin…ing(startIndex, endIndex)");
                    }
                    arrayList.add(strGroup3);
                    arrayList.add(strGroup4);
                    iEnd = matcher2.end();
                }
            }
            Object[] array = arrayList.toArray(new String[0]);
            if (array != null) {
                return new C6914(str, lowerCase, lowerCase2, (String[]) array, null);
            }
            throw new TypeCastException("null cannot be cast to non-null type kotlin.Array<T>");
        }

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final C6914 m10106(String str) {
            if (str != null) {
                try {
                    return m10105(str);
                } catch (IllegalArgumentException unused) {
                    return null;
                }
            }
            C6635.m9824("$this$toMediaTypeOrNull");
            throw null;
        }
    }

    public /* synthetic */ C6914(String str, String str2, String str3, String[] strArr, DefaultConstructorMarker defaultConstructorMarker) {
        this.f20035 = str;
        this.f20036 = str2;
        this.f20037 = strArr;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static final C6914 m10103(String str) {
        return f20034.m10105(str);
    }

    public boolean equals(Object obj) {
        return (obj instanceof C6914) && C6635.m9825((Object) ((C6914) obj).f20035, (Object) this.f20035);
    }

    public int hashCode() {
        return this.f20035.hashCode();
    }

    public String toString() {
        return this.f20035;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final Charset m10104(Charset charset) {
        String[] strArr = this.f20037;
        String str = null;
        if (strArr == null) {
            C6635.m9824("$this$indices");
            throw null;
        }
        C6659 c6659M9845 = C6664.m9845(new C6662(0, C4303.m6995((Object[]) strArr)), 2);
        int i = c6659M9845.f19412;
        int i2 = c6659M9845.f19413;
        int i3 = c6659M9845.f19414;
        if (i3 < 0 ? i >= i2 : i <= i2) {
            while (true) {
                if (!C6703.m9905(this.f20037[i], "charset", true)) {
                    if (i == i2) {
                        break;
                    }
                    i += i3;
                } else {
                    str = this.f20037[i + 1];
                    break;
                }
            }
        }
        if (str == null) {
            return charset;
        }
        try {
            return Charset.forName(str);
        } catch (IllegalArgumentException unused) {
            return charset;
        }
    }
}
