package androidx.room.util;

import android.database.Cursor;
import android.os.Build;
import kotlin.collections.q;

/* JADX INFO: loaded from: classes.dex */
public abstract class a {
    public static final int a(Cursor cursor, String str) {
        String strZ;
        nb.g.i(cursor, "c");
        int columnIndex = cursor.getColumnIndex(str);
        if (columnIndex < 0) {
            columnIndex = cursor.getColumnIndex("`" + str + '`');
            if (columnIndex < 0) {
                int i10 = -1;
                if (Build.VERSION.SDK_INT <= 25 && str.length() != 0) {
                    String[] columnNames = cursor.getColumnNames();
                    nb.g.f(columnNames);
                    String strConcat = ".".concat(str);
                    String str2 = "." + str + '`';
                    int length = columnNames.length;
                    int i11 = 0;
                    int i12 = 0;
                    while (i11 < length) {
                        String str3 = columnNames[i11];
                        int i13 = i12 + 1;
                        if (str3.length() >= str.length() + 2 && (kotlin.text.h.b0(str3, strConcat, false) || (str3.charAt(0) == '`' && kotlin.text.h.b0(str3, str2, false)))) {
                            i10 = i12;
                            break;
                        }
                        i11++;
                        i12 = i13;
                    }
                }
                columnIndex = i10;
            }
        }
        if (columnIndex >= 0) {
            return columnIndex;
        }
        try {
            String[] columnNames2 = cursor.getColumnNames();
            nb.g.h(columnNames2, "getColumnNames(...)");
            strZ = q.Z(columnNames2);
        } catch (Exception unused) {
            strZ = "unknown";
        }
        throw new IllegalArgumentException(defpackage.e.k("column '", str, "' does not exist. Available columns: ", strZ));
    }
}
