package o; import com.google.common.primitives.UnsignedBytes; import java.lang.reflect.Array; import java.nio.charset.Charset; import java.util.ArrayList; /* renamed from: o.mUD, reason: case insensitive filesystem */ /* loaded from: classes2.dex */ public class C16224mUD implements InterfaceC2154aYo { public final int d; public final int[] e; public C16224mUD(String str, Charset charset, int i) { int i2; this.d = i; C17668yld c17668yld = new C17668yld(str, charset, i); int i3 = 0; if (c17668yld.e.length == 1) { this.e = new int[str.length()]; while (i3 < this.e.length) { char charAt = str.charAt(i3); int[] iArr = this.e; if (charAt == i) { charAt = 1000; } iArr[i3] = charAt; i3++; } return; } int length = str.length(); RVV[][] rvvArr = (RVV[][]) Array.newInstance((Class) RVV.class, length + 1, c17668yld.e.length); e(str, c17668yld, rvvArr, 0, null, i); for (int i4 = 1; i4 <= length; i4++) { int i5 = 0; while (i5 < c17668yld.e.length) { RVV rvv = rvvArr[i4][i5]; if (rvv == null || i4 >= length) { i2 = i5; } else { i2 = i5; e(str, c17668yld, rvvArr, i4, rvv, i); } i5 = i2 + 1; } for (int i6 = 0; i6 < c17668yld.e.length; i6++) { rvvArr[i4 - 1][i6] = null; } } int i7 = -1; int i8 = Integer.MAX_VALUE; for (int i9 = 0; i9 < c17668yld.e.length; i9++) { RVV rvv2 = rvvArr[length][i9]; if (rvv2 != null && rvv2.a < i8) { i8 = rvv2.a; i7 = i9; } } if (i7 < 0) { StringBuilder sb = new StringBuilder("Failed to encode \""); sb.append(str); sb.append("\""); throw new IllegalStateException(sb.toString()); } ArrayList arrayList = new ArrayList(); for (RVV rvv3 = rvvArr[length][i7]; rvv3 != null; rvv3 = rvv3.d) { if (rvv3.b == 1000) { arrayList.add(0, 1000); } else { byte[] bytes = "".concat(String.valueOf(rvv3.b)).getBytes(c17668yld.e[rvv3.e].charset()); for (int length2 = bytes.length - 1; length2 >= 0; length2--) { arrayList.add(0, Integer.valueOf(bytes[length2] & UnsignedBytes.MAX_VALUE)); } } if ((rvv3.d == null ? 0 : rvv3.d.e) != rvv3.e) { arrayList.add(0, Integer.valueOf(EnumC0626KzG.d(c17668yld.e[rvv3.e].charset()).values[0] + 256)); } } int size = arrayList.size(); int[] iArr2 = new int[size]; while (i3 < size) { iArr2[i3] = ((Integer) arrayList.get(i3)).intValue(); i3++; } this.e = iArr2; } @Override // o.InterfaceC2154aYo public final int b() { return this.e.length; } public final boolean e(int i, int i2) { if ((i + i2) - 1 >= this.e.length) { return false; } for (int i3 = 0; i3 < i2; i3++) { if (d(i + i3)) { return false; } } return true; } @Override // o.InterfaceC2154aYo public final char c(int i) { if (i < 0 || i >= this.e.length) { throw new IndexOutOfBoundsException("".concat(String.valueOf(i))); } if (!d(i)) { return (char) (b(i) ? this.d : this.e[i]); } StringBuilder sb = new StringBuilder("value at "); sb.append(i); sb.append(" is not a character but an ECI"); throw new IllegalArgumentException(sb.toString()); } @Override // o.InterfaceC2154aYo public final CharSequence c(int i, int i2) { if (i < 0 || i > i2 || i2 > this.e.length) { throw new IndexOutOfBoundsException("".concat(String.valueOf(i))); } StringBuilder sb = new StringBuilder(); while (i < i2) { if (d(i)) { StringBuilder sb2 = new StringBuilder("value at "); sb2.append(i); sb2.append(" is not a character but an ECI"); throw new IllegalArgumentException(sb2.toString()); } sb.append(c(i)); i++; } return sb; } @Override // o.InterfaceC2154aYo public final boolean d(int i) { if (i >= 0) { int[] iArr = this.e; if (i < iArr.length) { int i2 = iArr[i]; return i2 > 255 && i2 <= 999; } } throw new IndexOutOfBoundsException("".concat(String.valueOf(i))); } public final boolean b(int i) { if (i >= 0) { int[] iArr = this.e; if (i < iArr.length) { return iArr[i] == 1000; } } throw new IndexOutOfBoundsException("".concat(String.valueOf(i))); } @Override // o.InterfaceC2154aYo public final int a(int i) { if (i < 0 || i >= this.e.length) { throw new IndexOutOfBoundsException("".concat(String.valueOf(i))); } if (!d(i)) { StringBuilder sb = new StringBuilder("value at "); sb.append(i); sb.append(" is not an ECI but a character"); throw new IllegalArgumentException(sb.toString()); } return this.e[i] - 256; } public String toString() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < this.e.length; i++) { if (i > 0) { sb.append(", "); } if (d(i)) { sb.append("ECI("); sb.append(a(i)); sb.append(')'); } else if (c(i) < 128) { sb.append('\''); sb.append(c(i)); sb.append('\''); } else { sb.append((int) c(i)); } } return sb.toString(); } private static void c(RVV[][] rvvArr, int i, RVV rvv) { if (rvvArr[i][rvv.e] == null || rvvArr[i][rvv.e].a > rvv.a) { rvvArr[i][rvv.e] = rvv; } } /* JADX WARN: Code restructure failed: missing block: B:5:0x0029, code lost: if (r17.e[r17.c].canEncode("".concat(java.lang.String.valueOf(r10))) != false) goto L7; */ /* JADX WARN: Removed duplicated region for block: B:9:0x0037 */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ private static void e(java.lang.String r16, o.C17668yld r17, o.C16224mUD.RVV[][] r18, int r19, o.C16224mUD.RVV r20, int r21) { /* r7 = r17 r8 = r19 r0 = r16 r9 = r21 char r10 = r0.charAt(r8) java.nio.charset.CharsetEncoder[] r0 = r7.e int r0 = r0.length int r1 = r7.c java.lang.String r11 = "" if (r1 < 0) goto L32 if (r10 == r9) goto L2b int r1 = r7.c java.nio.charset.CharsetEncoder[] r2 = r7.e r1 = r2[r1] java.lang.String r2 = java.lang.String.valueOf(r10) java.lang.String r2 = r11.concat(r2) boolean r1 = r1.canEncode(r2) if (r1 == 0) goto L32 L2b: int r0 = r7.c int r1 = r0 + 1 r12 = r0 r13 = r1 goto L35 L32: r1 = 0 r13 = r0 r12 = r1 L35: if (r12 >= r13) goto L68 if (r10 == r9) goto L4f java.nio.charset.CharsetEncoder[] r0 = r7.e r0 = r0[r12] java.lang.String r1 = java.lang.String.valueOf(r10) java.lang.String r1 = r11.concat(r1) boolean r0 = r0.canEncode(r1) if (r0 == 0) goto L4c goto L4f L4c: r0 = r18 goto L65 L4f: int r14 = r8 + 1 o.mUD$RVV r15 = new o.mUD$RVV r6 = 0 r0 = r15 r1 = r10 r2 = r17 r3 = r12 r4 = r20 r5 = r21 r0.(r1, r2, r3, r4, r5, r6) r0 = r18 c(r0, r14, r15) L65: int r12 = r12 + 1 goto L35 L68: return */ throw new UnsupportedOperationException("Method not decompiled: o.C16224mUD.e(java.lang.String, o.yld, o.mUD$RVV[][], int, o.mUD$RVV, int):void"); } /* JADX INFO: Access modifiers changed from: package-private */ /* renamed from: o.mUD$RVV */ /* loaded from: classes2.dex */ public static final class RVV { private final int a; final char b; private final RVV d; private final int e; /* synthetic */ RVV(char c, C17668yld c17668yld, int i, RVV rvv, int i2, byte b) { this(c, c17668yld, i, rvv, i2); } private RVV(char c, C17668yld c17668yld, int i, RVV rvv, int i2) { char c2 = c == i2 ? (char) 1000 : c; this.b = c2; this.e = i; this.d = rvv; int length = c2 == 1000 ? 1 : "".concat(String.valueOf(c)).getBytes(c17668yld.e[i].charset()).length; length = (rvv == null ? 0 : rvv.e) != i ? length + 3 : length; this.a = rvv != null ? length + rvv.a : length; } } }