- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
177 lines
6.1 KiB
Java
177 lines
6.1 KiB
Java
package androidx.core.text;
|
|
|
|
import java.nio.CharBuffer;
|
|
import java.util.Locale;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class TextDirectionHeuristicsCompat {
|
|
public static final TextDirectionHeuristicCompat ANYRTL_LTR;
|
|
public static final TextDirectionHeuristicCompat FIRSTSTRONG_LTR;
|
|
public static final TextDirectionHeuristicCompat FIRSTSTRONG_RTL;
|
|
public static final TextDirectionHeuristicCompat LOCALE;
|
|
public static final TextDirectionHeuristicCompat LTR = new TextDirectionHeuristicInternal(null, false);
|
|
public static final TextDirectionHeuristicCompat RTL = new TextDirectionHeuristicInternal(null, true);
|
|
private static final int STATE_FALSE = 1;
|
|
private static final int STATE_TRUE = 0;
|
|
private static final int STATE_UNKNOWN = 2;
|
|
|
|
public interface TextDirectionAlgorithm {
|
|
int checkRtl(CharSequence charSequence, int i, int i2);
|
|
}
|
|
|
|
public static int isRtlText(int i) {
|
|
if (i != 0) {
|
|
return (i == 1 || i == 2) ? 0 : 2;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
public static int isRtlTextOrFormat(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;
|
|
}
|
|
|
|
static {
|
|
FirstStrong firstStrong = FirstStrong.INSTANCE;
|
|
FIRSTSTRONG_LTR = new TextDirectionHeuristicInternal(firstStrong, false);
|
|
FIRSTSTRONG_RTL = new TextDirectionHeuristicInternal(firstStrong, true);
|
|
ANYRTL_LTR = new TextDirectionHeuristicInternal(AnyStrong.INSTANCE_RTL, false);
|
|
LOCALE = TextDirectionHeuristicLocale.INSTANCE;
|
|
}
|
|
|
|
public static abstract class TextDirectionHeuristicImpl implements TextDirectionHeuristicCompat {
|
|
private final TextDirectionAlgorithm mAlgorithm;
|
|
|
|
public abstract boolean defaultIsRtl();
|
|
|
|
public TextDirectionHeuristicImpl(TextDirectionAlgorithm textDirectionAlgorithm) {
|
|
this.mAlgorithm = textDirectionAlgorithm;
|
|
}
|
|
|
|
@Override // androidx.core.text.TextDirectionHeuristicCompat
|
|
public boolean isRtl(char[] cArr, int i, int i2) {
|
|
return isRtl(CharBuffer.wrap(cArr), i, i2);
|
|
}
|
|
|
|
@Override // androidx.core.text.TextDirectionHeuristicCompat
|
|
public boolean isRtl(CharSequence charSequence, int i, int i2) {
|
|
if (charSequence == null || i < 0 || i2 < 0 || charSequence.length() - i2 < i) {
|
|
throw new IllegalArgumentException();
|
|
}
|
|
if (this.mAlgorithm == null) {
|
|
return defaultIsRtl();
|
|
}
|
|
return doCheck(charSequence, i, i2);
|
|
}
|
|
|
|
private boolean doCheck(CharSequence charSequence, int i, int i2) {
|
|
int checkRtl = this.mAlgorithm.checkRtl(charSequence, i, i2);
|
|
if (checkRtl == 0) {
|
|
return true;
|
|
}
|
|
if (checkRtl != 1) {
|
|
return defaultIsRtl();
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static class TextDirectionHeuristicInternal extends TextDirectionHeuristicImpl {
|
|
private final boolean mDefaultIsRtl;
|
|
|
|
@Override // androidx.core.text.TextDirectionHeuristicsCompat.TextDirectionHeuristicImpl
|
|
public boolean defaultIsRtl() {
|
|
return this.mDefaultIsRtl;
|
|
}
|
|
|
|
public TextDirectionHeuristicInternal(TextDirectionAlgorithm textDirectionAlgorithm, boolean z) {
|
|
super(textDirectionAlgorithm);
|
|
this.mDefaultIsRtl = z;
|
|
}
|
|
}
|
|
|
|
public static class FirstStrong implements TextDirectionAlgorithm {
|
|
static final FirstStrong INSTANCE = new FirstStrong();
|
|
|
|
@Override // androidx.core.text.TextDirectionHeuristicsCompat.TextDirectionAlgorithm
|
|
public int checkRtl(CharSequence charSequence, int i, int i2) {
|
|
int i3 = i2 + i;
|
|
int i4 = 2;
|
|
while (i < i3 && i4 == 2) {
|
|
i4 = TextDirectionHeuristicsCompat.isRtlTextOrFormat(Character.getDirectionality(charSequence.charAt(i)));
|
|
i++;
|
|
}
|
|
return i4;
|
|
}
|
|
|
|
private FirstStrong() {
|
|
}
|
|
}
|
|
|
|
public static class AnyStrong implements TextDirectionAlgorithm {
|
|
static final AnyStrong INSTANCE_RTL = new AnyStrong(true);
|
|
private final boolean mLookForRtl;
|
|
|
|
@Override // androidx.core.text.TextDirectionHeuristicsCompat.TextDirectionAlgorithm
|
|
public int checkRtl(CharSequence charSequence, int i, int i2) {
|
|
int i3 = i2 + i;
|
|
boolean z = false;
|
|
while (i < i3) {
|
|
int isRtlText = TextDirectionHeuristicsCompat.isRtlText(Character.getDirectionality(charSequence.charAt(i)));
|
|
if (isRtlText != 0) {
|
|
if (isRtlText != 1) {
|
|
continue;
|
|
i++;
|
|
z = z;
|
|
} else if (!this.mLookForRtl) {
|
|
return 1;
|
|
}
|
|
} else if (this.mLookForRtl) {
|
|
return 0;
|
|
}
|
|
z = true;
|
|
i++;
|
|
z = z;
|
|
}
|
|
if (z) {
|
|
return this.mLookForRtl ? 1 : 0;
|
|
}
|
|
return 2;
|
|
}
|
|
|
|
private AnyStrong(boolean z) {
|
|
this.mLookForRtl = z;
|
|
}
|
|
}
|
|
|
|
public static class TextDirectionHeuristicLocale extends TextDirectionHeuristicImpl {
|
|
static final TextDirectionHeuristicLocale INSTANCE = new TextDirectionHeuristicLocale();
|
|
|
|
public TextDirectionHeuristicLocale() {
|
|
super(null);
|
|
}
|
|
|
|
@Override // androidx.core.text.TextDirectionHeuristicsCompat.TextDirectionHeuristicImpl
|
|
public boolean defaultIsRtl() {
|
|
return TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == 1;
|
|
}
|
|
}
|
|
|
|
private TextDirectionHeuristicsCompat() {
|
|
}
|
|
}
|