package com.linksure.browser.utils; import android.net.Uri; import android.text.TextUtils; import android.util.Log; import android.util.Patterns; import com.j256.ormlite.stmt.query.SimpleComparison; import com.lantern.webviewsdk.webview_compats.IURLUtil; import com.xiaomi.mipush.sdk.Constants; import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; import java.util.HashSet; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; /* compiled from: UrlUtils */ public final class v { /* renamed from: a reason: collision with root package name */ public static final Pattern f7420a = Pattern.compile("(?i)((?:http|https|file):\\/\\/|(?:inline|data|about|javascript):)(.*)"); /* renamed from: b reason: collision with root package name */ private static final Pattern f7421b = Pattern.compile("^http://(.*?)$"); private static final Pattern c = Pattern.compile("attachment;\\s*filename\\s*=\\s*(\"?)([^\"]*)\\1\\s*$", 2); private static final Set<String> d = new HashSet(Arrays.asList(new String("com|org|net|gov|edu|co|tv|mobi|info|asia|xxx|onion|cn|com.cn|edu.cn|gov.cn|net.cn|org.cn|jp|kr|tw|com.hk|hk|com.hk|org.hk|se|com.se|org.se").split("\\|"))); private static Pattern e = Pattern.compile("(\\d{1,3}\\.){3}(\\d{1,3})"); public static String a(String str) { String str2 = null; if (str == null) { return null; } Matcher matcher = Pattern.compile("(?<=http://|\\.)[^.]*?\\.(com|cn|net|org|biz|info|cc|tv)", 2).matcher(str); while (matcher.find()) { str2 = matcher.group(); } return str2; } public static boolean a(String str, String str2) { try { String a2 = a(str); String a3 = a(str2); if (TextUtils.isEmpty(a2) || TextUtils.isEmpty(a3) || !a2.equals(a3)) { return false; } return true; } catch (Exception unused) { return false; } } public static String b(String str) { String str2; int lastIndexOf; StringBuilder sb = new StringBuilder("url:"); sb.append(str); sb.append("contentDisposition:"); String str3 = null; sb.append((String) null); sb.append("mimeType:"); sb.append((String) null); sb.append("fileName"); sb.append((String) null); sb.append("extension:"); sb.append((String) null); Log.d("URLUtil", sb.toString()); String decode = Uri.decode(str); if (decode != null) { int indexOf = decode.indexOf(63); if (indexOf > 0) { decode = decode.substring(0, indexOf); } if (!decode.endsWith("/") && (lastIndexOf = decode.lastIndexOf(47) + 1) > 0) { str3 = decode.substring(lastIndexOf); } } if (str3 == null) { str3 = "downloadfile"; } int indexOf2 = str3.indexOf(46); if (indexOf2 < 0) { str2 = ".bin"; } else { String substring = str3.substring(indexOf2); str3 = str3.substring(0, indexOf2); str2 = substring; } return str3 + str2; } public static String c(String str) { if (str == null || str.trim().equals("")) { return ""; } Matcher matcher = Pattern.compile("(?<=//|)((\\w)+\\.)+\\w+").matcher(str); if (matcher.find()) { return matcher.group(); } return ""; } private static String a(URL url) { String host = url.getHost(); int i = 0; if (host.endsWith(".")) { host = host.substring(0, host.length() - 1); } if (e.matcher(host).matches()) { return host; } while (i >= 0) { i = host.indexOf(46); String substring = host.substring(i + 1); if (d.contains(substring)) { return host; } host = substring; } return host; } public static String e(String str) throws MalformedURLException { return a(new URL(str)); } private static boolean a(URL url, URL url2) { return a(url).equalsIgnoreCase(a(url2)); } public static boolean b(String str, String str2) throws MalformedURLException { return a(new URL(str), new URL(str2)); } public static boolean f(String str) { if (TextUtils.isEmpty(str)) { return false; } if (str.toLowerCase().startsWith("http://") || str.toLowerCase().startsWith("https://")) { return true; } return false; } public static boolean g(String str) { if (TextUtils.isEmpty(str)) { return false; } return str.toLowerCase().endsWith(".gif"); } public static boolean h(String str) { if (TextUtils.isEmpty(str)) { return false; } if (!str.toLowerCase().startsWith("http://") && !str.toLowerCase().startsWith("https://") && !str.toLowerCase().startsWith("file://")) { str = "http://".concat(String.valueOf(str)); } if (c(str).isEmpty() || c(str).equals("")) { return false; } return IURLUtil.isValidUrl(str); } public static String c(String str, String str2) { String[] split = str.substring(str.indexOf("?") + 1).split("&"); for (String str3 : split) { if (str3.contains(str2)) { return str3.replace(str2 + SimpleComparison.EQUAL_TO_OPERATION, ""); } } return ""; } public static boolean d(String str) { int indexOf = str.indexOf(58); String str2 = str; boolean z = true; for (int i = 0; i < indexOf; i++) { char charAt = str2.charAt(i); if (!Character.isLetter(charAt)) { break; } z &= Character.isLowerCase(charAt); if (i == indexOf - 1 && !z) { str2 = str2.substring(0, indexOf).toLowerCase() + str2.substring(indexOf); } } if (!str2.startsWith("http://") && !str2.startsWith("https://") && (str2.startsWith("http:") || str2.startsWith("https:"))) { if (str2.startsWith("http:/") || str2.startsWith("https:/")) { str2 = str2.replaceFirst("/", "//"); } else { str2 = str2.replaceFirst(Constants.COLON_SEPARATOR, "://"); } } String trim = str2.trim(); return !TextUtils.isEmpty(trim) && !Patterns.WEB_URL.matcher(trim).matches() && !f7420a.matcher(trim).matches(); } }