mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-12-06 12:29:32 +01:00
77 lines
2.5 KiB
Java
77 lines
2.5 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;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@GwtCompatible
|
|
/* loaded from: classes8.dex */
|
|
public final class CharEscaperBuilder {
|
|
private int max = -1;
|
|
private final Map<Character, String> map = new HashMap();
|
|
|
|
@CanIgnoreReturnValue
|
|
public CharEscaperBuilder addEscape(char c, String str) {
|
|
this.map.put(Character.valueOf(c), (String) Preconditions.checkNotNull(str));
|
|
if (c > this.max) {
|
|
this.max = c;
|
|
}
|
|
return this;
|
|
}
|
|
|
|
@CanIgnoreReturnValue
|
|
public CharEscaperBuilder addEscapes(char[] cArr, String str) {
|
|
Preconditions.checkNotNull(str);
|
|
for (char c : cArr) {
|
|
addEscape(c, str);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public char[][] toArray() {
|
|
char[][] cArr = new char[this.max + 1][];
|
|
for (Map.Entry<Character, String> entry : this.map.entrySet()) {
|
|
cArr[entry.getKey().charValue()] = entry.getValue().toCharArray();
|
|
}
|
|
return cArr;
|
|
}
|
|
|
|
public Escaper toEscaper() {
|
|
return new CharArrayDecorator(toArray());
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public static class CharArrayDecorator extends CharEscaper {
|
|
private final int replaceLength;
|
|
private final char[][] replacements;
|
|
|
|
public CharArrayDecorator(char[][] cArr) {
|
|
this.replacements = cArr;
|
|
this.replaceLength = cArr.length;
|
|
}
|
|
|
|
@Override // com.google.common.escape.CharEscaper, com.google.common.escape.Escaper
|
|
public String escape(String str) {
|
|
int length = str.length();
|
|
for (int i = 0; i < length; i++) {
|
|
char charAt = str.charAt(i);
|
|
char[][] cArr = this.replacements;
|
|
if (charAt < cArr.length && cArr[charAt] != null) {
|
|
return escapeSlow(str, i);
|
|
}
|
|
}
|
|
return str;
|
|
}
|
|
|
|
@Override // com.google.common.escape.CharEscaper
|
|
public char[] escape(char c) {
|
|
if (c < this.replaceLength) {
|
|
return this.replacements[c];
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|