package o; /* loaded from: classes2.dex */ public final class ZdS implements InterfaceC16012kTv { @Override // o.InterfaceC16012kTv public final void c(C8198dDy c8198dDy) { boolean z; StringBuilder sb = new StringBuilder(); while (true) { z = true; if (c8198dDy.j >= c8198dDy.a.length() - c8198dDy.f) { break; } char charAt = c8198dDy.a.charAt(c8198dDy.j); if (charAt >= ' ' && charAt <= '?') { sb.append(charAt); } else if (charAt >= '@' && charAt <= '^') { sb.append((char) (charAt - '@')); } else { GpJ.a(charAt); } c8198dDy.j++; if (sb.length() >= 4) { c8198dDy.c.append(c(sb)); sb.delete(0, 4); if (GpJ.a(c8198dDy.a, c8198dDy.j, 4) != 4) { c8198dDy.d = 0; break; } } } sb.append((char) 31); try { int length = sb.length(); if (length == 0) { return; } if (length == 1) { c8198dDy.e(c8198dDy.c.length()); int length2 = c8198dDy.i.e - c8198dDy.c.length(); int length3 = (c8198dDy.a.length() - c8198dDy.f) - c8198dDy.j; if (length3 > length2) { c8198dDy.e(c8198dDy.c.length() + 1); length2 = c8198dDy.i.e - c8198dDy.c.length(); } if (length3 <= length2 && length2 <= 2) { return; } } if (length > 4) { throw new IllegalStateException("Count must not exceed 4"); } int i = length - 1; String c = c(sb); if (!(!(c8198dDy.j < c8198dDy.a.length() - c8198dDy.f)) || i > 2) { z = false; } if (i <= 2) { c8198dDy.e(c8198dDy.c.length() + i); if (c8198dDy.i.e - c8198dDy.c.length() >= 3) { c8198dDy.e(c8198dDy.c.length() + c.length()); c8198dDy.c.append(c); } } if (z) { c8198dDy.i = null; c8198dDy.j -= i; } c8198dDy.c.append(c); } finally { c8198dDy.d = 0; } } private static String c(CharSequence charSequence) { int length = charSequence.length(); if (length == 0) { throw new IllegalStateException("StringBuilder must not be empty"); } int charAt = (charSequence.charAt(0) << 18) + ((length >= 2 ? charSequence.charAt(1) : (char) 0) << '\f') + ((length >= 3 ? charSequence.charAt(2) : (char) 0) << 6) + (length >= 4 ? charSequence.charAt(3) : (char) 0); char c = (char) ((charAt >> 16) & 255); char c2 = (char) ((charAt >> 8) & 255); char c3 = (char) (charAt & 255); StringBuilder sb = new StringBuilder(3); sb.append(c); if (length >= 2) { sb.append(c2); } if (length >= 3) { sb.append(c3); } return sb.toString(); } }