74 lines
2.2 KiB
Java
74 lines
2.2 KiB
Java
package com.google.common.escape;
|
|
|
|
import com.google.common.base.Preconditions;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class CharEscaperBuilder {
|
|
private int max = -1;
|
|
private final Map<Character, String> map = new HashMap();
|
|
|
|
/* loaded from: classes2.dex */
|
|
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
|
|
public char[] escape(char c) {
|
|
if (c < this.replaceLength) {
|
|
return this.replacements[c];
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public final CharEscaperBuilder addEscape(char c, String str) {
|
|
this.map.put(Character.valueOf(c), Preconditions.checkNotNull(str));
|
|
if (c > this.max) {
|
|
this.max = c;
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public final CharEscaperBuilder addEscapes(char[] cArr, String str) {
|
|
Preconditions.checkNotNull(str);
|
|
for (char c : cArr) {
|
|
addEscape(c, str);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public final 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 final Escaper toEscaper() {
|
|
return new CharArrayDecorator(toArray());
|
|
}
|
|
}
|