package com.google.android.gms.internal.clearcut; import java.nio.ByteBuffer; import org.jmrtd.PassportService; /* loaded from: classes2.dex */ abstract class zzfg { abstract int zzb(int i, byte[] bArr, int i2, int i3); /* JADX INFO: Access modifiers changed from: package-private */ public abstract int zzb(CharSequence charSequence, byte[] bArr, int i, int i2); /* JADX INFO: Access modifiers changed from: package-private */ public abstract void zzb(CharSequence charSequence, ByteBuffer byteBuffer); /* JADX INFO: Access modifiers changed from: package-private */ public final boolean zze(byte[] bArr, int i, int i2) { return zzb(0, bArr, i, i2) == 0; } /* JADX INFO: Access modifiers changed from: package-private */ public static void zzc(CharSequence charSequence, ByteBuffer byteBuffer) { int i; int i2; int length = charSequence.length(); int position = byteBuffer.position(); int i3 = 0; while (i3 < length) { try { char charAt = charSequence.charAt(i3); if (charAt >= 128) { break; } byteBuffer.put(position + i3, (byte) charAt); i3++; } catch (IndexOutOfBoundsException unused) { i = position; int position2 = byteBuffer.position(); int max = Math.max(i3, (i - byteBuffer.position()) + 1); char charAt2 = charSequence.charAt(i3); StringBuilder sb = new StringBuilder(37); sb.append("Failed writing "); sb.append(charAt2); sb.append(" at index "); sb.append(position2 + max); throw new ArrayIndexOutOfBoundsException(sb.toString()); } } if (i3 == length) { byteBuffer.position(position + i3); return; } int i4 = position + i3; while (i3 < length) { char charAt3 = charSequence.charAt(i3); if (charAt3 < 128) { byteBuffer.put(i4, (byte) charAt3); } else if (charAt3 < 2048) { int i5 = i4 + 1; try { byteBuffer.put(i4, (byte) ((charAt3 >>> 6) | 192)); byteBuffer.put(i5, (byte) ((charAt3 & '?') | 128)); i4 = i5; } catch (IndexOutOfBoundsException unused2) { i = i5; int position22 = byteBuffer.position(); int max2 = Math.max(i3, (i - byteBuffer.position()) + 1); char charAt22 = charSequence.charAt(i3); StringBuilder sb2 = new StringBuilder(37); sb2.append("Failed writing "); sb2.append(charAt22); sb2.append(" at index "); sb2.append(position22 + max2); throw new ArrayIndexOutOfBoundsException(sb2.toString()); } } else { if (charAt3 >= 55296 && 57343 >= charAt3) { int i6 = i3 + 1; if (i6 != length) { try { char charAt4 = charSequence.charAt(i6); if (Character.isSurrogatePair(charAt3, charAt4)) { int codePoint = Character.toCodePoint(charAt3, charAt4); i2 = i4 + 1; try { byteBuffer.put(i4, (byte) ((codePoint >>> 18) | 240)); i = i4 + 2; } catch (IndexOutOfBoundsException unused3) { i = i2; i3 = i6; int position222 = byteBuffer.position(); int max22 = Math.max(i3, (i - byteBuffer.position()) + 1); char charAt222 = charSequence.charAt(i3); StringBuilder sb22 = new StringBuilder(37); sb22.append("Failed writing "); sb22.append(charAt222); sb22.append(" at index "); sb22.append(position222 + max22); throw new ArrayIndexOutOfBoundsException(sb22.toString()); } try { byteBuffer.put(i2, (byte) (((codePoint >>> 12) & 63) | 128)); i4 += 3; byteBuffer.put(i, (byte) (((codePoint >>> 6) & 63) | 128)); byteBuffer.put(i4, (byte) ((codePoint & 63) | 128)); i3 = i6; } catch (IndexOutOfBoundsException unused4) { i3 = i6; int position2222 = byteBuffer.position(); int max222 = Math.max(i3, (i - byteBuffer.position()) + 1); char charAt2222 = charSequence.charAt(i3); StringBuilder sb222 = new StringBuilder(37); sb222.append("Failed writing "); sb222.append(charAt2222); sb222.append(" at index "); sb222.append(position2222 + max222); throw new ArrayIndexOutOfBoundsException(sb222.toString()); } } else { i3 = i6; } } catch (IndexOutOfBoundsException unused5) { i2 = i4; } } throw new zzfi(i3, length); } int i7 = i4 + 1; byteBuffer.put(i4, (byte) ((charAt3 >>> '\f') | PassportService.DEFAULT_MAX_BLOCKSIZE)); i4 += 2; byteBuffer.put(i7, (byte) (((charAt3 >>> 6) & 63) | 128)); byteBuffer.put(i4, (byte) ((charAt3 & '?') | 128)); } i3++; i4++; } byteBuffer.position(i4); } }