mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-15 18:37:17 +01:00
163 lines
6 KiB
Java
163 lines
6 KiB
Java
package com.google.common.base;
|
|
|
|
import androidx.compose.animation.core.ArcMode$$ExternalSyntheticOutline0;
|
|
import androidx.core.os.ParcelCompat$$ExternalSyntheticOutline0;
|
|
import com.google.common.annotations.GwtCompatible;
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
import defpackage.a$$ExternalSyntheticOutline0;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
import kotlinx.serialization.json.internal.AbstractJsonLexerKt;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@GwtCompatible
|
|
/* loaded from: classes8.dex */
|
|
public final class Strings {
|
|
private Strings() {
|
|
}
|
|
|
|
public static String commonPrefix(CharSequence charSequence, CharSequence charSequence2) {
|
|
Preconditions.checkNotNull(charSequence);
|
|
Preconditions.checkNotNull(charSequence2);
|
|
int min = Math.min(charSequence.length(), charSequence2.length());
|
|
int i = 0;
|
|
while (i < min && charSequence.charAt(i) == charSequence2.charAt(i)) {
|
|
i++;
|
|
}
|
|
int i2 = i - 1;
|
|
if (validSurrogatePairAt(charSequence, i2) || validSurrogatePairAt(charSequence2, i2)) {
|
|
i--;
|
|
}
|
|
return charSequence.subSequence(0, i).toString();
|
|
}
|
|
|
|
public static String commonSuffix(CharSequence charSequence, CharSequence charSequence2) {
|
|
Preconditions.checkNotNull(charSequence);
|
|
Preconditions.checkNotNull(charSequence2);
|
|
int min = Math.min(charSequence.length(), charSequence2.length());
|
|
int i = 0;
|
|
while (i < min && charSequence.charAt((charSequence.length() - i) - 1) == charSequence2.charAt((charSequence2.length() - i) - 1)) {
|
|
i++;
|
|
}
|
|
if (validSurrogatePairAt(charSequence, (charSequence.length() - i) - 1) || validSurrogatePairAt(charSequence2, (charSequence2.length() - i) - 1)) {
|
|
i--;
|
|
}
|
|
return charSequence.subSequence(charSequence.length() - i, charSequence.length()).toString();
|
|
}
|
|
|
|
public static String emptyToNull(String str) {
|
|
return Platform.emptyToNull(str);
|
|
}
|
|
|
|
public static boolean isNullOrEmpty(String str) {
|
|
return Platform.stringIsNullOrEmpty(str);
|
|
}
|
|
|
|
public static String lenientFormat(String str, Object... objArr) {
|
|
int indexOf;
|
|
String valueOf = String.valueOf(str);
|
|
int i = 0;
|
|
if (objArr == null) {
|
|
objArr = new Object[]{"(Object[])null"};
|
|
} else {
|
|
for (int i2 = 0; i2 < objArr.length; i2++) {
|
|
objArr[i2] = lenientToString(objArr[i2]);
|
|
}
|
|
}
|
|
StringBuilder sb = new StringBuilder((objArr.length * 16) + valueOf.length());
|
|
int i3 = 0;
|
|
while (i < objArr.length && (indexOf = valueOf.indexOf("%s", i3)) != -1) {
|
|
sb.append((CharSequence) valueOf, i3, indexOf);
|
|
sb.append(objArr[i]);
|
|
i3 = indexOf + 2;
|
|
i++;
|
|
}
|
|
sb.append((CharSequence) valueOf, i3, valueOf.length());
|
|
if (i < objArr.length) {
|
|
sb.append(" [");
|
|
sb.append(objArr[i]);
|
|
for (int i4 = i + 1; i4 < objArr.length; i4++) {
|
|
sb.append(", ");
|
|
sb.append(objArr[i4]);
|
|
}
|
|
sb.append(AbstractJsonLexerKt.END_LIST);
|
|
}
|
|
return sb.toString();
|
|
}
|
|
|
|
private static String lenientToString(Object obj) {
|
|
if (obj == null) {
|
|
return "null";
|
|
}
|
|
try {
|
|
return obj.toString();
|
|
} catch (Exception e) {
|
|
String str = obj.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(obj));
|
|
Logger.getLogger("com.google.common.base.Strings").log(Level.WARNING, "Exception during lenientFormat for ".concat(str), (Throwable) e);
|
|
StringBuilder m2m = a$$ExternalSyntheticOutline0.m2m("<", str, " threw ");
|
|
m2m.append(e.getClass().getName());
|
|
m2m.append(">");
|
|
return m2m.toString();
|
|
}
|
|
}
|
|
|
|
public static String nullToEmpty(String str) {
|
|
return Platform.nullToEmpty(str);
|
|
}
|
|
|
|
public static String padEnd(String str, int i, char c) {
|
|
Preconditions.checkNotNull(str);
|
|
if (str.length() >= i) {
|
|
return str;
|
|
}
|
|
StringBuilder m = ParcelCompat$$ExternalSyntheticOutline0.m(i, str);
|
|
for (int length = str.length(); length < i; length++) {
|
|
m.append(c);
|
|
}
|
|
return m.toString();
|
|
}
|
|
|
|
public static String padStart(String str, int i, char c) {
|
|
Preconditions.checkNotNull(str);
|
|
if (str.length() >= i) {
|
|
return str;
|
|
}
|
|
StringBuilder sb = new StringBuilder(i);
|
|
for (int length = str.length(); length < i; length++) {
|
|
sb.append(c);
|
|
}
|
|
sb.append(str);
|
|
return sb.toString();
|
|
}
|
|
|
|
public static String repeat(String str, int i) {
|
|
Preconditions.checkNotNull(str);
|
|
if (i <= 1) {
|
|
Preconditions.checkArgument(i >= 0, "invalid count: %s", i);
|
|
return i == 0 ? "" : str;
|
|
}
|
|
int length = str.length();
|
|
long j = length * i;
|
|
int i2 = (int) j;
|
|
if (i2 != j) {
|
|
Verify$$ExternalSyntheticBUOutline0.m(ArcMode$$ExternalSyntheticOutline0.m(j, "Required array size too large: "));
|
|
return null;
|
|
}
|
|
char[] cArr = new char[i2];
|
|
str.getChars(0, length, cArr, 0);
|
|
while (true) {
|
|
int i3 = i2 - length;
|
|
if (length >= i3) {
|
|
System.arraycopy(cArr, 0, cArr, length, i3);
|
|
return new String(cArr);
|
|
}
|
|
System.arraycopy(cArr, 0, cArr, length, length);
|
|
length <<= 1;
|
|
}
|
|
}
|
|
|
|
@VisibleForTesting
|
|
public static boolean validSurrogatePairAt(CharSequence charSequence, int i) {
|
|
return i >= 0 && i <= charSequence.length() + (-2) && Character.isHighSurrogate(charSequence.charAt(i)) && Character.isLowSurrogate(charSequence.charAt(i + 1));
|
|
}
|
|
}
|