/*
 * Decompiled with CFR 0.152.
 */
import java.util.Vector;

public final class bk {
    static {
        new ek(32);
    }

    public static void a(ht ht2, w w2, String string, int n, int n2, int[] nArray, lc lc2) {
        bk.a(ht2, w2, string, 0, string.length(), n, n2, nArray, lc2);
    }

    public static int[] a(ht ht2, w w2, String[] stringArray, int n, int n2, lc lc2) {
        return bk.a(ht2, w2, stringArray, n, n2, lc2, new int[2]);
    }

    public static boolean a(ht ht2, int n, int n2, int n3, int n4) {
        int n5 = ht2.f();
        return n5 < n2 + n4 && n2 < n5 + ht2.d() && (n2 = ht2.g()) < n + n3 && n < n2 + ht2.h();
    }

    private static boolean a(char c) {
        return c == ' ';
    }

    public static String[] a(w w2, String string, int n, int n2, lc lc2) {
        if (lc2 != null) {
            return bk.a(w2, string, n, n2, lc2, false);
        }
        return new String[0];
    }

    public static String a(String string, w w2, int n, String string2) {
        if (w2.a(string) > n) {
            n = bk.b(string, w2, n, string2);
            return string.substring(0, n) + string2;
        }
        return string;
    }

    public static void a(ht ht2, int n, int n2, String string, int n3) {
        if (n3 > 0) {
            w w2 = ht2.f();
            if (w2.a(string) > n3) {
                n3 = bk.b(string, w2, n3, "...");
                int n4 = n + w2.a(string, 0, n3);
                ht2.a(string, 0, n3, n, n2);
                ht2.a("...", n4, n2);
                return;
            }
            ht2.a(string, n, n2);
        }
    }

    public static int[] a(ht ht2, w w2, String[] stringArray, int n, int n2, lc lc2, int[] nArray) {
        int n3 = 0;
        int n4 = 0;
        int n5 = 0;
        while (n3 < stringArray.length) {
            bk.a(ht2, w2, stringArray[n3], n, n2 + n4, nArray, lc2);
            ++n3;
            n5 = Math.max(n5, nArray[0]);
            n4 += nArray[1];
        }
        nArray[0] = n5;
        nArray[1] = n4;
        return nArray;
    }

    public static String[] a(w object, String string, int n, int n2, lc lc2, boolean bl2) {
        if (object != null && string != null && n > 0 && string.length() != 0) {
            int n3;
            int n4;
            int n5;
            int n6;
            int n7;
            Vector<Object> vector;
            int[] nArray;
            block21: {
                if (n2 <= 0) {
                    n2 = Integer.MAX_VALUE;
                }
                nArray = bk.a((w)object, string, lc2);
                if (!bl2 && nArray[0] <= n) {
                    return new String[]{string};
                }
                vector = new Vector<Object>();
                n7 = string.length();
                for (n6 = 1; n6 < string.length(); ++n6) {
                    if (!oz.a(string.charAt(n6 - 1), string.charAt(n6))) {
                        continue;
                    }
                    break block21;
                }
                n6 = -1;
            }
            if (bl2 || n6 >= 0 && vector.size() <= n2) {
                n5 = 1;
                int n8 = 0;
                while (n5 < nArray.length) {
                    boolean bl3 = false;
                    n4 = 0;
                    while ((n3 = n5) < nArray.length && (n4 + nArray[n3] <= n || bl2 && string.charAt(n3 - 1) == '\n' || n3 - 1 == n8)) {
                        if (!bl2 || string.charAt(n3 - 1) != '\n') {
                            n5 = n3 + 1;
                            n4 += nArray[n3];
                            continue;
                        }
                        ++n3;
                        bl3 = true;
                        break;
                    }
                    n4 = bl3 && n5 > n8 ? n5 - 1 : n5;
                    String string2 = string.substring(n8, n4);
                    for (n5 = n3 - 1; n5 < n7 && bk.a(string.charAt(n5)); ++n5) {
                    }
                    if (!bl3 && n5 == n3 - 1 && n3 < nArray.length) {
                        block22: {
                            if (!oz.a(string2.charAt(string2.length() - 1), string.charAt(n5))) {
                                for (n4 = string2.length() - 1; n4 >= 1; --n4) {
                                    if (!oz.a(string2.charAt(n4 - 1), string2.charAt(n4))) {
                                        continue;
                                    }
                                    break block22;
                                }
                                n4 = -1;
                            } else {
                                n4 = string2.length();
                            }
                        }
                        if (n4 >= 0) {
                            n5 = n8 + n4;
                            string2 = string.substring(n8, n5);
                        }
                    }
                    while (true) {
                        n8 = n5;
                        if (string2.length() <= 0 || !bk.a(string2.charAt(string2.length() - 1))) break;
                        string2 = string2.substring(0, string2.length() - 1);
                        n5 = n8;
                    }
                    vector.addElement(string2);
                    n5 = n8 + 1;
                }
            }
            if (!(bl2 || n6 >= 0 && vector.size() <= n2)) {
                n5 = 1;
                n3 = 0;
                vector.removeAllElements();
                while (n5 < nArray.length) {
                    n4 = 0;
                    while ((n2 = n5) < nArray.length && (n4 + nArray[n2] <= n || n2 - 1 == n3)) {
                        n4 += nArray[n2];
                        n5 = n2 + 1;
                    }
                    n5 = n2 - 1;
                    object = string.substring(n3, n5);
                    while ((n3 = n5) < n7 && bk.a(string.charAt(n3))) {
                        n5 = n3 + 1;
                    }
                    n5 = n3 + 1;
                    vector.addElement(object);
                }
            }
            Object[] objectArray = new String[vector.size()];
            vector.copyInto(objectArray);
            return objectArray;
        }
        return new String[0];
    }

    private static int b(String string, w w2, int n, String string2) {
        int n2 = n - w2.a(string2);
        if (n2 > 0) {
            int n3 = string.length();
            n = w2.a(string);
            if (n > n2) {
                if (n > n2 * 2) {
                    for (n = 0; n < n3; ++n) {
                        int n4 = w2.a(string, 0, n);
                        if (n4 < n2) {
                            continue;
                        }
                        if (n4 != n2) {
                            --n;
                        }
                        break;
                    }
                } else {
                    for (n = n3; n > 0 && w2.a(string, 0, n) > n2; --n) {
                    }
                }
            } else {
                n = n3;
            }
        } else {
            n = 0;
        }
        while (n > 0 && ed.a(string.charAt(n - 1))) {
            --n;
        }
        return n;
    }

    public static int[] a(w w2, String string, lc lc2) {
        int n = 0;
        int n2 = string.length();
        int[] nArray = new int[n2 + 1];
        for (int i = 1; i <= n2; ++i) {
            char c = string.charAt(i - 1);
            if (c == '\u0001') {
                if (i < n2) {
                    nArray[i] = lc2 == null ? w2.a(string.substring(i - 1, i + 1)) : lc2.c(string.charAt(i));
                    n += nArray[i];
                    nArray[++i] = 0;
                    continue;
                }
                nArray[i] = 0;
                continue;
            }
            n += w2.d(c);
        }
        nArray[0] = n;
        return nArray;
    }

    public static void a(ht ht2, w w2, String string, int n, int n2, int n3, int n4, int[] nArray, lc lc2) {
        int n5;
        int n6 = n + n2;
        int n7 = 0;
        n2 = w2.l();
        if (ht2 != null) {
            ht2.a(w2);
        }
        while ((n5 = string.indexOf(1, n)) >= 0 && n5 < n6) {
            String string2 = string.substring(n, n5);
            if (ht2 != null) {
                ht2.a(string2, n3 + n7, n4);
            }
            n7 += w2.a(string2);
            if (n5 + 1 < n6 && lc2.a((char)(n = (int)string.charAt(n5 + 1)))) {
                n2 = Math.max(n2, lc2.b((char)n));
                if (ht2 != null) {
                    lc2.a((char)n, ht2, n3 + n7, n4 + (n2 - lc2.b((char)n)) / 2);
                }
                n7 += lc2.c((char)n);
            }
            n = n5 + 2;
        }
        if (n < n6) {
            if (n != 0 || n6 != string.length()) {
                string = string.substring(n, n6);
            }
            if (ht2 != null) {
                ht2.a(string, n3 + n7, n4);
            }
            if (nArray != null) {
                n7 += w2.a(string);
            }
        }
        if (nArray != null) {
            nArray[0] = n7;
            nArray[1] = n2;
        }
    }
}

