package 㿎;

import com.facebook.appevents.codeless.CodelessMatcher;
import com.google.android.material.badge.BadgeDrawable;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import ඓ.K.K.K.C1293;
import ᨨ.C1492;
import 㿎.ሽ.C2540;

/* renamed from: 㿎.Ԛ  reason: contains not printable characters */
/* compiled from: HttpUrl */
public final class C2531 {

    /* renamed from: 㳳  reason: contains not printable characters */
    public static final char[] f8534 = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

    /* renamed from: ʬ  reason: contains not printable characters */
    public final String f8535;

    /* renamed from: ඓ  reason: contains not printable characters */
    public final int f8536;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public final String f8537;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final String f8538;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public final List<String> f8539;

    /* renamed from: K  reason: contains not printable characters */
    public final String f8540;

    /* renamed from: 㴹  reason: contains not printable characters */
    public final List<String> f8541;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final String f8542;

    /* renamed from: 㿎  reason: contains not printable characters */
    public final String f8543;

    public C2531(C2532 k) {
        this.f8540 = k.f8548;
        this.f8538 = m6589(k.f8546, false);
        this.f8535 = m6589(k.f8544, false);
        this.f8542 = k.f8550;
        int i = k.f8545;
        this.f8536 = i == -1 ? m6584(k.f8548) : i;
        this.f8541 = m6597(k.f8549, false);
        List<String> list = k.f8547;
        String str = null;
        this.f8539 = list != null ? m6597(list, true) : null;
        String str2 = k.f8551;
        this.f8543 = str2 != null ? m6586(str2, 0, str2.length(), false) : str;
        this.f8537 = k.toString();
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public static int m6584(String str) {
        if (str.equals("http")) {
            return 80;
        }
        return str.equals("https") ? 443 : -1;
    }

    public boolean equals(Object obj) {
        return (obj instanceof C2531) && ((C2531) obj).f8537.equals(this.f8537);
    }

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

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

    /* renamed from: ʬ  reason: contains not printable characters */
    public List<String> m6593() {
        int indexOf = this.f8537.indexOf(47, this.f8540.length() + 3);
        String str = this.f8537;
        int r1 = C2540.m6637(str, indexOf, str.length(), "?#");
        ArrayList arrayList = new ArrayList();
        while (indexOf < r1) {
            int i = indexOf + 1;
            int r4 = C2540.m6636(this.f8537, i, r1, '/');
            arrayList.add(this.f8537.substring(i, r4));
            indexOf = r4;
        }
        return arrayList;
    }

    /* renamed from: ඓ  reason: contains not printable characters */
    public String m6594() {
        if (this.f8538.isEmpty()) {
            return "";
        }
        int length = this.f8540.length() + 3;
        String str = this.f8537;
        return this.f8537.substring(length, C2540.m6637(str, length, str.length(), ":@"));
    }

    /* renamed from: K  reason: contains not printable characters */
    public String m6596() {
        if (this.f8535.isEmpty()) {
            return "";
        }
        int indexOf = this.f8537.indexOf(64);
        return this.f8537.substring(this.f8537.indexOf(58, this.f8540.length() + 3) + 1, indexOf);
    }

    /* renamed from: 㴹  reason: contains not printable characters */
    public URI m6599() {
        String str;
        C2532 k = new C2532();
        k.f8548 = this.f8540;
        k.f8546 = m6594();
        k.f8544 = m6596();
        k.f8550 = this.f8542;
        k.f8545 = this.f8536 != m6584(this.f8540) ? this.f8536 : -1;
        k.f8549.clear();
        k.f8549.addAll(m6593());
        k.m6604(m6600());
        if (this.f8543 == null) {
            str = null;
        } else {
            str = this.f8537.substring(this.f8537.indexOf(35) + 1);
        }
        k.f8551 = str;
        int size = k.f8549.size();
        for (int i = 0; i < size; i++) {
            k.f8549.set(i, m6587(k.f8549.get(i), "[]", true, true, false, true));
        }
        List<String> list = k.f8547;
        if (list != null) {
            int size2 = list.size();
            for (int i2 = 0; i2 < size2; i2++) {
                String str2 = k.f8547.get(i2);
                if (str2 != null) {
                    k.f8547.set(i2, m6587(str2, "\\^`{|}", true, true, true, true));
                }
            }
        }
        String str3 = k.f8551;
        if (str3 != null) {
            k.f8551 = m6587(str3, " \"#<>\\^`{|}", true, true, false, false);
        }
        String k2 = k.toString();
        try {
            return new URI(k2);
        } catch (URISyntaxException e) {
            try {
                return URI.create(k2.replaceAll("[\\u0000-\\u001F\\u007F-\\u009F\\p{javaWhitespace}]", ""));
            } catch (Exception unused) {
                throw new RuntimeException(e);
            }
        }
    }

    /* renamed from: 㸾  reason: contains not printable characters */
    public String m6600() {
        if (this.f8539 == null) {
            return null;
        }
        int indexOf = this.f8537.indexOf(63) + 1;
        String str = this.f8537;
        return this.f8537.substring(indexOf, C2540.m6636(str, indexOf, str.length(), '#'));
    }

    /* renamed from: 㿎.Ԛ$K  reason: contains not printable characters */
    /* compiled from: HttpUrl */
    public static final class C2532 {

        /* renamed from: ʬ  reason: contains not printable characters */
        public String f8544 = "";

        /* renamed from: ඓ  reason: contains not printable characters */
        public int f8545 = -1;

        /* renamed from: ῲ  reason: contains not printable characters */
        public String f8546 = "";

        /* renamed from: ⁱ  reason: contains not printable characters */
        public List<String> f8547;

        /* renamed from: K  reason: contains not printable characters */
        public String f8548;

        /* renamed from: 㴹  reason: contains not printable characters */
        public final List<String> f8549 = new ArrayList();

        /* renamed from: 㸾  reason: contains not printable characters */
        public String f8550;

        /* renamed from: 㿎  reason: contains not printable characters */
        public String f8551;

        public C2532() {
            this.f8549.add("");
        }

        public String toString() {
            StringBuilder sb = new StringBuilder();
            sb.append(this.f8548);
            sb.append("://");
            if (!this.f8546.isEmpty() || !this.f8544.isEmpty()) {
                sb.append(this.f8546);
                if (!this.f8544.isEmpty()) {
                    sb.append(':');
                    sb.append(this.f8544);
                }
                sb.append('@');
            }
            if (this.f8550.indexOf(58) != -1) {
                sb.append('[');
                sb.append(this.f8550);
                sb.append(']');
            } else {
                sb.append(this.f8550);
            }
            int i = this.f8545;
            if (i == -1) {
                i = C2531.m6584(this.f8548);
            }
            if (i != C2531.m6584(this.f8548)) {
                sb.append(':');
                sb.append(i);
            }
            List<String> list = this.f8549;
            int size = list.size();
            for (int i2 = 0; i2 < size; i2++) {
                sb.append('/');
                sb.append(list.get(i2));
            }
            if (this.f8547 != null) {
                sb.append('?');
                C2531.m6590(sb, this.f8547);
            }
            if (this.f8551 != null) {
                sb.append('#');
                sb.append(this.f8551);
            }
            return sb.toString();
        }

        /* renamed from: ῲ  reason: contains not printable characters */
        public C2532 m6602(String str) {
            if (str != null) {
                this.f8546 = C2531.m6587(str, " \"':;<=>@[]^`{}|/\\?#", false, false, false, true);
                return this;
            }
            throw new NullPointerException("username == null");
        }

        /* renamed from: K  reason: contains not printable characters */
        public C2532 m6604(String str) {
            this.f8547 = str != null ? C2531.m6583(C2531.m6587(str, " \"'<>#", true, false, true, true)) : null;
            return this;
        }

        /* renamed from: ῲ  reason: contains not printable characters */
        public C2532 m6603(String str, String str2) {
            if (str != null) {
                if (this.f8547 == null) {
                    this.f8547 = new ArrayList();
                }
                this.f8547.add(C2531.m6587(str, " !\"#$&'(),/:;<=>?@[]\\^`{|}~", false, false, true, true));
                this.f8547.add(str2 != null ? C2531.m6587(str2, " !\"#$&'(),/:;<=>?@[]\\^`{|}~", false, false, true, true) : null);
                return this;
            }
            throw new NullPointerException("name == null");
        }

        /* renamed from: K  reason: contains not printable characters */
        public C2532 m6605(String str, String str2) {
            if (str != null) {
                if (this.f8547 == null) {
                    this.f8547 = new ArrayList();
                }
                this.f8547.add(C2531.m6587(str, " \"'<>#&=", true, false, true, true));
                this.f8547.add(str2 != null ? C2531.m6587(str2, " \"'<>#&=", true, false, true, true) : null);
                return this;
            }
            throw new NullPointerException("encodedName == null");
        }

        /* renamed from: K  reason: contains not printable characters */
        public C2531 m6607() {
            if (this.f8548 == null) {
                throw new IllegalStateException("scheme == null");
            } else if (this.f8550 != null) {
                return new C2531(this);
            } else {
                throw new IllegalStateException("host == null");
            }
        }

        /* JADX WARNING: Code restructure failed: missing block: B:104:0x020b, code lost:
            if (r1 <= 65535) goto L_0x0213;
         */
        /* JADX WARNING: Removed duplicated region for block: B:111:0x0235  */
        /* JADX WARNING: Removed duplicated region for block: B:116:0x0255  */
        /* JADX WARNING: Removed duplicated region for block: B:117:0x025b  */
        /* JADX WARNING: Removed duplicated region for block: B:125:0x0296  */
        /* JADX WARNING: Removed duplicated region for block: B:173:0x03a1  */
        /* JADX WARNING: Removed duplicated region for block: B:197:0x01df A[SYNTHETIC] */
        /* JADX WARNING: Removed duplicated region for block: B:202:0x0356 A[SYNTHETIC] */
        /* JADX WARNING: Removed duplicated region for block: B:30:0x0066  */
        /* JADX WARNING: Removed duplicated region for block: B:38:0x00ac  */
        /* JADX WARNING: Removed duplicated region for block: B:61:0x0120  */
        /* JADX WARNING: Removed duplicated region for block: B:62:0x0125  */
        /* JADX WARNING: Removed duplicated region for block: B:84:0x01c1  */
        /* JADX WARNING: Removed duplicated region for block: B:99:0x01e6  */
        /* renamed from: K  reason: contains not printable characters */
        public C2532 m6606(C2531 r24, String str) {
            int i;
            int i2;
            int i3;
            char c;
            char c2;
            char c3;
            char c4;
            int i4;
            int i5;
            int r1;
            String str2;
            C2532 k;
            int i6;
            String str3;
            char c5;
            int i7;
            String str4;
            C2532 k2;
            int i8;
            String str5;
            int i9;
            int i10;
            C2532 k3;
            int i11;
            int i12;
            int r9;
            char charAt;
            int i13;
            int i14;
            int i15;
            char c6;
            int i16;
            int i17;
            int i18;
            char charAt2;
            int r92 = C2540.m6632(str, 0, str.length());
            int r11 = C2540.m6629(str, r92, str.length());
            char c7 = ':';
            char c8 = 65535;
            if (r11 - r92 >= 2) {
                char charAt3 = str.charAt(r92);
                char c9 = 'Z';
                if ((charAt3 >= 'a' && charAt3 <= 'z') || (charAt3 >= 'A' && charAt3 <= 'Z')) {
                    int i19 = r92;
                    while (true) {
                        i19++;
                        if (i19 >= r11) {
                            break;
                        }
                        char charAt4 = str.charAt(i19);
                        if ((charAt4 >= 'a' && charAt4 <= 'z') || ((charAt4 >= 'A' && charAt4 <= c9) || ((charAt4 >= '0' && charAt4 <= '9') || charAt4 == '+' || charAt4 == '-' || charAt4 == '.'))) {
                            c9 = 'Z';
                        } else if (charAt4 == ':') {
                            i = i19;
                        }
                    }
                    if (i == -1) {
                        if (str.regionMatches(true, r92, "https:", 0, 6)) {
                            this.f8548 = "https";
                            r92 += 6;
                        } else if (str.regionMatches(true, r92, "http:", 0, 5)) {
                            this.f8548 = "http";
                            r92 += 5;
                        } else {
                            StringBuilder r2 = C1293.m3416("Expected URL scheme 'http' or 'https' but was '");
                            r2.append(str.substring(0, i));
                            r2.append("'");
                            throw new IllegalArgumentException(r2.toString());
                        }
                    } else if (r24 != null) {
                        this.f8548 = r24.f8540;
                    } else {
                        throw new IllegalArgumentException("Expected URL scheme 'http' or 'https' but no colon was found");
                    }
                    i2 = r92;
                    i3 = 0;
                    while (true) {
                        c = '/';
                        c2 = '\\';
                        if (i2 >= r11 || !((charAt2 = str.charAt(i2)) == '\\' || charAt2 == '/')) {
                            c3 = '?';
                            c4 = '#';
                        } else {
                            i3++;
                            i2++;
                        }
                    }
                    c3 = '?';
                    c4 = '#';
                    if (i3 < 2 || r24 == null || !r24.f8540.equals(this.f8548)) {
                        i12 = r92 + i3;
                        boolean z = false;
                        boolean z2 = false;
                        while (true) {
                            r9 = C2540.m6637(str, i12, r11, "@/\\?#");
                            charAt = r9 == r11 ? str.charAt(r9) : 65535;
                            if (charAt == c8 || charAt == c4 || charAt == c || charAt == c2 || charAt == c3) {
                                i5 = r9;
                                i13 = i12;
                            } else {
                                if (charAt == '@') {
                                    if (!z) {
                                        int r8 = C2540.m6636(str, i12, r9, c7);
                                        i18 = r9;
                                        String r12 = C2531.m6585(str, i12, r8, " \"':;<=>@[]^`{}|/\\?#", true, false, false, true, null);
                                        if (z2) {
                                            r12 = this.f8546 + "%40" + r12;
                                        }
                                        this.f8546 = r12;
                                        if (r8 != i18) {
                                            this.f8544 = C2531.m6585(str, r8 + 1, i18, " \"':;<=>@[]^`{}|/\\?#", true, false, false, true, null);
                                            z = true;
                                        }
                                        z2 = true;
                                    } else {
                                        i18 = r9;
                                        this.f8544 += "%40" + C2531.m6585(str, i12, i18, " \"':;<=>@[]^`{}|/\\?#", true, false, false, true, null);
                                    }
                                    i12 = i18 + 1;
                                }
                                c4 = '#';
                                c3 = '?';
                                c2 = '\\';
                                c8 = 65535;
                                c = '/';
                                c7 = ':';
                            }
                        }
                        i5 = r9;
                        i13 = i12;
                        while (true) {
                            if (i13 < i5) {
                                char charAt5 = str.charAt(i13);
                                if (charAt5 == ':') {
                                    i14 = i13;
                                    break;
                                }
                                if (charAt5 == '[') {
                                    i17 = 1;
                                    do {
                                        i13++;
                                        if (i13 >= i5) {
                                            break;
                                        }
                                    } while (str.charAt(i13) != ']');
                                } else {
                                    i17 = 1;
                                }
                                i13 += i17;
                            } else {
                                i14 = i5;
                                break;
                            }
                        }
                        i15 = i14 + 1;
                        if (i15 >= i5) {
                            this.f8550 = m6601(str, i12, i14);
                            i4 = r11;
                            c6 = '\"';
                            try {
                                i16 = Integer.parseInt(C2531.m6585(str, i15, i5, "", false, false, false, true, null));
                                if (i16 > 0) {
                                }
                            } catch (NumberFormatException unused) {
                            }
                            i16 = -1;
                            this.f8545 = i16;
                            if (this.f8545 == -1) {
                                StringBuilder r22 = C1293.m3416("Invalid URL port: \"");
                                r22.append(str.substring(i15, i5));
                                r22.append('\"');
                                throw new IllegalArgumentException(r22.toString());
                            }
                        } else {
                            i4 = r11;
                            c6 = '\"';
                            this.f8550 = m6601(str, i12, i14);
                            this.f8545 = C2531.m6584(this.f8548);
                        }
                        if (this.f8550 == null) {
                            StringBuilder r23 = C1293.m3416("Invalid URL host: \"");
                            r23.append(str.substring(i12, i14));
                            r23.append(c6);
                            throw new IllegalArgumentException(r23.toString());
                        }
                    } else {
                        this.f8546 = r24.m6594();
                        this.f8544 = r24.m6596();
                        this.f8550 = r24.f8542;
                        this.f8545 = r24.f8536;
                        this.f8549.clear();
                        this.f8549.addAll(r24.m6593());
                        if (r92 == r11 || str.charAt(r92) == '#') {
                            m6604(r24.m6600());
                        }
                        i5 = r92;
                        i4 = r11;
                    }
                    r1 = C2540.m6637(str, i5, i4, "?#");
                    if (i5 != r1) {
                        k = this;
                        i6 = i4;
                        str3 = str;
                        str2 = str3;
                    } else {
                        char charAt6 = str.charAt(i5);
                        if (charAt6 != '/' && charAt6 != '\\') {
                            List<String> list = this.f8549;
                            list.set(list.size() - 1, "");
                            k2 = this;
                            i8 = i4;
                            str4 = "";
                            str5 = str;
                            str2 = str5;
                            i7 = i5;
                            i10 = r1;
                            i9 = i10;
                            k3 = k2;
                            while (true) {
                                if (i7 < i9) {
                                    int r3 = C2540.m6637(str5, i7, i9, "/\\");
                                    boolean z3 = r3 < i9;
                                    String r122 = C2531.m6585(str5, i7, r3, " \"<>^`{}|/\\?#", true, false, false, true, null);
                                    if (!(r122.equals(CodelessMatcher.CURRENT_CLASS_NAME) || r122.equalsIgnoreCase("%2e"))) {
                                        if (r122.equals("..") || r122.equalsIgnoreCase("%2e.") || r122.equalsIgnoreCase(".%2e") || r122.equalsIgnoreCase("%2e%2e")) {
                                            List<String> list2 = k2.f8549;
                                            if (!list2.remove(list2.size() - 1).isEmpty() || k2.f8549.isEmpty()) {
                                                k2.f8549.add(str4);
                                            } else {
                                                List<String> list3 = k2.f8549;
                                                list3.set(list3.size() - 1, str4);
                                            }
                                        } else {
                                            List<String> list4 = k2.f8549;
                                            if (list4.get(list4.size() - 1).isEmpty()) {
                                                List<String> list5 = k2.f8549;
                                                list5.set(list5.size() - 1, r122);
                                            } else {
                                                k2.f8549.add(r122);
                                            }
                                            if (z3) {
                                                k2.f8549.add(str4);
                                            }
                                        }
                                    }
                                    if (z3) {
                                        i5 = r3;
                                        i11 = 1;
                                        break;
                                    }
                                    i7 = r3;
                                }
                                k = k3;
                                r1 = i10;
                                i6 = i8;
                                str3 = str;
                                break;
                            }
                        } else {
                            i11 = 1;
                            this.f8549.clear();
                            this.f8549.add("");
                            k2 = this;
                            i8 = i4;
                            str4 = "";
                            str5 = str;
                            str2 = str5;
                            i10 = r1;
                            i9 = i10;
                            k3 = k2;
                        }
                        i7 = i5 + i11;
                        while (true) {
                            if (i7 < i9) {
                            }
                            k = k3;
                            r1 = i10;
                            i6 = i8;
                            str3 = str;
                            i7 = r3;
                        }
                    }
                    if (r1 < i6 || str2.charAt(r1) != '?') {
                        c5 = '#';
                    } else {
                        c5 = '#';
                        int r16 = C2540.m6636(str2, r1, i6, '#');
                        k.f8547 = C2531.m6583(C2531.m6585(str3, r1 + 1, r16, " \"'<>#", true, false, true, true, null));
                        r1 = r16;
                    }
                    if (r1 < i6 || str2.charAt(r1) != c5) {
                        return k;
                    }
                    k.f8551 = C2531.m6585(str3, r1 + 1, i6, "", true, false, false, false, null);
                    return k;
                }
            }
            i = -1;
            if (i == -1) {
            }
            i2 = r92;
            i3 = 0;
            while (true) {
                c = '/';
                c2 = '\\';
                if (i2 >= r11) {
                    break;
                }
                break;
                i3++;
                i2++;
            }
            c3 = '?';
            c4 = '#';
            if (i3 < 2) {
            }
            i12 = r92 + i3;
            boolean z4 = false;
            boolean z22 = false;
            while (true) {
                r9 = C2540.m6637(str, i12, r11, "@/\\?#");
                if (r9 == r11) {
                }
                if (charAt == c8) {
                    break;
                }
                break;
                c4 = '#';
                c3 = '?';
                c2 = '\\';
                c8 = 65535;
                c = '/';
                c7 = ':';
            }
            i5 = r9;
            i13 = i12;
            while (true) {
                if (i13 < i5) {
                }
                i13 += i17;
            }
            i15 = i14 + 1;
            if (i15 >= i5) {
            }
            if (this.f8550 == null) {
            }
            r1 = C2540.m6637(str, i5, i4, "?#");
            if (i5 != r1) {
            }
            if (r1 < i6) {
            }
            c5 = '#';
            if (r1 < i6) {
            }
            return k;
        }

        /* renamed from: K  reason: contains not printable characters */
        public static String m6601(String str, int i, int i2) {
            return C2540.m6641(C2531.m6586(str, i, i2, false));
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public String m6595() {
        int indexOf = this.f8537.indexOf(47, this.f8540.length() + 3);
        String str = this.f8537;
        return this.f8537.substring(indexOf, C2540.m6637(str, indexOf, str.length(), "?#"));
    }

    /* renamed from: ඓ  reason: contains not printable characters */
    public static List<String> m6583(String str) {
        ArrayList arrayList = new ArrayList();
        int i = 0;
        while (i <= str.length()) {
            int indexOf = str.indexOf(38, i);
            if (indexOf == -1) {
                indexOf = str.length();
            }
            int indexOf2 = str.indexOf(61, i);
            if (indexOf2 == -1 || indexOf2 > indexOf) {
                arrayList.add(str.substring(i, indexOf));
                arrayList.add(null);
            } else {
                arrayList.add(str.substring(i, indexOf2));
                arrayList.add(str.substring(indexOf2 + 1, indexOf));
            }
            i = indexOf + 1;
        }
        return arrayList;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static void m6590(StringBuilder sb, List<String> list) {
        int size = list.size();
        for (int i = 0; i < size; i += 2) {
            String str = list.get(i);
            String str2 = list.get(i + 1);
            if (i > 0) {
                sb.append('&');
            }
            sb.append(str);
            if (str2 != null) {
                sb.append('=');
                sb.append(str2);
            }
        }
    }

    /* renamed from: 㸾  reason: contains not printable characters */
    public static C2531 m6592(String str) {
        try {
            return m6582(str);
        } catch (IllegalArgumentException unused) {
            return null;
        }
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public static C2531 m6582(String str) {
        C2532 k = new C2532();
        k.m6606((C2531) null, str);
        return k.m6607();
    }

    /* renamed from: K  reason: contains not printable characters */
    public C2532 m6598(String str) {
        try {
            C2532 k = new C2532();
            k.m6606(this, str);
            return k;
        } catch (IllegalArgumentException unused) {
            return null;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static String m6589(String str, boolean z) {
        return m6586(str, 0, str.length(), z);
    }

    /* renamed from: K  reason: contains not printable characters */
    public final List<String> m6597(List<String> list, boolean z) {
        int size = list.size();
        ArrayList arrayList = new ArrayList(size);
        for (int i = 0; i < size; i++) {
            String str = list.get(i);
            arrayList.add(str != null ? m6586(str, 0, str.length(), z) : null);
        }
        return Collections.unmodifiableList(arrayList);
    }

    /* renamed from: K  reason: contains not printable characters */
    public static String m6586(String str, int i, int i2, boolean z) {
        int i3;
        int i4 = i;
        while (i4 < i2) {
            char charAt = str.charAt(i4);
            if (charAt == '%' || (charAt == '+' && z)) {
                C1492 r1 = new C1492();
                r1.m3793(str, i, i4);
                while (i4 < i2) {
                    int codePointAt = str.codePointAt(i4);
                    if (codePointAt == 37 && (i3 = i4 + 2) < i2) {
                        int r5 = C2540.m6635(str.charAt(i4 + 1));
                        int r6 = C2540.m6635(str.charAt(i3));
                        if (!(r5 == -1 || r6 == -1)) {
                            r1.writeByte((r5 << 4) + r6);
                            i4 = i3;
                            i4 += Character.charCount(codePointAt);
                        }
                    } else if (codePointAt == 43 && z) {
                        r1.writeByte(32);
                        i4 += Character.charCount(codePointAt);
                    }
                    r1.m3775(codePointAt);
                    i4 += Character.charCount(codePointAt);
                }
                return r1.m3800();
            }
            i4++;
        }
        return str.substring(i, i2);
    }

    /* renamed from: K  reason: contains not printable characters */
    public static boolean m6591(String str, int i, int i2) {
        int i3 = i + 2;
        if (i3 >= i2 || str.charAt(i) != '%' || C2540.m6635(str.charAt(i + 1)) == -1 || C2540.m6635(str.charAt(i3)) == -1) {
            return false;
        }
        return true;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static String m6585(String str, int i, int i2, String str2, boolean z, boolean z2, boolean z3, boolean z4, Charset charset) {
        int i3 = i;
        while (i3 < i2) {
            int codePointAt = str.codePointAt(i3);
            if (codePointAt < 32 || codePointAt == 127 || ((codePointAt >= 128 && z4) || str2.indexOf(codePointAt) != -1 || ((codePointAt == 37 && (!z || (z2 && !m6591(str, i3, i2)))) || (codePointAt == 43 && z3)))) {
                C1492 r5 = new C1492();
                r5.m3793(str, i, i3);
                C1492 r12 = null;
                while (i3 < i2) {
                    int codePointAt2 = str.codePointAt(i3);
                    if (!z || !(codePointAt2 == 9 || codePointAt2 == 10 || codePointAt2 == 12 || codePointAt2 == 13)) {
                        if (codePointAt2 == 43 && z3) {
                            r5.m3792(z ? BadgeDrawable.DEFAULT_EXCEED_MAX_BADGE_NUMBER_SUFFIX : "%2B");
                        } else if (codePointAt2 < 32 || codePointAt2 == 127 || ((codePointAt2 >= 128 && z4) || str2.indexOf(codePointAt2) != -1 || (codePointAt2 == 37 && (!z || (z2 && !m6591(str, i3, i2)))))) {
                            if (r12 == null) {
                                r12 = new C1492();
                            }
                            if (charset == null || charset.equals(C2540.f8566)) {
                                r12.m3775(codePointAt2);
                            } else {
                                r12.m3794(str, i3, Character.charCount(codePointAt2) + i3, charset);
                            }
                            while (!r12.m3802()) {
                                int readByte = r12.readByte() & 255;
                                r5.writeByte(37);
                                r5.writeByte((int) f8534[(readByte >> 4) & 15]);
                                r5.writeByte((int) f8534[readByte & 15]);
                            }
                        } else {
                            r5.m3775(codePointAt2);
                        }
                    }
                    i3 += Character.charCount(codePointAt2);
                }
                return r5.m3800();
            }
            i3 += Character.charCount(codePointAt);
        }
        return str.substring(i, i2);
    }

    /* renamed from: K  reason: contains not printable characters */
    public static String m6588(String str, String str2, boolean z, boolean z2, boolean z3, boolean z4, Charset charset) {
        return m6585(str, 0, str.length(), str2, z, z2, z3, z4, charset);
    }

    /* renamed from: K  reason: contains not printable characters */
    public static String m6587(String str, String str2, boolean z, boolean z2, boolean z3, boolean z4) {
        return m6585(str, 0, str.length(), str2, z, z2, z3, z4, null);
    }
}
