package S4;

import a.AbstractC0872a;
import e4.C;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import x4.AbstractC3251q;
import x4.AbstractC3252r;
import x4.AbstractC3253s;

/* JADX INFO: loaded from: classes3.dex */
public abstract class q extends C {
    public static String p0(String str) {
        int length;
        Comparable comparable;
        kotlin.jvm.internal.o.h(str, "<this>");
        List listD0 = R4.n.d0(new H4.f(str, 4));
        ArrayList arrayList = new ArrayList();
        for (Object obj : listD0) {
            if (!p.Q0((String) obj)) {
                arrayList.add(obj);
            }
        }
        ArrayList arrayList2 = new ArrayList(AbstractC3253s.G(arrayList, 10));
        Iterator it = arrayList.iterator();
        while (true) {
            length = 0;
            if (!it.hasNext()) {
                break;
            }
            String str2 = (String) it.next();
            int length2 = str2.length();
            while (true) {
                if (length >= length2) {
                    length = -1;
                    break;
                }
                if (!AbstractC0872a.W(str2.charAt(length))) {
                    break;
                }
                length++;
            }
            if (length == -1) {
                length = str2.length();
            }
            arrayList2.add(Integer.valueOf(length));
        }
        Iterator it2 = arrayList2.iterator();
        if (it2.hasNext()) {
            comparable = (Comparable) it2.next();
            while (it2.hasNext()) {
                Comparable comparable2 = (Comparable) it2.next();
                if (comparable.compareTo(comparable2) > 0) {
                    comparable = comparable2;
                }
            }
        } else {
            comparable = null;
        }
        Integer num = (Integer) comparable;
        int iIntValue = num != null ? num.intValue() : 0;
        int length3 = str.length();
        listD0.size();
        int iA = AbstractC3252r.A(listD0);
        ArrayList arrayList3 = new ArrayList();
        for (Object obj2 : listD0) {
            int i6 = length + 1;
            if (length < 0) {
                AbstractC3252r.F();
                throw null;
            }
            String str3 = (String) obj2;
            String strG0 = ((length == 0 || length == iA) && p.Q0(str3)) ? null : p.G0(iIntValue, str3);
            if (strG0 != null) {
                arrayList3.add(strG0);
            }
            length = i6;
        }
        StringBuilder sb = new StringBuilder(length3);
        AbstractC3251q.l0(arrayList3, sb, null, 124);
        return sb.toString();
    }

    public static String q0(String str) {
        kotlin.jvm.internal.o.h(str, "<this>");
        if (p.Q0("|")) {
            throw new IllegalArgumentException("marginPrefix must be non-blank string.");
        }
        List listD0 = R4.n.d0(new H4.f(str, 4));
        int length = str.length();
        listD0.size();
        int iA = AbstractC3252r.A(listD0);
        ArrayList arrayList = new ArrayList();
        Iterator it = listD0.iterator();
        int i6 = 0;
        while (true) {
            String strSubstring = null;
            if (!it.hasNext()) {
                StringBuilder sb = new StringBuilder(length);
                AbstractC3251q.l0(arrayList, sb, null, 124);
                return sb.toString();
            }
            Object next = it.next();
            int i7 = i6 + 1;
            if (i6 < 0) {
                AbstractC3252r.F();
                throw null;
            }
            String str2 = (String) next;
            if ((i6 != 0 && i6 != iA) || !p.Q0(str2)) {
                int length2 = str2.length();
                int i8 = 0;
                while (true) {
                    if (i8 >= length2) {
                        i8 = -1;
                        break;
                    }
                    if (!AbstractC0872a.W(str2.charAt(i8))) {
                        break;
                    }
                    i8++;
                }
                if (i8 != -1 && w.z0(str2, "|", i8, false)) {
                    strSubstring = str2.substring("|".length() + i8);
                    kotlin.jvm.internal.o.g(strSubstring, "substring(...)");
                }
                if (strSubstring == null) {
                    strSubstring = str2;
                }
            }
            if (strSubstring != null) {
                arrayList.add(strSubstring);
            }
            i6 = i7;
        }
    }
}
