mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-12-06 12:29:32 +01:00
101 lines
3.2 KiB
Java
101 lines
3.2 KiB
Java
package com.google.common.escape;
|
|
|
|
import com.google.common.annotations.GwtCompatible;
|
|
import com.google.common.base.Preconditions;
|
|
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import kotlin.jvm.internal.CharCompanionObject;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@GwtCompatible
|
|
/* loaded from: classes8.dex */
|
|
public final class Escapers {
|
|
private static final Escaper NULL_ESCAPER = new CharEscaper() { // from class: com.google.common.escape.Escapers.1
|
|
@Override // com.google.common.escape.CharEscaper, com.google.common.escape.Escaper
|
|
public String escape(String str) {
|
|
return (String) Preconditions.checkNotNull(str);
|
|
}
|
|
|
|
@Override // com.google.common.escape.CharEscaper
|
|
public char[] escape(char c) {
|
|
return null;
|
|
}
|
|
};
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public static final class Builder {
|
|
private final Map<Character, String> replacementMap;
|
|
private char safeMax;
|
|
private char safeMin;
|
|
private String unsafeReplacement;
|
|
|
|
private Builder() {
|
|
this.replacementMap = new HashMap();
|
|
this.safeMin = (char) 0;
|
|
this.safeMax = CharCompanionObject.MAX_VALUE;
|
|
this.unsafeReplacement = null;
|
|
}
|
|
|
|
@CanIgnoreReturnValue
|
|
public Builder addEscape(char c, String str) {
|
|
Preconditions.checkNotNull(str);
|
|
this.replacementMap.put(Character.valueOf(c), str);
|
|
return this;
|
|
}
|
|
|
|
public Escaper build() {
|
|
return new ArrayBasedCharEscaper(this.replacementMap, this.safeMin, this.safeMax) { // from class: com.google.common.escape.Escapers.Builder.1
|
|
private final char[] replacementChars;
|
|
|
|
{
|
|
this.replacementChars = Builder.this.unsafeReplacement != null ? Builder.this.unsafeReplacement.toCharArray() : null;
|
|
}
|
|
|
|
@Override // com.google.common.escape.ArrayBasedCharEscaper
|
|
public char[] escapeUnsafe(char c) {
|
|
return this.replacementChars;
|
|
}
|
|
};
|
|
}
|
|
|
|
@CanIgnoreReturnValue
|
|
public Builder setSafeRange(char c, char c2) {
|
|
this.safeMin = c;
|
|
this.safeMax = c2;
|
|
return this;
|
|
}
|
|
|
|
@CanIgnoreReturnValue
|
|
public Builder setUnsafeReplacement(String str) {
|
|
this.unsafeReplacement = str;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
private Escapers() {
|
|
}
|
|
|
|
public static Builder builder() {
|
|
return new Builder();
|
|
}
|
|
|
|
public static String computeReplacement(CharEscaper charEscaper, char c) {
|
|
return stringOrNull(charEscaper.escape(c));
|
|
}
|
|
|
|
public static Escaper nullEscaper() {
|
|
return NULL_ESCAPER;
|
|
}
|
|
|
|
private static String stringOrNull(char[] cArr) {
|
|
if (cArr == null) {
|
|
return null;
|
|
}
|
|
return new String(cArr);
|
|
}
|
|
|
|
public static String computeReplacement(UnicodeEscaper unicodeEscaper, int i) {
|
|
return stringOrNull(unicodeEscaper.escape(i));
|
|
}
|
|
}
|