package k7;

import d5.AbstractC0844a;
import java.io.EOFException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import x7.C1731g;

/* JADX INFO: loaded from: classes.dex */
public final class l implements InterfaceC1110b {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public static final l f14102q = new l();

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public static final l f14103r = new l();

    public static final h a(l lVar, String str) {
        h hVar = new h(str);
        h.f14063d.put(str, hVar);
        return hVar;
    }

    public static String b(String str, int i, int i5, String str2, int i8) throws EOFException {
        int i9 = (i8 & 1) != 0 ? 0 : i;
        int length = (i8 & 2) != 0 ? str.length() : i5;
        boolean z8 = (i8 & 8) == 0;
        boolean z9 = (i8 & 16) == 0;
        boolean z10 = (i8 & 32) == 0;
        boolean z11 = (i8 & 64) == 0;
        P6.g.e(str, "<this>");
        int iCharCount = i9;
        while (iCharCount < length) {
            int iCodePointAt = str.codePointAt(iCharCount);
            int i10 = 32;
            int i11 = 128;
            if (iCodePointAt < 32 || iCodePointAt == 127 || ((iCodePointAt >= 128 && !z11) || X6.e.N(str2, (char) iCodePointAt) || ((iCodePointAt == 37 && (!z8 || (z9 && !e(iCharCount, length, str)))) || (iCodePointAt == 43 && z10)))) {
                C1731g c1731g = new C1731g();
                c1731g.y0(i9, iCharCount, str);
                C1731g c1731g2 = null;
                while (iCharCount < length) {
                    int iCodePointAt2 = str.codePointAt(iCharCount);
                    if (!z8 || (iCodePointAt2 != 9 && iCodePointAt2 != 10 && iCodePointAt2 != 12 && iCodePointAt2 != 13)) {
                        if (iCodePointAt2 == 43 && z10) {
                            c1731g.z0(z8 ? "+" : "%2B");
                        } else if (iCodePointAt2 < i10 || iCodePointAt2 == 127 || ((iCodePointAt2 >= i11 && !z11) || X6.e.N(str2, (char) iCodePointAt2) || (iCodePointAt2 == 37 && (!z8 || (z9 && !e(iCharCount, length, str)))))) {
                            if (c1731g2 == null) {
                                c1731g2 = new C1731g();
                            }
                            c1731g2.A0(iCodePointAt2);
                            while (!c1731g2.u()) {
                                byte bQ = c1731g2.Q();
                                c1731g.u0(37);
                                char[] cArr = q.f14120k;
                                c1731g.u0(cArr[((bQ & 255) >> 4) & 15]);
                                c1731g.u0(cArr[bQ & 15]);
                            }
                        } else {
                            c1731g.A0(iCodePointAt2);
                        }
                    }
                    iCharCount += Character.charCount(iCodePointAt2);
                    i10 = 32;
                    i11 = 128;
                }
                return c1731g.o0();
            }
            iCharCount += Character.charCount(iCodePointAt);
        }
        String strSubstring = str.substring(i9, length);
        P6.g.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public static D c(String str) {
        Charset charset = X6.a.f7235a;
        C1731g c1731g = new C1731g();
        P6.g.e(charset, "charset");
        int length = str.length();
        P6.g.e(str, "string");
        if (length < 0) {
            throw new IllegalArgumentException(I1.a.o("endIndex < beginIndex: ", length, 0, " < ").toString());
        }
        if (length > str.length()) {
            StringBuilder sbO = AbstractC0844a.o(length, "endIndex > string.length: ", " > ");
            sbO.append(str.length());
            throw new IllegalArgumentException(sbO.toString().toString());
        }
        if (charset.equals(X6.a.f7235a)) {
            c1731g.y0(0, length, str);
        } else {
            String strSubstring = str.substring(0, length);
            P6.g.d(strSubstring, "substring(...)");
            byte[] bytes = strSubstring.getBytes(charset);
            P6.g.d(bytes, "getBytes(...)");
            c1731g.s0(bytes, 0, bytes.length);
        }
        return new D(null, c1731g.f18765r, c1731g, 0);
    }

    public static boolean e(int i, int i5, String str) {
        int i8 = i + 2;
        return i8 < i5 && str.charAt(i) == '%' && l7.b.r(str.charAt(i + 1)) != -1 && l7.b.r(str.charAt(i8)) != -1;
    }

    public static String f(String str, int i, int i5, int i8) {
        int i9;
        if ((i8 & 1) != 0) {
            i = 0;
        }
        if ((i8 & 2) != 0) {
            i5 = str.length();
        }
        boolean z8 = (i8 & 4) == 0;
        P6.g.e(str, "<this>");
        int iCharCount = i;
        while (iCharCount < i5) {
            char cCharAt = str.charAt(iCharCount);
            if (cCharAt == '%' || (cCharAt == '+' && z8)) {
                C1731g c1731g = new C1731g();
                c1731g.y0(i, iCharCount, str);
                while (iCharCount < i5) {
                    int iCodePointAt = str.codePointAt(iCharCount);
                    if (iCodePointAt == 37 && (i9 = iCharCount + 2) < i5) {
                        int iR = l7.b.r(str.charAt(iCharCount + 1));
                        int iR2 = l7.b.r(str.charAt(i9));
                        if (iR == -1 || iR2 == -1) {
                            c1731g.A0(iCodePointAt);
                            iCharCount += Character.charCount(iCodePointAt);
                        } else {
                            c1731g.u0((iR << 4) + iR2);
                            iCharCount = Character.charCount(iCodePointAt) + i9;
                        }
                    } else if (iCodePointAt == 43 && z8) {
                        c1731g.u0(32);
                        iCharCount++;
                    } else {
                        c1731g.A0(iCodePointAt);
                        iCharCount += Character.charCount(iCodePointAt);
                    }
                }
                return c1731g.o0();
            }
            iCharCount++;
        }
        String strSubstring = str.substring(i, i5);
        P6.g.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        return strSubstring;
    }

    public static ArrayList g(String str) {
        ArrayList arrayList = new ArrayList();
        int i = 0;
        while (i <= str.length()) {
            int iS = X6.e.S(str, '&', i, 4);
            if (iS == -1) {
                iS = str.length();
            }
            int iS2 = X6.e.S(str, '=', i, 4);
            if (iS2 == -1 || iS2 > iS) {
                String strSubstring = str.substring(i, iS);
                P6.g.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
                arrayList.add(strSubstring);
                arrayList.add(null);
            } else {
                String strSubstring2 = str.substring(i, iS2);
                P6.g.d(strSubstring2, "this as java.lang.String…ing(startIndex, endIndex)");
                arrayList.add(strSubstring2);
                String strSubstring3 = str.substring(iS2 + 1, iS);
                P6.g.d(strSubstring3, "this as java.lang.String…ing(startIndex, endIndex)");
                arrayList.add(strSubstring3);
            }
            i = iS + 1;
        }
        return arrayList;
    }

    public static void h(ArrayList arrayList, StringBuilder sb) {
        P6.g.e(arrayList, "<this>");
        U6.a aVarC = s7.d.C(s7.d.H(0, arrayList.size()), 2);
        int i = aVarC.f6797q;
        int i5 = aVarC.f6798r;
        int i8 = aVarC.f6799s;
        if ((i8 <= 0 || i > i5) && (i8 >= 0 || i5 > i)) {
            return;
        }
        while (true) {
            String str = (String) arrayList.get(i);
            String str2 = (String) arrayList.get(i + 1);
            if (i > 0) {
                sb.append('&');
            }
            sb.append(str);
            if (str2 != null) {
                sb.append('=');
                sb.append(str2);
            }
            if (i == i5) {
                return;
            } else {
                i += i8;
            }
        }
    }

    public synchronized h d(String str) {
        h hVar;
        String strConcat;
        try {
            P6.g.e(str, "javaName");
            LinkedHashMap linkedHashMap = h.f14063d;
            hVar = (h) linkedHashMap.get(str);
            if (hVar == null) {
                if (X6.n.M(str, "TLS_", false)) {
                    String strSubstring = str.substring(4);
                    P6.g.d(strSubstring, "this as java.lang.String).substring(startIndex)");
                    strConcat = "SSL_".concat(strSubstring);
                } else if (X6.n.M(str, "SSL_", false)) {
                    String strSubstring2 = str.substring(4);
                    P6.g.d(strSubstring2, "this as java.lang.String).substring(startIndex)");
                    strConcat = "TLS_".concat(strSubstring2);
                } else {
                    strConcat = str;
                }
                hVar = (h) linkedHashMap.get(strConcat);
                if (hVar == null) {
                    hVar = new h(str);
                }
                linkedHashMap.put(str, hVar);
            }
        } catch (Throwable th) {
            throw th;
        }
        return hVar;
    }

    @Override // k7.InterfaceC1110b
    public y j(F f3, C c3) {
        P6.g.e(c3, "response");
        return null;
    }
}
