package com.google.firebase.firestore.model; import java.util.ArrayList; import java.util.Collections; import java.util.List; /* loaded from: classes2.dex */ public final class FieldPath extends BasePath { public static final FieldPath KEY_PATH = fromSingleSegment("__name__"); public static final FieldPath EMPTY_PATH = new FieldPath(Collections.emptyList()); @Override // com.google.firebase.firestore.model.BasePath final /* bridge */ /* synthetic */ FieldPath createPathWithSegments(List list) { return createPathWithSegments2((List) list); } private FieldPath(List list) { super(list); } public static FieldPath fromSingleSegment(String str) { return new FieldPath(Collections.singletonList(str)); } public static FieldPath fromSegments(List list) { return list.isEmpty() ? EMPTY_PATH : new FieldPath(list); } @Override // com.google.firebase.firestore.model.BasePath /* renamed from: createPathWithSegments, reason: avoid collision after fix types in other method */ final FieldPath createPathWithSegments2(List list) { return new FieldPath(list); } public static FieldPath fromServerFormat(String str) { ArrayList arrayList = new ArrayList(); StringBuilder sb = new StringBuilder(); int i = 0; boolean z = false; while (i < str.length()) { char charAt = str.charAt(i); if (charAt == '\\') { i++; if (i == str.length()) { throw new IllegalArgumentException("Trailing escape character is not allowed"); } sb.append(str.charAt(i)); } else if (charAt == '.') { if (!z) { String obj = sb.toString(); if (obj.isEmpty()) { StringBuilder sb2 = new StringBuilder("Invalid field path ("); sb2.append(str); sb2.append("). Paths must not be empty, begin with '.', end with '.', or contain '..'"); throw new IllegalArgumentException(sb2.toString()); } StringBuilder sb3 = new StringBuilder(); arrayList.add(obj); sb = sb3; } else { sb.append(charAt); } } else if (charAt == '`') { z = !z; } else { sb.append(charAt); } i++; } String obj2 = sb.toString(); if (obj2.isEmpty()) { StringBuilder sb4 = new StringBuilder("Invalid field path ("); sb4.append(str); sb4.append("). Paths must not be empty, begin with '.', end with '.', or contain '..'"); throw new IllegalArgumentException(sb4.toString()); } arrayList.add(obj2); return new FieldPath(arrayList); } private static boolean isValidIdentifier(String str) { if (str.isEmpty()) { return false; } char charAt = str.charAt(0); if (charAt != '_' && ((charAt < 'a' || charAt > 'z') && (charAt < 'A' || charAt > 'Z'))) { return false; } for (int i = 1; i < str.length(); i++) { char charAt2 = str.charAt(i); if (charAt2 != '_' && ((charAt2 < 'a' || charAt2 > 'z') && ((charAt2 < 'A' || charAt2 > 'Z') && (charAt2 < '0' || charAt2 > '9')))) { return false; } } return true; } @Override // com.google.firebase.firestore.model.BasePath public final String canonicalString() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < this.segments.size(); i++) { if (i > 0) { sb.append("."); } String replace = this.segments.get(i).replace("\\", "\\\\").replace("`", "\\`"); if (!isValidIdentifier(replace)) { StringBuilder sb2 = new StringBuilder("`"); sb2.append(replace); sb2.append('`'); replace = sb2.toString(); } sb.append(replace); } return sb.toString(); } public final boolean isKeyField() { return equals(KEY_PATH); } }