package ῲ.ᨨ.ⁱ;

import android.text.SpannableStringBuilder;
import java.util.Locale;
import ῲ.ᨨ.ⁱ.C1814;

/* renamed from: ῲ.ᨨ.ⁱ.K  reason: contains not printable characters */
/* compiled from: BidiFormatter */
public final class C1812 {

    /* renamed from: ඓ  reason: contains not printable characters */
    public static final String f6178 = Character.toString(8206);

    /* renamed from: ⁱ  reason: contains not printable characters */
    public static final C1812 f6179 = new C1812(false, 2, f6181);

    /* renamed from: 㴹  reason: contains not printable characters */
    public static final String f6180 = Character.toString(8207);

    /* renamed from: 㸾  reason: contains not printable characters */
    public static final AbstractC1808 f6181 = C1814.f6192;

    /* renamed from: 㿎  reason: contains not printable characters */
    public static final C1812 f6182 = new C1812(true, 2, f6181);

    /* renamed from: ʬ  reason: contains not printable characters */
    public final AbstractC1808 f6183;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final int f6184;

    /* renamed from: K  reason: contains not printable characters */
    public final boolean f6185;

    /* renamed from: ῲ.ᨨ.ⁱ.K$K  reason: contains not printable characters */
    /* compiled from: BidiFormatter */
    public static class C1813 {

        /* renamed from: 㴹  reason: contains not printable characters */
        public static final byte[] f6186 = new byte[1792];

        /* renamed from: ʬ  reason: contains not printable characters */
        public final int f6187;

        /* renamed from: ඓ  reason: contains not printable characters */
        public char f6188;

        /* renamed from: ῲ  reason: contains not printable characters */
        public final boolean f6189;

        /* renamed from: K  reason: contains not printable characters */
        public final CharSequence f6190;

        /* renamed from: 㸾  reason: contains not printable characters */
        public int f6191;

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

        public C1813(CharSequence charSequence, boolean z) {
            this.f6190 = charSequence;
            this.f6189 = z;
            this.f6187 = charSequence.length();
        }

        /* JADX WARNING: Code restructure failed: missing block: B:27:0x0082, code lost:
            r5.f6191 = r0;
            r5.f6188 = '>';
         */
        /* renamed from: K  reason: contains not printable characters */
        public byte m4702() {
            char c;
            char charAt;
            this.f6188 = this.f6190.charAt(this.f6191 - 1);
            if (Character.isLowSurrogate(this.f6188)) {
                int codePointBefore = Character.codePointBefore(this.f6190, this.f6191);
                this.f6191 -= Character.charCount(codePointBefore);
                return Character.getDirectionality(codePointBefore);
            }
            this.f6191--;
            char c2 = this.f6188;
            byte directionality = c2 < 1792 ? f6186[c2] : Character.getDirectionality(c2);
            if (!this.f6189) {
                return directionality;
            }
            char c3 = this.f6188;
            if (c3 == '>') {
                int i = this.f6191;
                while (true) {
                    int i2 = this.f6191;
                    if (i2 <= 0) {
                        break;
                    }
                    CharSequence charSequence = this.f6190;
                    int i3 = i2 - 1;
                    this.f6191 = i3;
                    this.f6188 = charSequence.charAt(i3);
                    char c4 = this.f6188;
                    if (c4 == '<') {
                        break;
                    } else if (c4 == '>') {
                        break;
                    } else if (c4 == '\"' || c4 == '\'') {
                        char c5 = this.f6188;
                        do {
                            int i4 = this.f6191;
                            if (i4 <= 0) {
                                break;
                            }
                            CharSequence charSequence2 = this.f6190;
                            int i5 = i4 - 1;
                            this.f6191 = i5;
                            charAt = charSequence2.charAt(i5);
                            this.f6188 = charAt;
                        } while (charAt != c5);
                    }
                }
            } else if (c3 != ';') {
                return directionality;
            } else {
                int i6 = this.f6191;
                do {
                    int i7 = this.f6191;
                    if (i7 <= 0) {
                        break;
                    }
                    CharSequence charSequence3 = this.f6190;
                    int i8 = i7 - 1;
                    this.f6191 = i8;
                    this.f6188 = charSequence3.charAt(i8);
                    c = this.f6188;
                    if (c == '&') {
                    }
                } while (c != ';');
                this.f6191 = i6;
                this.f6188 = ';';
                return 13;
            }
            return 12;
        }
    }

    public C1812(boolean z, int i, AbstractC1808 r3) {
        this.f6185 = z;
        this.f6184 = i;
        this.f6183 = r3;
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public static int m4697(CharSequence charSequence) {
        C1813 k = new C1813(charSequence, false);
        k.f6191 = k.f6187;
        int i = 0;
        int i2 = 0;
        while (k.f6191 > 0) {
            byte r3 = k.m4702();
            if (r3 != 0) {
                if (r3 == 1 || r3 == 2) {
                    if (i != 0) {
                        if (i2 != 0) {
                        }
                        i2 = i;
                    }
                } else if (r3 != 9) {
                    switch (r3) {
                        case 14:
                        case 15:
                            if (i2 == i) {
                                break;
                            }
                            i--;
                            break;
                        case 16:
                        case 17:
                            if (i2 == i) {
                                break;
                            }
                            i--;
                            break;
                        case 18:
                            i++;
                            break;
                        default:
                            if (i2 != 0) {
                                break;
                            }
                            i2 = i;
                            break;
                    }
                } else {
                    continue;
                }
                return 1;
            } else if (i != 0) {
                if (i2 != 0) {
                }
                i2 = i;
            }
            return -1;
        }
        return 0;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static C1812 m4699() {
        boolean r0 = m4700(Locale.getDefault());
        AbstractC1808 r1 = f6181;
        if (r1 == f6181) {
            return r0 ? f6182 : f6179;
        }
        return new C1812(r0, 2, r1);
    }

    /* renamed from: K  reason: contains not printable characters */
    public CharSequence m4701(CharSequence charSequence, AbstractC1808 r9, boolean z) {
        String str;
        if (charSequence == null) {
            return null;
        }
        boolean r92 = ((C1814.AbstractC1819) r9).m4710(charSequence, 0, charSequence.length());
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
        String str2 = "";
        if (((this.f6184 & 2) != 0) && z) {
            boolean r2 = ((C1814.AbstractC1819) (r92 ? C1814.f6193 : C1814.f6194)).m4710(charSequence, 0, charSequence.length());
            if (this.f6185 || (!r2 && m4698(charSequence) != 1)) {
                str = (!this.f6185 || (r2 && m4698(charSequence) != -1)) ? str2 : f6180;
            } else {
                str = f6178;
            }
            spannableStringBuilder.append((CharSequence) str);
        }
        if (r92 != this.f6185) {
            spannableStringBuilder.append(r92 ? (char) 8235 : 8234);
            spannableStringBuilder.append(charSequence);
            spannableStringBuilder.append((char) 8236);
        } else {
            spannableStringBuilder.append(charSequence);
        }
        if (z) {
            boolean r93 = ((C1814.AbstractC1819) (r92 ? C1814.f6193 : C1814.f6194)).m4710(charSequence, 0, charSequence.length());
            if (!this.f6185 && (r93 || m4697(charSequence) == 1)) {
                str2 = f6178;
            } else if (this.f6185 && (!r93 || m4697(charSequence) == -1)) {
                str2 = f6180;
            }
            spannableStringBuilder.append((CharSequence) str2);
        }
        return spannableStringBuilder;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static boolean m4700(Locale locale) {
        return C1809.m4692(locale) == 1;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:62:0x00ff, code lost:
        return 0;
     */
    /* renamed from: K  reason: contains not printable characters */
    public static int m4698(CharSequence charSequence) {
        byte b;
        char charAt;
        char charAt2;
        C1813 k = new C1813(charSequence, false);
        k.f6191 = 0;
        int i = 0;
        int i2 = 0;
        int i3 = 0;
        while (true) {
            int i4 = k.f6191;
            if (i4 < k.f6187 && i == 0) {
                k.f6188 = k.f6190.charAt(i4);
                if (Character.isHighSurrogate(k.f6188)) {
                    int codePointAt = Character.codePointAt(k.f6190, k.f6191);
                    k.f6191 = Character.charCount(codePointAt) + k.f6191;
                    b = Character.getDirectionality(codePointAt);
                } else {
                    k.f6191++;
                    char c = k.f6188;
                    b = c < 1792 ? C1813.f6186[c] : Character.getDirectionality(c);
                    if (k.f6189) {
                        char c2 = k.f6188;
                        if (c2 == '<') {
                            int i5 = k.f6191;
                            while (true) {
                                int i6 = k.f6191;
                                if (i6 < k.f6187) {
                                    CharSequence charSequence2 = k.f6190;
                                    k.f6191 = i6 + 1;
                                    k.f6188 = charSequence2.charAt(i6);
                                    char c3 = k.f6188;
                                    if (c3 != '>') {
                                        if (c3 == '\"' || c3 == '\'') {
                                            char c4 = k.f6188;
                                            do {
                                                int i7 = k.f6191;
                                                if (i7 < k.f6187) {
                                                    CharSequence charSequence3 = k.f6190;
                                                    k.f6191 = i7 + 1;
                                                    charAt2 = charSequence3.charAt(i7);
                                                    k.f6188 = charAt2;
                                                }
                                            } while (charAt2 != c4);
                                        }
                                    }
                                } else {
                                    k.f6191 = i5;
                                    k.f6188 = '<';
                                    b = 13;
                                }
                            }
                        } else if (c2 == '&') {
                            do {
                                int i8 = k.f6191;
                                if (i8 < k.f6187) {
                                    CharSequence charSequence4 = k.f6190;
                                    k.f6191 = i8 + 1;
                                    charAt = charSequence4.charAt(i8);
                                    k.f6188 = charAt;
                                }
                            } while (charAt != ';');
                        }
                        b = 12;
                    }
                }
                if (b != 0) {
                    if (b == 1 || b == 2) {
                        if (i3 == 0) {
                        }
                    } else if (b != 9) {
                        switch (b) {
                            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;
            } else if (i != 0) {
                if (i2 != 0) {
                    return i2;
                }
                while (k.f6191 > 0) {
                    switch (k.m4702()) {
                        case 14:
                        case 15:
                            if (i == i3) {
                                return -1;
                            }
                            break;
                        case 16:
                        case 17:
                            if (i == i3) {
                                break;
                            }
                            break;
                        case 18:
                            i3++;
                            continue;
                    }
                    i3--;
                }
            }
        }
        return 1;
    }
}
