Rabbit-R1/android (non root)/java/sources/com/google/common/escape/CharEscaperBuilder.java
2024-05-21 17:08:36 -04:00

75 lines
2.3 KiB
Java

package com.google.common.escape;
import com.google.common.base.Preconditions;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.CheckForNull;
@ElementTypesAreNonnullByDefault
/* loaded from: classes3.dex */
public final class CharEscaperBuilder {
private int max = -1;
private final Map<Character, String> map = new HashMap();
/* loaded from: classes3.dex */
private static class CharArrayDecorator extends CharEscaper {
private final int replaceLength;
private final char[][] replacements;
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;
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.escape.CharEscaper
@CheckForNull
public char[] escape(char c) {
if (c < this.replaceLength) {
return this.replacements[c];
}
return null;
}
}
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;
}
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());
}
}