package X6FRs_4.IMuAHx_6.Nm6q_10;

import android.text.SpannableStringBuilder;
import com.wang.avi.BuildConfig;
import java.util.Locale;
/* compiled from: BidiFormatter.java */
/* loaded from: classes.dex */
public final class KQgRr5e_0 {

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final int f471KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final Mqv2r_3 f472KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final boolean f473KQgRr5e_0;

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public static final Mqv2r_3 f469QxJ9d_1 = X6FRs_4.PGPF6hQ_2;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public static final String f468KQgRr5e_0 = Character.toString(8206);

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public static final String f470QxJ9d_1 = Character.toString(8207);
    public static final KQgRr5e_0 KQgRr5e_0 = new KQgRr5e_0(false, 2, f469QxJ9d_1);
    public static final KQgRr5e_0 QxJ9d_1 = new KQgRr5e_0(true, 2, f469QxJ9d_1);

    public KQgRr5e_0(boolean z, int i, Mqv2r_3 mqv2r_3) {
        this.f473KQgRr5e_0 = z;
        this.f471KQgRr5e_0 = i;
        this.f472KQgRr5e_0 = mqv2r_3;
    }

    public static KQgRr5e_0 KQgRr5e_0() {
        return new C0041KQgRr5e_0().KQgRr5e_0();
    }

    public final String QxJ9d_1(CharSequence charSequence, Mqv2r_3 mqv2r_3) {
        boolean KQgRr5e_02 = mqv2r_3.KQgRr5e_0(charSequence, 0, charSequence.length());
        if (this.f473KQgRr5e_0 || !(KQgRr5e_02 || KQgRr5e_0(charSequence) == 1)) {
            return this.f473KQgRr5e_0 ? (!KQgRr5e_02 || KQgRr5e_0(charSequence) == -1) ? f470QxJ9d_1 : BuildConfig.FLAVOR : BuildConfig.FLAVOR;
        }
        return f468KQgRr5e_0;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public boolean m312KQgRr5e_0() {
        return (this.f471KQgRr5e_0 & 2) != 0;
    }

    /* compiled from: BidiFormatter.java */
    /* renamed from: X6FRs_4.IMuAHx_6.Nm6q_10.KQgRr5e_0$KQgRr5e_0  reason: collision with other inner class name */
    /* loaded from: classes.dex */
    public static final class C0041KQgRr5e_0 {
        public int KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public Mqv2r_3 f474KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public boolean f475KQgRr5e_0;

        public C0041KQgRr5e_0() {
            m313KQgRr5e_0(KQgRr5e_0.KQgRr5e_0(Locale.getDefault()));
        }

        /* renamed from: KQgRr5e_0  reason: collision with other method in class */
        public final void m313KQgRr5e_0(boolean z) {
            this.f475KQgRr5e_0 = z;
            this.f474KQgRr5e_0 = KQgRr5e_0.f469QxJ9d_1;
            this.KQgRr5e_0 = 2;
        }

        public static KQgRr5e_0 KQgRr5e_0(boolean z) {
            return z ? KQgRr5e_0.QxJ9d_1 : KQgRr5e_0.KQgRr5e_0;
        }

        public KQgRr5e_0 KQgRr5e_0() {
            if (this.KQgRr5e_0 == 2 && this.f474KQgRr5e_0 == KQgRr5e_0.f469QxJ9d_1) {
                return KQgRr5e_0(this.f475KQgRr5e_0);
            }
            return new KQgRr5e_0(this.f475KQgRr5e_0, this.KQgRr5e_0, this.f474KQgRr5e_0);
        }
    }

    /* compiled from: BidiFormatter.java */
    /* loaded from: classes.dex */
    public static class QxJ9d_1 {
        public static final byte[] KQgRr5e_0 = new byte[1792];

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public char f476KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public final int f477KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public final CharSequence f478KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public final boolean f479KQgRr5e_0;
        public int QxJ9d_1;

        static {
            for (int i = 0; i < 1792; i++) {
                KQgRr5e_0[i] = Character.getDirectionality(i);
            }
        }

        public QxJ9d_1(CharSequence charSequence, boolean z) {
            this.f478KQgRr5e_0 = charSequence;
            this.f479KQgRr5e_0 = z;
            this.f477KQgRr5e_0 = charSequence.length();
        }

        public final byte IFxWkV_5() {
            char charAt;
            int i = this.QxJ9d_1;
            while (true) {
                int i2 = this.QxJ9d_1;
                if (i2 < this.f477KQgRr5e_0) {
                    CharSequence charSequence = this.f478KQgRr5e_0;
                    this.QxJ9d_1 = i2 + 1;
                    char charAt2 = charSequence.charAt(i2);
                    this.f476KQgRr5e_0 = charAt2;
                    if (charAt2 == '>') {
                        return (byte) 12;
                    }
                    if (charAt2 == '\"' || charAt2 == '\'') {
                        char c = this.f476KQgRr5e_0;
                        do {
                            int i3 = this.QxJ9d_1;
                            if (i3 < this.f477KQgRr5e_0) {
                                CharSequence charSequence2 = this.f478KQgRr5e_0;
                                this.QxJ9d_1 = i3 + 1;
                                charAt = charSequence2.charAt(i3);
                                this.f476KQgRr5e_0 = charAt;
                            }
                        } while (charAt != c);
                    }
                } else {
                    this.QxJ9d_1 = i;
                    this.f476KQgRr5e_0 = '<';
                    return (byte) 13;
                }
            }
        }

        /* renamed from: KQgRr5e_0  reason: collision with other method in class */
        public int m314KQgRr5e_0() {
            this.QxJ9d_1 = 0;
            int i = 0;
            int i2 = 0;
            int i3 = 0;
            while (this.QxJ9d_1 < this.f477KQgRr5e_0 && i == 0) {
                byte QxJ9d_1 = QxJ9d_1();
                if (QxJ9d_1 != 0) {
                    if (QxJ9d_1 == 1 || QxJ9d_1 == 2) {
                        if (i3 == 0) {
                            return 1;
                        }
                    } else if (QxJ9d_1 != 9) {
                        switch (QxJ9d_1) {
                            case 14:
                            case 15:
                                i3++;
                                i2 = -1;
                                break;
                            case 16:
                            case 17:
                                i3++;
                                i2 = 1;
                                break;
                            case 18:
                                i3--;
                                i2 = 0;
                                break;
                        }
                    }
                } else if (i3 == 0) {
                    return -1;
                }
                i = i3;
            }
            if (i == 0) {
                return 0;
            }
            if (i2 != 0) {
                return i2;
            }
            while (this.QxJ9d_1 > 0) {
                switch (KQgRr5e_0()) {
                    case 14:
                    case 15:
                        if (i == i3) {
                            return -1;
                        }
                        break;
                    case 16:
                    case 17:
                        if (i == i3) {
                            return 1;
                        }
                        break;
                    case 18:
                        i3++;
                        continue;
                }
                i3--;
            }
            return 0;
        }

        public final byte Mqv2r_3() {
            char charAt;
            do {
                int i = this.QxJ9d_1;
                if (i >= this.f477KQgRr5e_0) {
                    return (byte) 12;
                }
                CharSequence charSequence = this.f478KQgRr5e_0;
                this.QxJ9d_1 = i + 1;
                charAt = charSequence.charAt(i);
                this.f476KQgRr5e_0 = charAt;
            } while (charAt != ';');
            return (byte) 12;
        }

        public final byte PGPF6hQ_2() {
            char charAt;
            int i = this.QxJ9d_1;
            do {
                int i2 = this.QxJ9d_1;
                if (i2 <= 0) {
                    break;
                }
                CharSequence charSequence = this.f478KQgRr5e_0;
                int i3 = i2 - 1;
                this.QxJ9d_1 = i3;
                charAt = charSequence.charAt(i3);
                this.f476KQgRr5e_0 = charAt;
                if (charAt == '&') {
                    return (byte) 12;
                }
            } while (charAt != ';');
            this.QxJ9d_1 = i;
            this.f476KQgRr5e_0 = ';';
            return (byte) 13;
        }

        /* renamed from: QxJ9d_1  reason: collision with other method in class */
        public int m315QxJ9d_1() {
            this.QxJ9d_1 = this.f477KQgRr5e_0;
            int i = 0;
            int i2 = 0;
            while (this.QxJ9d_1 > 0) {
                byte KQgRr5e_02 = KQgRr5e_0();
                if (KQgRr5e_02 != 0) {
                    if (KQgRr5e_02 == 1 || KQgRr5e_02 == 2) {
                        if (i == 0) {
                            return 1;
                        }
                        if (i2 == 0) {
                            i2 = i;
                        }
                    } else if (KQgRr5e_02 != 9) {
                        switch (KQgRr5e_02) {
                            case 14:
                            case 15:
                                if (i2 == i) {
                                    return -1;
                                }
                                i--;
                                break;
                            case 16:
                            case 17:
                                if (i2 == i) {
                                    return 1;
                                }
                                i--;
                                break;
                            case 18:
                                i++;
                                break;
                            default:
                                if (i2 != 0) {
                                    break;
                                } else {
                                    i2 = i;
                                    break;
                                }
                        }
                    } else {
                        continue;
                    }
                } else if (i == 0) {
                    return -1;
                } else {
                    if (i2 == 0) {
                        i2 = i;
                    }
                }
            }
            return 0;
        }

        public final byte X6FRs_4() {
            char charAt;
            int i = this.QxJ9d_1;
            while (true) {
                int i2 = this.QxJ9d_1;
                if (i2 <= 0) {
                    break;
                }
                CharSequence charSequence = this.f478KQgRr5e_0;
                int i3 = i2 - 1;
                this.QxJ9d_1 = i3;
                char charAt2 = charSequence.charAt(i3);
                this.f476KQgRr5e_0 = charAt2;
                if (charAt2 == '<') {
                    return (byte) 12;
                }
                if (charAt2 == '>') {
                    break;
                } else if (charAt2 == '\"' || charAt2 == '\'') {
                    char c = this.f476KQgRr5e_0;
                    do {
                        int i4 = this.QxJ9d_1;
                        if (i4 > 0) {
                            CharSequence charSequence2 = this.f478KQgRr5e_0;
                            int i5 = i4 - 1;
                            this.QxJ9d_1 = i5;
                            charAt = charSequence2.charAt(i5);
                            this.f476KQgRr5e_0 = charAt;
                        }
                    } while (charAt != c);
                }
            }
            this.QxJ9d_1 = i;
            this.f476KQgRr5e_0 = '>';
            return (byte) 13;
        }

        public byte QxJ9d_1() {
            char charAt = this.f478KQgRr5e_0.charAt(this.QxJ9d_1);
            this.f476KQgRr5e_0 = charAt;
            if (Character.isHighSurrogate(charAt)) {
                int codePointAt = Character.codePointAt(this.f478KQgRr5e_0, this.QxJ9d_1);
                this.QxJ9d_1 += Character.charCount(codePointAt);
                return Character.getDirectionality(codePointAt);
            }
            this.QxJ9d_1++;
            byte KQgRr5e_02 = KQgRr5e_0(this.f476KQgRr5e_0);
            if (this.f479KQgRr5e_0) {
                char c = this.f476KQgRr5e_0;
                if (c == '<') {
                    return IFxWkV_5();
                }
                return c == '&' ? Mqv2r_3() : KQgRr5e_02;
            }
            return KQgRr5e_02;
        }

        public static byte KQgRr5e_0(char c) {
            return c < 1792 ? KQgRr5e_0[c] : Character.getDirectionality(c);
        }

        public byte KQgRr5e_0() {
            char charAt = this.f478KQgRr5e_0.charAt(this.QxJ9d_1 - 1);
            this.f476KQgRr5e_0 = charAt;
            if (Character.isLowSurrogate(charAt)) {
                int codePointBefore = Character.codePointBefore(this.f478KQgRr5e_0, this.QxJ9d_1);
                this.QxJ9d_1 -= Character.charCount(codePointBefore);
                return Character.getDirectionality(codePointBefore);
            }
            this.QxJ9d_1--;
            byte KQgRr5e_02 = KQgRr5e_0(this.f476KQgRr5e_0);
            if (this.f479KQgRr5e_0) {
                char c = this.f476KQgRr5e_0;
                if (c == '>') {
                    return X6FRs_4();
                }
                return c == ';' ? PGPF6hQ_2() : KQgRr5e_02;
            }
            return KQgRr5e_02;
        }
    }

    public final String KQgRr5e_0(CharSequence charSequence, Mqv2r_3 mqv2r_3) {
        boolean KQgRr5e_02 = mqv2r_3.KQgRr5e_0(charSequence, 0, charSequence.length());
        if (this.f473KQgRr5e_0 || !(KQgRr5e_02 || QxJ9d_1(charSequence) == 1)) {
            return this.f473KQgRr5e_0 ? (!KQgRr5e_02 || QxJ9d_1(charSequence) == -1) ? f470QxJ9d_1 : BuildConfig.FLAVOR : BuildConfig.FLAVOR;
        }
        return f468KQgRr5e_0;
    }

    public static int QxJ9d_1(CharSequence charSequence) {
        return new QxJ9d_1(charSequence, false).m315QxJ9d_1();
    }

    public CharSequence KQgRr5e_0(CharSequence charSequence, Mqv2r_3 mqv2r_3, boolean z) {
        if (charSequence == null) {
            return null;
        }
        boolean KQgRr5e_02 = mqv2r_3.KQgRr5e_0(charSequence, 0, charSequence.length());
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
        if (m312KQgRr5e_0() && z) {
            spannableStringBuilder.append((CharSequence) QxJ9d_1(charSequence, KQgRr5e_02 ? X6FRs_4.QxJ9d_1 : X6FRs_4.KQgRr5e_0));
        }
        if (KQgRr5e_02 != this.f473KQgRr5e_0) {
            spannableStringBuilder.append(KQgRr5e_02 ? (char) 8235 : (char) 8234);
            spannableStringBuilder.append(charSequence);
            spannableStringBuilder.append((char) 8236);
        } else {
            spannableStringBuilder.append(charSequence);
        }
        if (z) {
            spannableStringBuilder.append((CharSequence) KQgRr5e_0(charSequence, KQgRr5e_02 ? X6FRs_4.QxJ9d_1 : X6FRs_4.KQgRr5e_0));
        }
        return spannableStringBuilder;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public CharSequence m311KQgRr5e_0(CharSequence charSequence) {
        return KQgRr5e_0(charSequence, this.f472KQgRr5e_0, true);
    }

    public static boolean KQgRr5e_0(Locale locale) {
        return IFxWkV_5.QxJ9d_1(locale) == 1;
    }

    public static int KQgRr5e_0(CharSequence charSequence) {
        return new QxJ9d_1(charSequence, false).m314KQgRr5e_0();
    }
}
