161 lines
4.9 KiB
Java
161 lines
4.9 KiB
Java
package androidx.core.text;
|
|
|
|
import java.util.Locale;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class TextDirectionHeuristicsCompat {
|
|
public static final TextDirectionHeuristicCompat a;
|
|
public static final TextDirectionHeuristicCompat b;
|
|
|
|
private static class AnyStrong implements TextDirectionAlgorithm {
|
|
static final AnyStrong b = new AnyStrong(true);
|
|
private final boolean a;
|
|
|
|
static {
|
|
new AnyStrong(false);
|
|
}
|
|
|
|
private AnyStrong(boolean z) {
|
|
this.a = z;
|
|
}
|
|
|
|
@Override // androidx.core.text.TextDirectionHeuristicsCompat.TextDirectionAlgorithm
|
|
public int a(CharSequence charSequence, int i, int i2) {
|
|
int i3 = i2 + i;
|
|
boolean z = false;
|
|
while (i < i3) {
|
|
int a = TextDirectionHeuristicsCompat.a(Character.getDirectionality(charSequence.charAt(i)));
|
|
if (a != 0) {
|
|
if (a != 1) {
|
|
continue;
|
|
i++;
|
|
} else if (!this.a) {
|
|
return 1;
|
|
}
|
|
} else if (this.a) {
|
|
return 0;
|
|
}
|
|
z = true;
|
|
i++;
|
|
}
|
|
if (z) {
|
|
return this.a ? 1 : 0;
|
|
}
|
|
return 2;
|
|
}
|
|
}
|
|
|
|
private static class FirstStrong implements TextDirectionAlgorithm {
|
|
static final FirstStrong a = new FirstStrong();
|
|
|
|
private FirstStrong() {
|
|
}
|
|
|
|
@Override // androidx.core.text.TextDirectionHeuristicsCompat.TextDirectionAlgorithm
|
|
public int a(CharSequence charSequence, int i, int i2) {
|
|
int i3 = i2 + i;
|
|
int i4 = 2;
|
|
while (i < i3 && i4 == 2) {
|
|
i4 = TextDirectionHeuristicsCompat.b(Character.getDirectionality(charSequence.charAt(i)));
|
|
i++;
|
|
}
|
|
return i4;
|
|
}
|
|
}
|
|
|
|
private interface TextDirectionAlgorithm {
|
|
int a(CharSequence charSequence, int i, int i2);
|
|
}
|
|
|
|
private static abstract class TextDirectionHeuristicImpl implements TextDirectionHeuristicCompat {
|
|
private final TextDirectionAlgorithm a;
|
|
|
|
TextDirectionHeuristicImpl(TextDirectionAlgorithm textDirectionAlgorithm) {
|
|
this.a = textDirectionAlgorithm;
|
|
}
|
|
|
|
private boolean b(CharSequence charSequence, int i, int i2) {
|
|
int a = this.a.a(charSequence, i, i2);
|
|
if (a == 0) {
|
|
return true;
|
|
}
|
|
if (a != 1) {
|
|
return a();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
protected abstract boolean a();
|
|
|
|
@Override // androidx.core.text.TextDirectionHeuristicCompat
|
|
public boolean a(CharSequence charSequence, int i, int i2) {
|
|
if (charSequence == null || i < 0 || i2 < 0 || charSequence.length() - i2 < i) {
|
|
throw new IllegalArgumentException();
|
|
}
|
|
return this.a == null ? a() : b(charSequence, i, i2);
|
|
}
|
|
}
|
|
|
|
private static class TextDirectionHeuristicInternal extends TextDirectionHeuristicImpl {
|
|
private final boolean b;
|
|
|
|
TextDirectionHeuristicInternal(TextDirectionAlgorithm textDirectionAlgorithm, boolean z) {
|
|
super(textDirectionAlgorithm);
|
|
this.b = z;
|
|
}
|
|
|
|
@Override // androidx.core.text.TextDirectionHeuristicsCompat.TextDirectionHeuristicImpl
|
|
protected boolean a() {
|
|
return this.b;
|
|
}
|
|
}
|
|
|
|
private static class TextDirectionHeuristicLocale extends TextDirectionHeuristicImpl {
|
|
static final TextDirectionHeuristicLocale b = new TextDirectionHeuristicLocale();
|
|
|
|
TextDirectionHeuristicLocale() {
|
|
super(null);
|
|
}
|
|
|
|
@Override // androidx.core.text.TextDirectionHeuristicsCompat.TextDirectionHeuristicImpl
|
|
protected boolean a() {
|
|
return TextUtilsCompat.b(Locale.getDefault()) == 1;
|
|
}
|
|
}
|
|
|
|
static {
|
|
new TextDirectionHeuristicInternal(null, false);
|
|
new TextDirectionHeuristicInternal(null, true);
|
|
a = new TextDirectionHeuristicInternal(FirstStrong.a, false);
|
|
b = new TextDirectionHeuristicInternal(FirstStrong.a, true);
|
|
new TextDirectionHeuristicInternal(AnyStrong.b, false);
|
|
TextDirectionHeuristicLocale textDirectionHeuristicLocale = TextDirectionHeuristicLocale.b;
|
|
}
|
|
|
|
static int a(int i) {
|
|
if (i != 0) {
|
|
return (i == 1 || i == 2) ? 0 : 2;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static int b(int i) {
|
|
if (i != 0) {
|
|
if (i == 1 || i == 2) {
|
|
return 0;
|
|
}
|
|
switch (i) {
|
|
case 14:
|
|
case 15:
|
|
break;
|
|
case 16:
|
|
case 17:
|
|
return 0;
|
|
default:
|
|
return 2;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
}
|