54 lines
2.2 KiB
Java
54 lines
2.2 KiB
Java
package androidx.core.net;
|
|
|
|
import android.net.Uri;
|
|
import androidx.annotation.NonNull;
|
|
import c.d.b.a.a;
|
|
import com.adjust.sdk.Constants;
|
|
import com.discord.widgets.chat.input.MentionUtilsKt;
|
|
public final class UriCompat {
|
|
private UriCompat() {
|
|
}
|
|
|
|
@NonNull
|
|
public static String toSafeString(@NonNull Uri uri) {
|
|
String scheme = uri.getScheme();
|
|
String schemeSpecificPart = uri.getSchemeSpecificPart();
|
|
if (scheme != null) {
|
|
if (scheme.equalsIgnoreCase("tel") || scheme.equalsIgnoreCase("sip") || scheme.equalsIgnoreCase("sms") || scheme.equalsIgnoreCase("smsto") || scheme.equalsIgnoreCase("mailto") || scheme.equalsIgnoreCase("nfc")) {
|
|
StringBuilder sb = new StringBuilder(64);
|
|
sb.append(scheme);
|
|
sb.append(MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR);
|
|
if (schemeSpecificPart != null) {
|
|
for (int i = 0; i < schemeSpecificPart.length(); i++) {
|
|
char charAt = schemeSpecificPart.charAt(i);
|
|
if (charAt == '-' || charAt == '@' || charAt == '.') {
|
|
sb.append(charAt);
|
|
} else {
|
|
sb.append('x');
|
|
}
|
|
}
|
|
}
|
|
return sb.toString();
|
|
} else if (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase(Constants.SCHEME) || scheme.equalsIgnoreCase("ftp") || scheme.equalsIgnoreCase("rtsp")) {
|
|
StringBuilder L = a.L("//");
|
|
String str = "";
|
|
L.append(uri.getHost() != null ? uri.getHost() : str);
|
|
if (uri.getPort() != -1) {
|
|
StringBuilder L2 = a.L(":");
|
|
L2.append(uri.getPort());
|
|
str = L2.toString();
|
|
}
|
|
schemeSpecificPart = a.D(L, str, "/...");
|
|
}
|
|
}
|
|
StringBuilder sb2 = new StringBuilder(64);
|
|
if (scheme != null) {
|
|
sb2.append(scheme);
|
|
sb2.append(MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR);
|
|
}
|
|
if (schemeSpecificPart != null) {
|
|
sb2.append(schemeSpecificPart);
|
|
}
|
|
return sb2.toString();
|
|
}
|
|
}
|