package com.google.zxing.client.result; import com.google.android.exoplayer2.C; import com.google.zxing.Result; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.regex.Pattern; /* loaded from: classes3.dex */ public abstract class ResultParser { private static final String BYTE_ORDER_MARK = "\ufeff"; private static final ResultParser[] PARSERS = {new BookmarkDoCoMoResultParser(), new AddressBookDoCoMoResultParser(), new EmailDoCoMoResultParser(), new AddressBookAUResultParser(), new VCardResultParser(), new BizcardResultParser(), new VEventResultParser(), new EmailAddressResultParser(), new SMTPResultParser(), new TelResultParser(), new SMSMMSResultParser(), new SMSTOMMSTOResultParser(), new GeoResultParser(), new WifiResultParser(), new URLTOResultParser(), new URIResultParser(), new ISBNResultParser(), new ProductResultParser(), new ExpandedProductResultParser(), new VINResultParser()}; private static final Pattern DIGITS = Pattern.compile("\\d+"); private static final Pattern AMPERSAND = Pattern.compile("&"); private static final Pattern EQUALS = Pattern.compile("="); static final String[] EMPTY_STR_ARRAY = new String[0]; /* JADX INFO: Access modifiers changed from: protected */ public static int parseHexDigit(char c) { if (c >= '0' && c <= '9') { return c - '0'; } if (c >= 'a' && c <= 'f') { return c - 'W'; } if (c < 'A' || c > 'F') { return -1; } return c - '7'; } public abstract ParsedResult parse(Result result); /* JADX INFO: Access modifiers changed from: protected */ public static String getMassagedText(Result result) { String text = result.getText(); return text.startsWith(BYTE_ORDER_MARK) ? text.substring(1) : text; } public static ParsedResult parseResult(Result result) { for (ResultParser resultParser : PARSERS) { ParsedResult parse = resultParser.parse(result); if (parse != null) { return parse; } } return new TextParsedResult(result.getText(), null); } protected static void maybeAppend(String str, StringBuilder sb) { if (str != null) { sb.append('\n'); sb.append(str); } } protected static void maybeAppend(String[] strArr, StringBuilder sb) { if (strArr != null) { for (String str : strArr) { sb.append('\n'); sb.append(str); } } } /* JADX INFO: Access modifiers changed from: protected */ public static String[] maybeWrap(String str) { if (str == null) { return null; } return new String[]{str}; } protected static String unescapeBackslash(String str) { int indexOf = str.indexOf(92); if (indexOf < 0) { return str; } int length = str.length(); StringBuilder sb = new StringBuilder(length - 1); sb.append(str.toCharArray(), 0, indexOf); boolean z = false; while (indexOf < length) { char charAt = str.charAt(indexOf); if (z || charAt != '\\') { sb.append(charAt); z = false; } else { z = true; } indexOf++; } return sb.toString(); } /* JADX INFO: Access modifiers changed from: protected */ public static boolean isStringOfDigits(CharSequence charSequence, int i) { return charSequence != null && i > 0 && i == charSequence.length() && DIGITS.matcher(charSequence).matches(); } /* JADX INFO: Access modifiers changed from: protected */ public static boolean isSubstringOfDigits(CharSequence charSequence, int i, int i2) { int i3; return charSequence != null && i2 > 0 && charSequence.length() >= (i3 = i2 + i) && DIGITS.matcher(charSequence.subSequence(i, i3)).matches(); } /* JADX INFO: Access modifiers changed from: package-private */ public static Map parseNameValuePairs(String str) { int indexOf = str.indexOf(63); if (indexOf < 0) { return null; } HashMap hashMap = new HashMap(3); for (String str2 : AMPERSAND.split(str.substring(indexOf + 1))) { appendKeyValue(str2, hashMap); } return hashMap; } private static void appendKeyValue(CharSequence charSequence, Map map) { String[] split = EQUALS.split(charSequence, 2); if (split.length == 2) { try { map.put(split[0], urlDecode(split[1])); } catch (IllegalArgumentException unused) { } } } /* JADX INFO: Access modifiers changed from: package-private */ public static String urlDecode(String str) { try { return URLDecoder.decode(str, C.UTF8_NAME); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } } /* JADX INFO: Access modifiers changed from: package-private */ public static String[] matchPrefixedField(String str, String str2, char c, boolean z) { int length = str2.length(); ArrayList arrayList = null; int i = 0; while (i < length) { int indexOf = str2.indexOf(str, i); if (indexOf < 0) { break; } int length2 = indexOf + str.length(); boolean z2 = true; ArrayList arrayList2 = arrayList; int i2 = length2; while (z2) { int indexOf2 = str2.indexOf(c, i2); if (indexOf2 < 0) { i2 = str2.length(); } else if (countPrecedingBackslashes(str2, indexOf2) % 2 != 0) { i2 = indexOf2 + 1; } else { if (arrayList2 == null) { arrayList2 = new ArrayList(3); } String unescapeBackslash = unescapeBackslash(str2.substring(length2, indexOf2)); if (z) { unescapeBackslash = unescapeBackslash.trim(); } if (!unescapeBackslash.isEmpty()) { arrayList2.add(unescapeBackslash); } i2 = indexOf2 + 1; } z2 = false; } i = i2; arrayList = arrayList2; } if (arrayList == null || arrayList.isEmpty()) { return null; } return (String[]) arrayList.toArray(EMPTY_STR_ARRAY); } private static int countPrecedingBackslashes(CharSequence charSequence, int i) { int i2 = 0; for (int i3 = i - 1; i3 >= 0 && charSequence.charAt(i3) == '\\'; i3--) { i2++; } return i2; } /* JADX INFO: Access modifiers changed from: package-private */ public static String matchSinglePrefixedField(String str, String str2, char c, boolean z) { String[] matchPrefixedField = matchPrefixedField(str, str2, c, z); if (matchPrefixedField == null) { return null; } return matchPrefixedField[0]; } }