QQ浏览器 v12.2.3.7053版本的 MD5 值为:8285ab3059e5c8b521a264dfbc5c3685

以下内容为反编译后的 UrlUtils.java 源代码,内容仅作参考


package com.tencent.common.utils;

import android.net.Uri;
import android.text.TextUtils;
import com.huawei.hms.framework.common.ContainerUtils;
import com.qq.e.comm.constants.Constants;
import com.tencent.basesupport.FLogger;
import com.tencent.common.featuretoggle.FeatureToggle;
import com.tencent.common.http.ContentType;
import com.tencent.common.http.MimeTypeMap;
import com.tencent.common.http.NetUtils;
import com.tencent.mtt.compliance.MethodDelegate;
import com.tencent.mtt.video.browser.export.wc.m3u8.M3U8Constants;
import com.tencent.smtt.sdk.WebView;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import kotlin.jvm.internal.CharCompanionObject;
import kotlin.text.Typography;
import qb.foundation.basetask.BuildConfig;
import tmsdk.common.gourd.vine.IActionReportService;

public class UrlUtils {
    public static final String URL_CODING = "utf-8";
    private static boolean i;
    private static Object j = new Object();
    private static final boolean k = FeatureToggle.a(BuildConfig.FEATURE_TOGGLE_ADDPARAMSTOURL_869502581);
    private static Pattern l = null;
    private static Pattern m = null;
    private static Pattern n = null;
    private static Pattern o = null;
    private static Pattern p = null;
    private static Pattern q = null;
    private static Pattern r = null;
    private static Pattern s = null;
    private static Pattern t = null;
    private static Pattern u = null;
    private static Pattern v = null;
    private static Pattern w = null;
    private static Pattern x = null;
    private static Pattern y = null;
    public static String[] SUFFIX = {"gd", "com", "cn", "ac", "edu", "gov", "mil", "arpa", "net", "org", Constants.KEYS.BIZ, "info", "pro", "name", "coop", "mobi", "int", "us", "travel", "xxx", "idv", "co", "so", "tv", "hk", "asia", "me", "cc", "tw"};

    static int f10334a = 1;

    static int f10335b = 26;

    static int f10336c = 36;

    static int f10337d = 128;
    static int e = 72;
    static int f = 700;
    static int g = 38;
    static char h = '-';

    public static Pattern CONTENT_DISPOSITION_PATTERN() {
        a();
        return v;
    }

    public static Pattern INLINE_CONTENT_DISPOSITION_PATTERN() {
        a();
        return x;
    }

    public static Pattern IPV6_HEX_COMPRESSED_PATTERN() {
        a();
        return s;
    }

    public static Pattern IPV6_STD_PATTERN() {
        a();
        return r;
    }

    public static Pattern OTHER_CONTENT_DISPOSITION_PATTERN() {
        a();
        return y;
    }

    public static Pattern USER_CONTENT_DISPOSITION_PATTERN() {
        a();
        return w;
    }

    public static Pattern VALID_GAME_URL() {
        a();
        return u;
    }

    public static Pattern VALID_IPV6_URL() {
        a();
        return t;
    }

    public static Pattern VALID_IP_ADDRESS() {
        a();
        return q;
    }

    public static Pattern VALID_LOCAL_URL() {
        a();
        return m;
    }

    public static Pattern VALID_MTT_URL() {
        a();
        return n;
    }

    public static Pattern VALID_PAY_URL() {
        a();
        return p;
    }

    public static Pattern VALID_QB_URL() {
        a();
        return o;
    }

    public static Pattern VALID_URL() {
        a();
        return l;
    }

    private static String a(String str) {
        int lastIndexOf = str.lastIndexOf(com.xiaomi.mipush.sdk.Constants.COLON_SEPARATOR);
        return lastIndexOf >= 0 ? str.substring(0, lastIndexOf) : str;
    }

    static String a(String str, String str2) {
        String str3;
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
            return str;
        }
        int indexOf = str.indexOf(35);
        if (indexOf > 0) {
            String substring = str.substring(0, indexOf);
            str3 = str.substring(indexOf);
            str = substring;
        } else {
            str3 = "";
        }
        return str + (str.contains("?") ? ContainerUtils.FIELD_DELIMITER : "?") + str2 + str3;
    }

    private static String a(Pattern pattern, String str) {
        byte[] bArr;
        int indexOf;
        int indexOf2;
        try {
            Matcher matcher = pattern.matcher(str);
            if (matcher.find()) {
                String group = matcher.group(2);
                if (!TextUtils.isEmpty(group) && group.endsWith(IActionReportService.COMMON_SEPARATOR)) {
                    group = group.substring(0, group.length() - 1);
                }
                String group2 = matcher.groupCount() >= 3 ? matcher.group(3) : null;
                if (group == null) {
                    return null;
                }
                String str2 = "";
                String replace = group.replace("=?UTF8?B?", "=?UTF-8?B?");
                boolean z = false;
                while (replace.indexOf("=?UTF-8?B?") != -1) {
                    try {
                        indexOf = replace.indexOf("=?UTF-8?B?");
                        indexOf2 = replace.indexOf("?=");
                    } catch (UnsupportedEncodingException | ArrayIndexOutOfBoundsException unused) {
                    }
                    if (indexOf == -1 || indexOf2 == -1) {
                        break;
                    }
                    String substring = replace.substring(indexOf + 10, indexOf2);
                    replace = replace.substring(indexOf2 + 2);
                    str2 = str2 + new String(Base64.a(substring));
                    z = true;
                }
                if (z) {
                    group = str2;
                }
                if (e(group)) {
                    char[] charArray = group.toCharArray();
                    int length = charArray.length;
                    byte[] bArr2 = new byte[length];
                    for (int i2 = 0; i2 < length; i2++) {
                        bArr2[i2] = (byte) charArray[i2];
                    }
                    bArr = bArr2;
                } else {
                    try {
                        try {
                            bArr = group.getBytes("utf-8");
                        } catch (UnsupportedEncodingException unused2) {
                            bArr = group.getBytes("GBK");
                        }
                    } catch (UnsupportedEncodingException unused3) {
                        bArr = null;
                    }
                }
                if (group2 != null) {
                    try {
                        if (group2.equalsIgnoreCase("gbk")) {
                            return DecoderUtil.c(new String(bArr, "GBK"));
                        }
                        if (group2.equalsIgnoreCase("utf-8")) {
                            return DecoderUtil.c(new String(bArr, "utf-8"));
                        }
                    } catch (Exception unused4) {
                        return group;
                    }
                }
                return ByteUtils.guessCharacterEncoding(bArr) == 2 ? DecoderUtil.c(new String(bArr, "GBK")) : DecoderUtil.c(decode(new String(bArr, "utf-8")));
            }
        } catch (IllegalStateException unused5) {
        }
        return null;
    }

    private static void a() {
        synchronized (j) {
            if (i) {
                return;
            }
            if (!i) {
                l = Pattern.compile(".+\\.[A-Za-z]+(?:/.+[^\\w]*.*)?", 2);
                m = Pattern.compile("(^file://.+)|(.+localhost:?\\d*/.+\\..+)", 2);
                n = Pattern.compile("mtt://(.+)", 2);
                o = Pattern.compile("qb://(.+)", 2);
                u = Pattern.compile("x5gameplayer://(.+)", 2);
                p = Pattern.compile("(tenpay|alipay)://(.+)", 2);
                q = Pattern.compile("(\\d){1,3}\\.(\\d){1,3}\\.(\\d){1,3}\\.(\\d){1,3}(:\\d{1,4})?(/(.*))?", 2);
                t = Pattern.compile("((^((http://|https://)?\\[(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|([0-9a-fA-F]{1,4}:){1,7}:|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))]))(.*))", 2);
                w = Pattern.compile("\\s*filename\\s*=\\s*(\"?)([^\"]*)\\1\\s*[;\\s*charset=\\s*]*([^\"]*)\\s*$", 2);
                v = Pattern.compile("attachment;\\s*filename\\s*=\\s*(\"?)([^\"]*)\\1\\s*[;\\s*charset=\\s*]*([^\"]*)\\s*$", 2);
                x = Pattern.compile("inline;\\s*filename\\s*=\\s*(\"?)([^\"]*)\\1\\s*[;\\s*charset=\\s*]*([^\"]*)\\s*$", 2);
                y = Pattern.compile("filename\\*\\s*=UTF-8''\\s*(\"?)([^\"]*)\\1\\s*[;\\s*charset=\\s*]*([^\"]*)\\s*$", 2);
                r = Pattern.compile("^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$");
                s = Pattern.compile("^((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)$");
                i = true;
            }
        }
    }

    private static boolean a(long j2, long j3, long j4) {
        return j2 >= j3 && j2 <= j4;
    }

    public static int adapt(int i2, int i3, boolean z) {
        int i4 = z ? i2 / f : i2 / 2;
        int i5 = i4 + (i4 / i3);
        int i6 = 0;
        while (true) {
            int i7 = f10336c;
            int i8 = f10334a;
            if (i5 <= ((i7 - i8) * f10335b) / 2) {
                return i6 + ((((i7 - i8) + 1) * i5) / (i5 + g));
            }
            i5 /= i7 - i8;
            i6 += i7;
        }
    }

    public static String addParamsToUrl(String str, String str2) {
        return k ? b(str, str2) : a(str, str2);
    }

    private static String b(String str) {
        int indexOf = str.indexOf(47);
        return indexOf != -1 ? str.substring(0, indexOf) : str;
    }

    static String b(String str, String str2) {
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
            return str;
        }
        StringBuilder sb = new StringBuilder(str.length() + str2.length() + 2);
        int indexOf = str.indexOf(35);
        if (indexOf > 0) {
            sb.append((CharSequence) str, 0, indexOf);
        } else {
            sb.append(str);
        }
        sb.append(sb.indexOf("?") >= 0 ? Typography.amp : '?');
        sb.append(str2);
        if (indexOf > 0) {
            sb.append((CharSequence) str, indexOf, str.length());
        }
        return sb.toString();
    }

    private static String c(String str) {
        int d2 = d(str);
        int indexOf = str.indexOf(63, d2);
        return indexOf != -1 ? str.substring(d2, indexOf) : str.substring(d2);
    }

    public static int codepoint2digit(int i2) throws Exception {
        int i3 = i2 - 48;
        if (i3 < 10) {
            return i3 + 26;
        }
        int i4 = i2 - 97;
        if (i4 < 26) {
            return i4;
        }
        throw new Exception("BAD_INPUT");
    }

    private static int d(String str) {
        int indexOf;
        if (TextUtils.isEmpty(str) || (indexOf = str.indexOf("://")) == -1) {
            return 0;
        }
        return indexOf + 3;
    }

    public static String decode(String str) {
        if (TextUtils.isEmpty(str)) {
            return str;
        }
        try {
            return URLDecoder.decode(str, "utf-8");
        } catch (UnsupportedEncodingException unused) {
            return str;
        } catch (Exception unused2) {
            FLogger.d("UrlUtility", "decode url failure");
            return str;
        }
    }

    public static String deleteCustomPrefix(String str) {
        return (isDttpUrl(str) || isSecurityCacheUrl(str) || isSecurityFileUrl(str) || isBrokerUrl(str) || isWebkitUrl(str)) ? deletePrefix(str) : str;
    }

    public static String deleteHttpPrefix(String str) {
        int i2;
        if (TextUtils.isEmpty(str)) {
            return str;
        }
        if (str.startsWith(NetUtils.SCHEME_HTTP)) {
            i2 = 7;
        } else {
            if (!str.startsWith(NetUtils.SCHEME_HTTPS)) {
                return str;
            }
            i2 = 8;
        }
        return str.substring(i2);
    }

    public static String deletePrefix(String str) {
        int indexOf;
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        if (str.startsWith("page://") && (indexOf = str.indexOf(NetUtils.SCHEME_HTTP)) != -1) {
            return str.substring(indexOf);
        }
        int indexOf2 = str.indexOf("://");
        return indexOf2 >= 0 ? str.substring(indexOf2 + 3) : str;
    }

    public static int digit2codepoint(int i2) throws Exception {
        if (i2 < 26) {
            return i2 + 97;
        }
        if (i2 < 36) {
            return (i2 - 26) + 48;
        }
        throw new Exception("BAD_INPUT");
    }

    private static boolean e(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        for (char c2 : str.toCharArray()) {
            if (((byte) ((c2 >> '\b') & 255)) != 0) {
                return false;
            }
        }
        return true;
    }

    public static String encode(String str) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        try {
            return URLEncoder.encode(str, "utf-8");
        } catch (UnsupportedEncodingException unused) {
            return str;
        } catch (Exception unused2) {
            FLogger.d("UrlUtility", "encode url failure");
            return str;
        }
    }

    public static String escape(String str) {
        if (str != null && str.trim().length() != 0) {
            try {
                int indexOf = str.indexOf(63);
                if (indexOf != -1) {
                    int i2 = indexOf + 1;
                    String substring = str.substring(0, i2);
                    String[] split = str.substring(i2).split(ContainerUtils.FIELD_DELIMITER);
                    StringBuilder sb = new StringBuilder();
                    sb.append(substring);
                    boolean z = false;
                    for (String str2 : split) {
                        if (str2 != null && str2.length() > 0) {
                            int indexOf2 = str2.indexOf(61);
                            if (indexOf2 != -1) {
                                int i3 = indexOf2 + 1;
                                sb.append(str2.substring(0, i3));
                                String substring2 = str2.substring(i3);
                                if (substring2 != null && substring2.length() > 0) {
                                    int i4 = 0;
                                    boolean z2 = true;
                                    int i5 = 0;
                                    while (i4 < substring2.length()) {
                                        char charAt = substring2.charAt(i4);
                                        if ((charAt < 19968 || charAt > 40959) && (charAt < 65072 || charAt > 65440)) {
                                            if (!z2) {
                                                sb.append(URLEncoder.encode(substring2.substring(i5, i4), "utf-8"));
                                            }
                                            sb.append(charAt);
                                            i5 = i4;
                                            z2 = true;
                                        } else {
                                            z2 = false;
                                        }
                                        i4++;
                                    }
                                    if (!z2 && i5 < i4) {
                                        sb.append(URLEncoder.encode(substring2.substring(i5, i4), "utf-8"));
                                    }
                                }
                            } else {
                                sb.append(str2);
                            }
                            sb.append(Typography.amp);
                            z = true;
                        }
                    }
                    String sb2 = sb.toString();
                    return (z && sb2.charAt(sb2.length() - 1) == '&') ? sb2.substring(0, sb2.length() - 1) : sb2;
                }
            } catch (Exception unused) {
            }
        }
        return str;
    }

    public static String escapeAllChineseChar(String str) {
        StringBuilder sb = new StringBuilder();
        for (int i2 = 0; i2 < str.length(); i2++) {
            char charAt = str.charAt(i2);
            if ((charAt < 19968 || charAt > 40959) && (charAt < 65072 || charAt > 65440)) {
                sb.append(charAt);
            } else {
                try {
                    String encode = URLEncoder.encode(String.valueOf(charAt), "utf-8");
                    FLogger.d("Url", " : " + encode);
                    sb.append(encode);
                } catch (UnsupportedEncodingException unused) {
                }
            }
        }
        return sb.toString();
    }

    private static long f(String str) {
        String[] split = str.split("\\.");
        return (Integer.parseInt(split[0]) * 256 * 256 * 256) + (Integer.parseInt(split[1]) * 256 * 256) + (Integer.parseInt(split[2]) * 256) + Integer.parseInt(split[3]);
    }

    public static String getAction(String str) {
        String[] split;
        String stringAfterHost = getStringAfterHost(str);
        return (TextUtils.isEmpty(stringAfterHost) || (split = stringAfterHost.split("/|\\?")) == null || split.length <= 0) ? "" : split[0];
    }

    public static String getDataFromQbUrl(String str, String str2) {
        if (str == null) {
            return "";
        }
        try {
            for (String str3 : str.substring(str.indexOf(63) + 1).split(ContainerUtils.FIELD_DELIMITER)) {
                String[] split = str3.split(ContainerUtils.KEY_VALUE_DELIMITER);
                if (split[0].equalsIgnoreCase(str2)) {
                    return split[1];
                }
            }
            return "";
        } catch (Exception unused) {
            return null;
        }
    }

    public static String getDefaultExtensionByMimeType(String str) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        if (str != null && str.toLowerCase().startsWith("text/")) {
            return str.equalsIgnoreCase("text/html") ? ".html" : ".txt";
        }
        if (str == null || !str.toLowerCase().startsWith("image/")) {
            if (str == null || !str.toLowerCase().startsWith("video/")) {
                return ".bin";
            }
            if (str.equalsIgnoreCase("video/flv")) {
                return ".flv";
            }
            return null;
        }
        if (str.equalsIgnoreCase("image/png")) {
            return ".png";
        }
        if (str.equalsIgnoreCase("image/jpeg")) {
            return ".jpeg";
        }
        if (str.equalsIgnoreCase("image/jpg")) {
            return ".jpg";
        }
        if (str.equalsIgnoreCase("image/gif")) {
            return ".gif";
        }
        return null;
    }

    public static String getDomainIp(String str) {
        try {
            return MethodDelegate.getHostAddress(InetAddress.getByName(new URI(str).getHost()));
        } catch (Error | Exception unused) {
            return "";
        }
    }

    @Deprecated
    public static String getHost(String str) {
        if (str == null || str.length() == 0) {
            return null;
        }
        int d2 = d(str);
        int indexOf = str.indexOf(47, d2);
        String substring = (indexOf == -1 && (indexOf = str.indexOf(63, d2)) == -1) ? str.substring(d2) : str.substring(d2, indexOf);
        int lastIndexOf = substring.lastIndexOf(com.xiaomi.mipush.sdk.Constants.COLON_SEPARATOR);
        return lastIndexOf >= 0 ? substring.substring(0, lastIndexOf) : substring;
    }

    public static String getHostNew(String str) {
        return (str == null || str.length() == 0) ? "" : a(b(c(str)));
    }

    public static String getJavascriptCommand(String str) {
        int indexOf = str.indexOf(58);
        int indexOf2 = str.indexOf(59);
        int i2 = indexOf == -1 ? 0 : indexOf + 1;
        if (indexOf2 == -1) {
            indexOf2 = str.length();
        }
        return str.substring(i2, indexOf2);
    }

    public static String getMailUrl(String str) {
        if (str == null || "".equalsIgnoreCase(str) || !isMailUrl(str)) {
            return null;
        }
        return str;
    }

    public static String getPara(String str) {
        String[] split;
        String stringAfterHost = getStringAfterHost(str);
        return (TextUtils.isEmpty(stringAfterHost) || (split = stringAfterHost.split("/|\\?")) == null || split.length <= 1) ? "" : split[1];
    }

    public static String getPath(String str) {
        int indexOf;
        if (str == null || str.length() == 0 || (indexOf = str.indexOf(47, d(str))) == -1) {
            return null;
        }
        int indexOf2 = str.indexOf(63, indexOf);
        int i2 = indexOf + 1;
        return indexOf2 != -1 ? str.substring(i2, indexOf2) : str.substring(i2);
    }

    public static String getPathAndQuery(String str) {
        if (TextUtils.isEmpty(str)) {
            return "";
        }
        try {
            URL url = new URL(str);
            return url.getPath() + url.getQuery();
        } catch (MalformedURLException unused) {
            return "";
        }
    }

    public static String getSchema(String str) {
        int indexOf;
        return (TextUtils.isEmpty(str) || (indexOf = str.indexOf("://")) <= 0) ? "" : str.substring(0, indexOf + 3);
    }

    public static String getSmsTextFromUrl(String str) {
        int indexOf;
        int indexOf2;
        if (isSmsUrl(str) && (indexOf = str.indexOf(63)) > -1 && indexOf < str.length() - 1) {
            for (String str2 : str.substring(indexOf + 1).split(ContainerUtils.FIELD_DELIMITER)) {
                if (str2.startsWith("body=") && (indexOf2 = str2.indexOf(61)) > -1 && indexOf2 < str2.length() - 1) {
                    return str2.substring(indexOf2 + 1);
                }
            }
        }
        return null;
    }

    public static Uri getSmsUriFromUrl(String str) {
        if (!isSmsUrl(str)) {
            return null;
        }
        String replaceFirst = str.replaceFirst("sms:", "smsto:");
        int indexOf = replaceFirst.indexOf(63);
        return indexOf > -1 ? Uri.parse(replaceFirst.substring(0, indexOf)) : Uri.parse(replaceFirst);
    }

    public static String getStringAfterHost(String str) {
        int indexOf;
        if (str == null || str.length() == 0 || (indexOf = str.indexOf(47, d(str))) == -1) {
            return null;
        }
        return str.substring(indexOf + 1);
    }

    public static String getTelUrl(String str) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        if (isTelUrl(str)) {
            return str;
        }
        String wtaiUrl = getWtaiUrl(str);
        if (wtaiUrl == null) {
            return null;
        }
        return WebView.SCHEME_TEL + wtaiUrl;
    }

    public static HashMap<String, String> getUrlParam(String str) {
        String[] split;
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        HashMap<String, String> hashMap = new HashMap<>();
        int indexOf = str.indexOf(63);
        if (indexOf != -1 && (split = str.substring(indexOf + 1).split(ContainerUtils.FIELD_DELIMITER)) != null && split.length > 0) {
            for (String str2 : split) {
                int indexOf2 = str2.indexOf(61);
                if (indexOf2 != -1) {
                    String substring = str2.substring(0, indexOf2);
                    String substring2 = str2.substring(indexOf2 + 1, str2.length());
                    try {
                        substring2 = URLDecoder.decode(substring2, "UTF-8");
                    } catch (UnsupportedEncodingException | Exception unused) {
                    }
                    hashMap.put(substring, substring2);
                }
            }
        }
        return hashMap;
    }

    public static String getUrlParamValue(String str, String str2) {
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
            return "";
        }
        Matcher matcher = Pattern.compile("(#|\\?|&)(" + str2 + "=.*?)(#|&|$)", 2).matcher(str);
        if (matcher == null || !matcher.find() || matcher.groupCount() <= 2) {
            return "";
        }
        return matcher.group(2).replace(str2 + ContainerUtils.KEY_VALUE_DELIMITER, "");
    }

    public static String getValueByKey(String str, String str2, String str3, char c2) {
        if (!str2.contains(str3)) {
            return "";
        }
        StringBuffer stringBuffer = new StringBuffer();
        for (int indexOf = str2.indexOf(str3) + str3.length(); indexOf < str.length() && str.charAt(indexOf) != c2; indexOf++) {
            stringBuffer.append(str.charAt(indexOf));
        }
        return stringBuffer.toString();
    }

    public static String getWtaiUrl(String str) {
        if (!isWtaiUrl(str)) {
            return null;
        }
        int indexOf = str.indexOf("?", 13);
        return indexOf != -1 ? str.substring(13, indexOf) : str.substring(13);
    }

    public static final String guessFileName(String str, String str2, String str3) {
        String str4;
        String str5;
        String decode;
        int lastIndexOf;
        int lastIndexOf2;
        int lastIndexOf3;
        String str6 = null;
        boolean z = true;
        if (str2 != null) {
            String a2 = a(OTHER_CONTENT_DISPOSITION_PATTERN(), str2);
            if (a2 != null) {
                lastIndexOf3 = a2.lastIndexOf(47) + 1;
            } else {
                a2 = a(USER_CONTENT_DISPOSITION_PATTERN(), str2);
                if (a2 != null) {
                    lastIndexOf3 = a2.lastIndexOf(47) + 1;
                } else {
                    a2 = a(CONTENT_DISPOSITION_PATTERN(), str2);
                    if (a2 != null) {
                        lastIndexOf3 = a2.lastIndexOf(47) + 1;
                    } else {
                        str4 = a(INLINE_CONTENT_DISPOSITION_PATTERN(), str2);
                        if (str4 != null && (lastIndexOf2 = str4.lastIndexOf(47) + 1) > 0) {
                            str4 = str4.substring(lastIndexOf2);
                        }
                    }
                }
            }
        } else {
            str4 = null;
        }
        if (str4 == null && (decode = Uri.decode(str)) != null) {
            int indexOf = decode.indexOf(63);
            if (indexOf > 0) {
                decode = decode.substring(0, indexOf);
            }
            if (!decode.endsWith("/") && (lastIndexOf = decode.lastIndexOf(47) + 1) > 0) {
                str4 = decode.substring(lastIndexOf);
            }
        }
        if (str4 == null) {
            str4 = "downloadfile";
        }
        int lastIndexOf4 = str4.lastIndexOf(46);
        if (lastIndexOf4 < 0) {
            if (str3 != null && (str6 = MimeTypeMap.getSingleton().getExtensionFromMimeType(str3)) != null) {
                str6 = "." + str6;
            }
            if (str6 == null) {
                str6 = getDefaultExtensionByMimeType(str3);
            }
        } else {
            String substring = str4.substring(lastIndexOf4 + 1);
            if (substring != null && (ContentType.SUBTYPE_PNG.equalsIgnoreCase(substring) || ContentType.SUBTYPE_JPEG.equalsIgnoreCase(substring) || "jpg".equalsIgnoreCase(substring) || "gif".equalsIgnoreCase(substring))) {
                str6 = "." + substring;
            } else if (TextUtils.isEmpty(substring) && str3 != null) {
                if (substring == null || !substring.equalsIgnoreCase("apk")) {
                    str6 = MimeTypeMap.getSingleton().getExtensionFromMimeType(str3);
                    if (str6 != null) {
                        str6 = "." + str6;
                    }
                } else {
                    str6 = ".apk";
                }
            }
            if (str6 == null) {
                str6 = str4.substring(lastIndexOf4);
            }
            str4 = str4.substring(0, lastIndexOf4);
        }
        if (str6 == null && str3 != null && str3.startsWith("image/")) {
            str5 = "." + str3.substring(str3.indexOf("/") + 1);
            if (!ContentType.SUBTYPE_PNG.equalsIgnoreCase(str5) && !ContentType.SUBTYPE_JPEG.equalsIgnoreCase(str5) && !"jpg".equalsIgnoreCase(str5) && !"gif".equalsIgnoreCase(str5)) {
                z = false;
            }
        }
        str5 = str6;
        if (str5 == null) {
            str5 = "";
        }
        return str4 + str5;
    }

    public static boolean hasValidProtocal(String str) {
        if (str == null || str.length() == 0) {
            return false;
        }
        int indexOf = str.indexOf("://");
        int indexOf2 = str.indexOf(46);
        if (indexOf <= 0 || indexOf2 <= 0 || indexOf <= indexOf2) {
            return str.contains("://");
        }
        return false;
    }

    public static boolean isAnchorUrl(String str) {
        if (str == null || str.length() == 0) {
            return false;
        }
        return str.startsWith(M3U8Constants.COMMENT_PREFIX);
    }

    public static boolean isBasic(char c2) {
        return c2 < 128;
    }

    public static boolean isBrokerUrl(String str) {
        if (str == null || str.length() == 0) {
            return false;
        }
        return str.startsWith("page:") || str.startsWith("hotpre:");
    }

    public static boolean isDataBase64Url(String str) {
        return str != null && str.startsWith("data:text/html; charset=utf-8;base64,");
    }

    public static boolean isDataUrl(String str) {
        if (str == null || str.length() < 5) {
            return false;
        }
        return str.substring(0, 5).equalsIgnoreCase("data:");
    }

    public static boolean isDeprecatedSechema(String str) {
        return isWebkitUrl(str) || isMttUrl(str) || isBrokerUrl(str) || isDttpUrl(str) || isTencentUrl(str);
    }

    public static boolean isDttpUrl(String str) {
        if (str == null || str.length() == 0) {
            return false;
        }
        return str.toLowerCase().startsWith("dttp://");
    }

    public static boolean isEmptyUrl(String str) {
        return str == null || str.trim().length() == 0 || str.trim().equals("/");
    }

    public static boolean isFileUrl(String str) {
        return str != null && str.length() > 6 && str.substring(0, 7).equalsIgnoreCase("file://");
    }

    public static boolean isFtpUrl(String str) {
        return str != null && str.length() > 5 && str.substring(0, 6).equalsIgnoreCase("ftp://");
    }

    public static boolean isHttpUrl(String str) {
        return str != null && str.length() > 6 && str.substring(0, 7).equalsIgnoreCase(NetUtils.SCHEME_HTTP);
    }

    public static boolean isHttpsUrl(String str) {
        return str != null && str.length() > 7 && str.substring(0, 8).equalsIgnoreCase(NetUtils.SCHEME_HTTPS);
    }

    public static boolean isIPv6Address(String str) {
        return isIPv6StdAddress(str) || isIPv6HexCompressedAddress(str);
    }

    public static boolean isIPv6HexCompressedAddress(String str) {
        return IPV6_HEX_COMPRESSED_PATTERN().matcher(str).matches();
    }

    public static boolean isIPv6StdAddress(String str) {
        return IPV6_STD_PATTERN().matcher(str).matches();
    }

    public static boolean isInnerIP(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        if (!VALID_IP_ADDRESS().matcher(str.trim()).find()) {
            return false;
        }
        try {
            long f2 = f(str);
            long f3 = f("10.0.0.0");
            long f4 = f("10.255.255.255");
            long f5 = f("172.16.0.0");
            long f6 = f("172.31.255.255");
            long f7 = f("192.168.0.0");
            long f8 = f("192.168.255.255");
            if (!a(f2, f3, f4) && !a(f2, f5, f6) && !a(f2, f7, f8) && !str.equals("127.0.0.1")) {
                if (!str.equals("1.1.1.1")) {
                    return false;
                }
            }
            return true;
        } catch (Exception unused) {
            return false;
        }
    }

    public static boolean isIpUrl(String str) {
        if (str != null && str.length() != 0) {
            if (VALID_IP_ADDRESS().matcher(str.trim()).find()) {
                return true;
            }
        }
        return false;
    }

    public static boolean isIpv6Url(String str) {
        if (str != null && str.length() != 0) {
            if (VALID_IPV6_URL().matcher(str.trim()).find()) {
                return true;
            }
        }
        return false;
    }

    public static boolean isJavascript(String str) {
        return str != null && str.length() > 10 && str.substring(0, 11).equalsIgnoreCase("javascript:");
    }

    public static boolean isMailUrl(String str) {
        return str != null && str.length() > 7 && str.substring(0, 7).equalsIgnoreCase("mailto:");
    }

    public static boolean isMarketUrl(String str) {
        return str != null && str.length() > 8 && str.substring(0, 9).equalsIgnoreCase("market://");
    }

    public static boolean isMmsUrl(String str) {
        if (str != null) {
            if (str.length() > 6 && str.substring(0, 6).equalsIgnoreCase("mms://")) {
                return true;
            }
            if (str.length() > 7 && str.substring(0, 7).equalsIgnoreCase("mmsh://")) {
                return true;
            }
            if (str.length() > 7 && str.substring(0, 7).equalsIgnoreCase("mmst://")) {
                return true;
            }
        }
        return false;
    }

    public static boolean isMttUrl(String str) {
        if (str == null || str.length() == 0) {
            return false;
        }
        return str.toLowerCase().startsWith("mtt://");
    }

    public static boolean isRtmpUrl(String str) {
        return str != null && str.length() > 6 && str.substring(0, 7).equalsIgnoreCase("rtmp://");
    }

    public static boolean isRtspUrl(String str) {
        return str != null && str.length() > 6 && str.substring(0, 7).equalsIgnoreCase("rtsp://");
    }

    public static boolean isSecurityCacheUrl(String str) {
        if (str == null || str.length() == 0) {
            return false;
        }
        return str.startsWith("security://");
    }

    public static boolean isSecurityFileUrl(String str) {
        if (str == null || str.length() == 0) {
            return false;
        }
        return str.startsWith("securityFile://");
    }

    public static boolean isSmsUrl(String str) {
        return str != null && str.length() > 4 && str.substring(0, 4).equalsIgnoreCase("sms:");
    }

    public static boolean isTelUrl(String str) {
        return str != null && str.length() > 4 && str.substring(0, 4).equalsIgnoreCase(WebView.SCHEME_TEL);
    }

    public static boolean isTencentUrl(String str) {
        if (str == null || str.length() == 0) {
            return false;
        }
        return str.toLowerCase().startsWith("tencent://");
    }

    public static boolean isWebUrl(String str) {
        return isHttpUrl(str) || isHttpsUrl(str);
    }

    public static boolean isWebkitUrl(String str) {
        if (str == null || str.length() == 0) {
            return false;
        }
        return str.toLowerCase().startsWith("webkit://");
    }

    public static boolean isWsUrl(String str) {
        return str != null && str.length() > 4 && str.substring(0, 5).equalsIgnoreCase("ws://");
    }

    public static boolean isWssUrl(String str) {
        return str != null && str.length() > 5 && str.substring(0, 6).equalsIgnoreCase("wss://");
    }

    public static boolean isWtaiUrl(String str) {
        return str != null && str.length() > 13 && str.substring(0, 13).equalsIgnoreCase("wtai://wp/mc;");
    }

    public static String prepareUrl(String str) {
        if (str == null || str.length() == 0 || str.charAt(0) == '#') {
            return str;
        }
        try {
            str = str.replaceAll(" ", "%20").replaceAll("&amp;", ContainerUtils.FIELD_DELIMITER).replaceAll("\\|", "%7C").replaceAll("\\^", "%5E").replaceAll("<", "%3C").replaceAll(">", "%3E").replaceAll("\\{", "%7B").replaceAll("\\}", "%7D");
        } catch (PatternSyntaxException unused) {
        }
        return !isSmsUrl(str) ? escapeAllChineseChar(str) : str;
    }

    public static String punyCodedecode(String str) throws Exception {
        int i2;
        int i3;
        int i4;
        int i5;
        int i6 = f10337d;
        int i7 = e;
        StringBuilder sb = new StringBuilder();
        int lastIndexOf = str.lastIndexOf(h);
        if (lastIndexOf > 0) {
            for (int i8 = 0; i8 < lastIndexOf; i8++) {
                char charAt = str.charAt(i8);
                if (!isBasic(charAt)) {
                    throw new Exception("BAD_INPUT");
                }
                sb.append(charAt);
            }
            i4 = lastIndexOf + 1;
            i2 = i6;
            i3 = 0;
        } else {
            i2 = i6;
            i3 = 0;
            i4 = 0;
        }
        while (i4 < str.length()) {
            int i9 = f10336c;
            int i10 = 1;
            int i11 = i3;
            while (i4 != str.length()) {
                int i12 = i4 + 1;
                int codepoint2digit = codepoint2digit(str.charAt(i4));
                if (codepoint2digit > (Integer.MAX_VALUE - i11) / i10) {
                    throw new Exception("OVERFLOW");
                }
                i11 += codepoint2digit * i10;
                if (i9 <= i7) {
                    i5 = f10334a;
                } else {
                    i5 = f10335b;
                    if (i9 < i7 + i5) {
                        i5 = i9 - i7;
                    }
                }
                if (codepoint2digit < i5) {
                    i7 = adapt(i11 - i3, sb.length() + 1, i3 == 0);
                    if (i11 / (sb.length() + 1) > Integer.MAX_VALUE - i2) {
                        throw new Exception("OVERFLOW");
                    }
                    i2 += i11 / (sb.length() + 1);
                    int length = i11 % (sb.length() + 1);
                    sb.insert(length, (char) i2);
                    i3 = length + 1;
                    i4 = i12;
                } else {
                    int i13 = f10336c;
                    i10 *= i13 - i5;
                    i9 += i13;
                    i4 = i12;
                }
            }
            throw new Exception("BAD_INPUT");
        }
        return sb.toString();
    }

    public static String punyCodeencode(String str) throws Exception {
        int i2;
        int i3 = f10337d;
        int i4 = e;
        StringBuilder sb = new StringBuilder();
        int i5 = 0;
        for (int i6 = 0; i6 < str.length(); i6++) {
            char charAt = str.charAt(i6);
            if (isBasic(charAt)) {
                sb.append(charAt);
                i5++;
            }
        }
        if (i5 > 0) {
            sb.append(h);
        }
        int i7 = i4;
        int i8 = 0;
        int i9 = i3;
        int i10 = i5;
        while (i10 < str.length()) {
            char c2 = CharCompanionObject.MAX_VALUE;
            for (int i11 = 0; i11 < str.length(); i11++) {
                char charAt2 = str.charAt(i11);
                if (charAt2 >= i9 && charAt2 < c2) {
                    c2 = charAt2;
                }
            }
            int i12 = c2 - i9;
            int i13 = i10 + 1;
            if (i12 > (Integer.MAX_VALUE - i8) / i13) {
                throw new Exception("OVERFLOW");
            }
            int i14 = i8 + (i12 * i13);
            int i15 = i10;
            for (int i16 = 0; i16 < str.length(); i16++) {
                char charAt3 = str.charAt(i16);
                if (charAt3 < c2 && (i14 = i14 + 1) == 0) {
                    throw new Exception("OVERFLOW");
                }
                if (charAt3 == c2) {
                    int i17 = f10336c;
                    int i18 = i14;
                    while (true) {
                        if (i17 <= i7) {
                            i2 = f10334a;
                        } else {
                            i2 = f10335b;
                            if (i17 < i7 + i2) {
                                i2 = i17 - i7;
                            }
                        }
                        if (i18 < i2) {
                            break;
                        }
                        int i19 = i18 - i2;
                        sb.append((char) digit2codepoint((i19 % (f10336c - i2)) + i2));
                        int i20 = f10336c;
                        i18 = i19 / (i20 - i2);
                        i17 += i20;
                    }
                    sb.append((char) digit2codepoint(i18));
                    int i21 = i15 + 1;
                    int adapt = adapt(i14, i21, i15 == i5);
                    i14 = 0;
                    i7 = adapt;
                    i15 = i21;
                }
            }
            i8 = i14 + 1;
            int i22 = i15;
            i9 = c2 + 1;
            i10 = i22;
        }
        return sb.toString();
    }

    public static String removeArg(String str, String str2) {
        if (TextUtils.isEmpty(str)) {
            return "";
        }
        if (TextUtils.isEmpty(str)) {
            return str;
        }
        if (!str.contains("?" + str2 + ContainerUtils.KEY_VALUE_DELIMITER)) {
            if (!str.contains(ContainerUtils.FIELD_DELIMITER + str2 + ContainerUtils.KEY_VALUE_DELIMITER)) {
                return str;
            }
        }
        int indexOf = str.indexOf(str2 + ContainerUtils.KEY_VALUE_DELIMITER);
        if (indexOf == -1) {
            return str;
        }
        String substring = str.substring(0, indexOf);
        String substring2 = str.substring(indexOf + 1);
        if (TextUtils.isEmpty(substring2) || substring2.indexOf(ContainerUtils.FIELD_DELIMITER) <= 0) {
            return str.substring(0, indexOf - 1);
        }
        return substring + substring2.substring(substring2.indexOf(ContainerUtils.FIELD_DELIMITER) + 1);
    }

    public static String removeMMSprefix(String str) {
        return !TextUtils.isEmpty(str) ? (str.toLowerCase().startsWith("sms:") || str.toLowerCase().startsWith("smsto:") || str.toLowerCase().startsWith("mms:") || str.toLowerCase().startsWith("mmsto:")) ? str.substring(str.indexOf(com.xiaomi.mipush.sdk.Constants.COLON_SEPARATOR) + 1, str.length()) : str : str;
    }

    public static String replaceValueByKey(String str, String str2, String str3) {
        String str4;
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
            return str;
        }
        StringBuilder sb = new StringBuilder("");
        int indexOf = str.indexOf(63);
        if (indexOf != -1) {
            sb.append(str.substring(0, indexOf));
            str4 = "?";
        } else {
            str4 = "";
        }
        String[] split = str.substring(indexOf + 1).split(ContainerUtils.FIELD_DELIMITER);
        int length = split.length;
        int i2 = 0;
        while (i2 < length) {
            String[] split2 = split[i2].split(ContainerUtils.KEY_VALUE_DELIMITER);
            if (split2[0].equalsIgnoreCase(str2) && split2.length == 2) {
                split2[1] = str3;
            }
            sb.append(i2 == 0 ? str4 : ContainerUtils.FIELD_DELIMITER);
            sb.append(split2[0]);
            sb.append(ContainerUtils.KEY_VALUE_DELIMITER);
            sb.append(split2.length == 2 ? split2[1] : "");
            i2++;
        }
        return sb.toString();
    }

    public static String resolvValidSqlUrl(String str) {
        return TextUtils.isEmpty(str) ? str : str.replaceAll("'", "''");
    }

    public static String resolveBase(String str, String str2) {
        try {
            String prepareUrl = prepareUrl(toURL(str).toString());
            return new URI(prepareUrl).resolve(prepareUrl(str2)).toURL().toString();
        } catch (MalformedURLException | Exception unused) {
            return "";
        }
    }

    public static String stripAnhcor(String str) throws MalformedURLException {
        int indexOf = str.indexOf(35);
        return indexOf != -1 ? str.substring(0, indexOf) : str;
    }

    @Deprecated
    public static String stripPath(String str) {
        String host;
        if (TextUtils.isEmpty(str) || (host = getHost(str)) == null || "".equals(host)) {
            return null;
        }
        return getSchema(str) + host;
    }

    public static String stripPathNew(String str) {
        if (TextUtils.isEmpty(str)) {
            return "";
        }
        String hostNew = getHostNew(str);
        if ("".equals(hostNew)) {
            return "";
        }
        return getSchema(str) + hostNew;
    }

    public static URL stripQuery(URL url) throws MalformedURLException {
        String file = url.getFile();
        int indexOf = file.indexOf("?");
        if (indexOf == -1) {
            return url;
        }
        return new URL(url.getProtocol(), url.getHost(), url.getPort(), file.substring(0, indexOf));
    }

    public static String stripSchemePrefix(String str) {
        int indexOf;
        return (TextUtils.isEmpty(str) || (indexOf = str.indexOf("://")) == -1) ? str : str.substring(indexOf + 3);
    }

    public static URL toURL(String str) throws MalformedURLException {
        int indexOf;
        URL url = new URL(str);
        if (url.getPath() != null && !"".equals(url.getPath())) {
            return url;
        }
        if (url.getFile() != null && url.getFile().startsWith("?") && (indexOf = str.indexOf(63)) != -1) {
            url = new URL(str.substring(0, indexOf) + '/' + str.substring(indexOf));
        }
        if (url.getFile() != null && !"".equals(url.getFile())) {
            return url;
        }
        return new URL(str + "/");
    }
}