Rabbit-R1/switch port/java/sources/com/google/common/base/Splitter.java
2024-05-21 17:08:36 -04:00

335 lines
14 KiB
Java

package com.google.common.base;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import javax.annotation.CheckForNull;
@ElementTypesAreNonnullByDefault
/* loaded from: classes2.dex */
public final class Splitter {
private final int limit;
private final boolean omitEmptyStrings;
private final Strategy strategy;
private final CharMatcher trimmer;
/* JADX INFO: Access modifiers changed from: private */
/* loaded from: classes2.dex */
public interface Strategy {
Iterator<String> iterator(Splitter splitter, CharSequence charSequence);
}
private Splitter(Strategy strategy) {
this(strategy, false, CharMatcher.none(), Integer.MAX_VALUE);
}
private Splitter(Strategy strategy, boolean z, CharMatcher charMatcher, int i) {
this.strategy = strategy;
this.omitEmptyStrings = z;
this.trimmer = charMatcher;
this.limit = i;
}
public static Splitter on(char c) {
return on(CharMatcher.is(c));
}
public static Splitter on(final CharMatcher charMatcher) {
Preconditions.checkNotNull(charMatcher);
return new Splitter(new Strategy() { // from class: com.google.common.base.Splitter.1
@Override // com.google.common.base.Splitter.Strategy
public SplittingIterator iterator(Splitter splitter, CharSequence charSequence) {
return new SplittingIterator(splitter, charSequence) { // from class: com.google.common.base.Splitter.1.1
@Override // com.google.common.base.Splitter.SplittingIterator
int separatorEnd(int i) {
return i + 1;
}
@Override // com.google.common.base.Splitter.SplittingIterator
int separatorStart(int i) {
return CharMatcher.this.indexIn(this.toSplit, i);
}
};
}
});
}
public static Splitter on(final String str) {
Preconditions.checkArgument(str.length() != 0, "The separator may not be the empty string.");
if (str.length() == 1) {
return on(str.charAt(0));
}
return new Splitter(new Strategy() { // from class: com.google.common.base.Splitter.2
@Override // com.google.common.base.Splitter.Strategy
public SplittingIterator iterator(Splitter splitter, CharSequence charSequence) {
return new SplittingIterator(splitter, charSequence) { // from class: com.google.common.base.Splitter.2.1
/* JADX WARN: Code restructure failed: missing block: B:9:0x0026, code lost:
r6 = r6 + 1;
*/
@Override // com.google.common.base.Splitter.SplittingIterator
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public int separatorStart(int r6) {
/*
r5 = this;
com.google.common.base.Splitter$2 r0 = com.google.common.base.Splitter.AnonymousClass2.this
java.lang.String r0 = r1
int r0 = r0.length()
java.lang.CharSequence r1 = r5.toSplit
int r1 = r1.length()
int r1 = r1 - r0
Lf:
if (r6 > r1) goto L2d
r2 = 0
L12:
if (r2 >= r0) goto L2c
java.lang.CharSequence r3 = r5.toSplit
int r4 = r2 + r6
char r3 = r3.charAt(r4)
com.google.common.base.Splitter$2 r4 = com.google.common.base.Splitter.AnonymousClass2.this
java.lang.String r4 = r1
char r4 = r4.charAt(r2)
if (r3 == r4) goto L29
int r6 = r6 + 1
goto Lf
L29:
int r2 = r2 + 1
goto L12
L2c:
return r6
L2d:
r5 = -1
return r5
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.common.base.Splitter.AnonymousClass2.AnonymousClass1.separatorStart(int):int");
}
@Override // com.google.common.base.Splitter.SplittingIterator
public int separatorEnd(int i) {
return i + str.length();
}
};
}
});
}
public static Splitter on(Pattern pattern) {
return on(new JdkPattern(pattern));
}
private static Splitter on(final CommonPattern commonPattern) {
Preconditions.checkArgument(!commonPattern.matcher("").matches(), "The pattern may not match the empty string: %s", commonPattern);
return new Splitter(new Strategy() { // from class: com.google.common.base.Splitter.3
@Override // com.google.common.base.Splitter.Strategy
public SplittingIterator iterator(Splitter splitter, CharSequence charSequence) {
final CommonMatcher matcher = CommonPattern.this.matcher(charSequence);
return new SplittingIterator(this, splitter, charSequence) { // from class: com.google.common.base.Splitter.3.1
@Override // com.google.common.base.Splitter.SplittingIterator
public int separatorStart(int i) {
if (matcher.find(i)) {
return matcher.start();
}
return -1;
}
@Override // com.google.common.base.Splitter.SplittingIterator
public int separatorEnd(int i) {
return matcher.end();
}
};
}
});
}
public static Splitter onPattern(String str) {
return on(Platform.compilePattern(str));
}
public static Splitter fixedLength(final int i) {
Preconditions.checkArgument(i > 0, "The length may not be less than 1");
return new Splitter(new Strategy() { // from class: com.google.common.base.Splitter.4
@Override // com.google.common.base.Splitter.Strategy
public SplittingIterator iterator(Splitter splitter, CharSequence charSequence) {
return new SplittingIterator(splitter, charSequence) { // from class: com.google.common.base.Splitter.4.1
@Override // com.google.common.base.Splitter.SplittingIterator
public int separatorEnd(int i2) {
return i2;
}
@Override // com.google.common.base.Splitter.SplittingIterator
public int separatorStart(int i2) {
int i3 = i2 + i;
if (i3 < this.toSplit.length()) {
return i3;
}
return -1;
}
};
}
});
}
public Splitter omitEmptyStrings() {
return new Splitter(this.strategy, true, this.trimmer, this.limit);
}
public Splitter limit(int i) {
Preconditions.checkArgument(i > 0, "must be greater than zero: %s", i);
return new Splitter(this.strategy, this.omitEmptyStrings, this.trimmer, i);
}
public Splitter trimResults() {
return trimResults(CharMatcher.whitespace());
}
public Splitter trimResults(CharMatcher charMatcher) {
Preconditions.checkNotNull(charMatcher);
return new Splitter(this.strategy, this.omitEmptyStrings, charMatcher, this.limit);
}
public Iterable<String> split(final CharSequence charSequence) {
Preconditions.checkNotNull(charSequence);
return new Iterable<String>() { // from class: com.google.common.base.Splitter.5
@Override // java.lang.Iterable
public Iterator<String> iterator() {
return Splitter.this.splittingIterator(charSequence);
}
public String toString() {
return Joiner.on(", ").appendTo(new StringBuilder().append('['), (Iterable<? extends Object>) this).append(']').toString();
}
};
}
/* JADX INFO: Access modifiers changed from: private */
public Iterator<String> splittingIterator(CharSequence charSequence) {
return this.strategy.iterator(this, charSequence);
}
public List<String> splitToList(CharSequence charSequence) {
Preconditions.checkNotNull(charSequence);
Iterator<String> splittingIterator = splittingIterator(charSequence);
ArrayList arrayList = new ArrayList();
while (splittingIterator.hasNext()) {
arrayList.add(splittingIterator.next());
}
return Collections.unmodifiableList(arrayList);
}
public MapSplitter withKeyValueSeparator(String str) {
return withKeyValueSeparator(on(str));
}
public MapSplitter withKeyValueSeparator(char c) {
return withKeyValueSeparator(on(c));
}
public MapSplitter withKeyValueSeparator(Splitter splitter) {
return new MapSplitter(splitter);
}
/* loaded from: classes2.dex */
public static final class MapSplitter {
private static final String INVALID_ENTRY_MESSAGE = "Chunk [%s] is not a valid entry";
private final Splitter entrySplitter;
private final Splitter outerSplitter;
private MapSplitter(Splitter splitter, Splitter splitter2) {
this.outerSplitter = splitter;
this.entrySplitter = (Splitter) Preconditions.checkNotNull(splitter2);
}
public Map<String, String> split(CharSequence charSequence) {
LinkedHashMap linkedHashMap = new LinkedHashMap();
for (String str : this.outerSplitter.split(charSequence)) {
Iterator splittingIterator = this.entrySplitter.splittingIterator(str);
Preconditions.checkArgument(splittingIterator.hasNext(), INVALID_ENTRY_MESSAGE, str);
String str2 = (String) splittingIterator.next();
Preconditions.checkArgument(!linkedHashMap.containsKey(str2), "Duplicate key [%s] found.", str2);
Preconditions.checkArgument(splittingIterator.hasNext(), INVALID_ENTRY_MESSAGE, str);
linkedHashMap.put(str2, (String) splittingIterator.next());
Preconditions.checkArgument(!splittingIterator.hasNext(), INVALID_ENTRY_MESSAGE, str);
}
return Collections.unmodifiableMap(linkedHashMap);
}
}
/* loaded from: classes2.dex */
private static abstract class SplittingIterator extends AbstractIterator<String> {
int limit;
int offset = 0;
final boolean omitEmptyStrings;
final CharSequence toSplit;
final CharMatcher trimmer;
abstract int separatorEnd(int i);
abstract int separatorStart(int i);
protected SplittingIterator(Splitter splitter, CharSequence charSequence) {
this.trimmer = splitter.trimmer;
this.omitEmptyStrings = splitter.omitEmptyStrings;
this.limit = splitter.limit;
this.toSplit = charSequence;
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.base.AbstractIterator
@CheckForNull
public String computeNext() {
int separatorStart;
int i = this.offset;
while (true) {
int i2 = this.offset;
if (i2 != -1) {
separatorStart = separatorStart(i2);
if (separatorStart == -1) {
separatorStart = this.toSplit.length();
this.offset = -1;
} else {
this.offset = separatorEnd(separatorStart);
}
int i3 = this.offset;
if (i3 == i) {
int i4 = i3 + 1;
this.offset = i4;
if (i4 > this.toSplit.length()) {
this.offset = -1;
}
} else {
while (i < separatorStart && this.trimmer.matches(this.toSplit.charAt(i))) {
i++;
}
while (separatorStart > i && this.trimmer.matches(this.toSplit.charAt(separatorStart - 1))) {
separatorStart--;
}
if (!this.omitEmptyStrings || i != separatorStart) {
break;
}
i = this.offset;
}
} else {
return endOfData();
}
}
int i5 = this.limit;
if (i5 == 1) {
separatorStart = this.toSplit.length();
this.offset = -1;
while (separatorStart > i && this.trimmer.matches(this.toSplit.charAt(separatorStart - 1))) {
separatorStart--;
}
} else {
this.limit = i5 - 1;
}
return this.toSplit.subSequence(i, separatorStart).toString();
}
}
}