package com.applovin.impl; import android.text.TextUtils; import com.applovin.exoplayer2.common.base.Ascii; import com.facebook.internal.security.CertificateUtil; import com.mbridge.msdk.playercommon.exoplayer2.text.ttml.TtmlNode; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; /* loaded from: classes.dex */ final class ur { private static final Pattern c = Pattern.compile("\\[voice=\"([^\"]*)\"\\]"); private static final Pattern d = Pattern.compile("^((?:[0-9]*\\.)?[0-9]+)(px|em|%)$"); private final bh a = new bh(); private final StringBuilder b = new StringBuilder(); public List c(bh bhVar) { this.b.setLength(0); int d2 = bhVar.d(); e(bhVar); this.a.a(bhVar.c(), bhVar.d()); this.a.f(d2); ArrayList arrayList = new ArrayList(); while (true) { String d3 = d(this.a, this.b); if (d3 == null || !"{".equals(b(this.a, this.b))) { return arrayList; } vr vrVar = new vr(); a(vrVar, d3); String str = null; boolean z = false; while (!z) { int d4 = this.a.d(); String b = b(this.a, this.b); boolean z2 = b == null || "}".equals(b); if (!z2) { this.a.f(d4); a(this.a, vrVar, this.b); } str = b; z = z2; } if ("}".equals(str)) { arrayList.add(vrVar); } } } private static String c(bh bhVar, StringBuilder sb) { StringBuilder sb2 = new StringBuilder(); boolean z = false; while (!z) { int d2 = bhVar.d(); String b = b(bhVar, sb); if (b == null) { return null; } if (!"}".equals(b) && !";".equals(b)) { sb2.append(b); } else { bhVar.f(d2); z = true; } } return sb2.toString(); } private static String d(bh bhVar, StringBuilder sb) { f(bhVar); if (bhVar.a() < 5 || !"::cue".equals(bhVar.c(5))) { return null; } int d2 = bhVar.d(); String b = b(bhVar, sb); if (b == null) { return null; } if ("{".equals(b)) { bhVar.f(d2); return ""; } String d3 = "(".equals(b) ? d(bhVar) : null; if (")".equals(b(bhVar, sb))) { return d3; } return null; } public static void f(bh bhVar) { while (true) { for (boolean z = true; bhVar.a() > 0 && z; z = false) { if (!b(bhVar) && !a(bhVar)) { } } return; } } private static boolean b(bh bhVar) { char a = a(bhVar, bhVar.d()); if (a != '\t' && a != '\n' && a != '\f' && a != '\r' && a != ' ') { return false; } bhVar.g(1); return true; } public static void e(bh bhVar) { while (!TextUtils.isEmpty(bhVar.l())) { } } private static boolean a(bh bhVar) { int d2 = bhVar.d(); int e = bhVar.e(); byte[] c2 = bhVar.c(); int i = d2 + 2; if (i > e) { return false; } int i2 = d2 + 1; if (c2[d2] != 47 || c2[i2] != 42) { return false; } while (true) { int i3 = i + 1; if (i3 < e) { if (((char) c2[i]) == '*' && ((char) c2[i3]) == '/') { i += 2; e = i; } else { i = i3; } } else { bhVar.g(e - bhVar.d()); return true; } } } private static String d(bh bhVar) { int d2 = bhVar.d(); int e = bhVar.e(); boolean z = false; while (d2 < e && !z) { int i = d2 + 1; z = ((char) bhVar.c()[d2]) == ')'; d2 = i; } return bhVar.c((d2 - 1) - bhVar.d()).trim(); } public static String b(bh bhVar, StringBuilder sb) { f(bhVar); if (bhVar.a() == 0) { return null; } String a = a(bhVar, sb); if (!"".equals(a)) { return a; } return "" + ((char) bhVar.w()); } private static String a(bh bhVar, StringBuilder sb) { boolean z = false; sb.setLength(0); int d2 = bhVar.d(); int e = bhVar.e(); while (d2 < e && !z) { char c2 = (char) bhVar.c()[d2]; if ((c2 < 'A' || c2 > 'Z') && ((c2 < 'a' || c2 > 'z') && !((c2 >= '0' && c2 <= '9') || c2 == '#' || c2 == '-' || c2 == '.' || c2 == '_'))) { z = true; } else { d2++; sb.append(c2); } } bhVar.g(d2 - bhVar.d()); return sb.toString(); } private static void a(bh bhVar, vr vrVar, StringBuilder sb) { f(bhVar); String a = a(bhVar, sb); if (!"".equals(a) && CertificateUtil.DELIMITER.equals(b(bhVar, sb))) { f(bhVar); String c2 = c(bhVar, sb); if (c2 == null || "".equals(c2)) { return; } int d2 = bhVar.d(); String b = b(bhVar, sb); if (!";".equals(b)) { if (!"}".equals(b)) { return; } else { bhVar.f(d2); } } if ("color".equals(a)) { vrVar.b(s3.a(c2)); return; } if ("background-color".equals(a)) { vrVar.a(s3.a(c2)); return; } boolean z = true; if ("ruby-position".equals(a)) { if ("over".equals(c2)) { vrVar.d(1); return; } else { if ("under".equals(c2)) { vrVar.d(2); return; } return; } } if ("text-combine-upright".equals(a)) { if (!"all".equals(c2) && !c2.startsWith("digits")) { z = false; } vrVar.b(z); return; } if ("text-decoration".equals(a)) { if (TtmlNode.UNDERLINE.equals(c2)) { vrVar.d(true); return; } return; } if ("font-family".equals(a)) { vrVar.a(c2); return; } if ("font-weight".equals(a)) { if (TtmlNode.BOLD.equals(c2)) { vrVar.a(true); } } else if ("font-style".equals(a)) { if (TtmlNode.ITALIC.equals(c2)) { vrVar.c(true); } } else if ("font-size".equals(a)) { a(c2, vrVar); } } } private static char a(bh bhVar, int i) { return (char) bhVar.c()[i]; } private static void a(String str, vr vrVar) { Matcher matcher = d.matcher(Ascii.toLowerCase(str)); if (!matcher.matches()) { pc.d("WebvttCssParser", "Invalid font-size: '" + str + "'."); return; } String str2 = (String) b1.a((Object) matcher.group(2)); str2.hashCode(); switch (str2) { case "%": vrVar.c(3); break; case "em": vrVar.c(2); break; case "px": vrVar.c(1); break; default: throw new IllegalStateException(); } vrVar.a(Float.parseFloat((String) b1.a((Object) matcher.group(1)))); } private void a(vr vrVar, String str) { if ("".equals(str)) { return; } int indexOf = str.indexOf(91); if (indexOf != -1) { Matcher matcher = c.matcher(str.substring(indexOf)); if (matcher.matches()) { vrVar.d((String) b1.a((Object) matcher.group(1))); } str = str.substring(0, indexOf); } String[] a = xp.a(str, "\\."); String str2 = a[0]; int indexOf2 = str2.indexOf(35); if (indexOf2 != -1) { vrVar.c(str2.substring(0, indexOf2)); vrVar.b(str2.substring(indexOf2 + 1)); } else { vrVar.c(str2); } if (a.length > 1) { vrVar.a((String[]) xp.a(a, 1, a.length)); } } }