jimu-decompiled/sources/com/google/zxing/client/result/ResultParser.java
2025-05-13 19:24:51 +02:00

173 lines
5.6 KiB
Java

package com.google.zxing.client.result;
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: classes.dex */
public abstract class ResultParser {
private static final ResultParser[] a = {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 b = Pattern.compile("\\d+");
private static final Pattern c = Pattern.compile("&");
private static final Pattern d = Pattern.compile("=");
protected static int a(char c2) {
if (c2 >= '0' && c2 <= '9') {
return c2 - '0';
}
char c3 = 'a';
if (c2 < 'a' || c2 > 'f') {
c3 = 'A';
if (c2 < 'A' || c2 > 'F') {
return -1;
}
}
return (c2 - c3) + 10;
}
protected static boolean a(CharSequence charSequence, int i, int i2) {
int i3;
return charSequence != null && i2 > 0 && charSequence.length() >= (i3 = i2 + i) && b.matcher(charSequence.subSequence(i, i3)).matches();
}
protected static String[] a(String str) {
if (str == null) {
return null;
}
return new String[]{str};
}
protected static String b(Result result) {
String e = result.e();
return e.startsWith("\ufeff") ? e.substring(1) : e;
}
public static ParsedResult c(Result result) {
for (ResultParser resultParser : a) {
ParsedResult a2 = resultParser.a(result);
if (a2 != null) {
return a2;
}
}
return new TextParsedResult(result.e(), null);
}
static String d(String str) {
try {
return URLDecoder.decode(str, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}
public abstract ParsedResult a(Result result);
private static void a(CharSequence charSequence, Map<String, String> map) {
String[] split = d.split(charSequence, 2);
if (split.length == 2) {
try {
map.put(split[0], d(split[1]));
} catch (IllegalArgumentException unused) {
}
}
}
protected static boolean b(CharSequence charSequence, int i) {
return charSequence != null && i > 0 && i == charSequence.length() && b.matcher(charSequence).matches();
}
protected static String c(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();
}
static Map<String, String> b(String str) {
int indexOf = str.indexOf(63);
if (indexOf < 0) {
return null;
}
HashMap hashMap = new HashMap(3);
for (String str2 : c.split(str.substring(indexOf + 1))) {
a(str2, hashMap);
}
return hashMap;
}
static String[] a(String str, String str2, char c2, boolean z) {
int i;
int length = str2.length();
ArrayList arrayList = null;
for (int i2 = 0; i2 < length; i2 = i) {
int indexOf = str2.indexOf(str, i2);
if (indexOf < 0) {
break;
}
int length2 = indexOf + str.length();
boolean z2 = true;
i = length2;
while (z2) {
int indexOf2 = str2.indexOf(c2, i);
if (indexOf2 < 0) {
i = str2.length();
} else if (a(str2, indexOf2) % 2 != 0) {
i = indexOf2 + 1;
} else {
if (arrayList == null) {
arrayList = new ArrayList(3);
}
String c3 = c(str2.substring(length2, indexOf2));
if (z) {
c3 = c3.trim();
}
if (!c3.isEmpty()) {
arrayList.add(c3);
}
i = indexOf2 + 1;
}
z2 = false;
}
}
if (arrayList == null || arrayList.isEmpty()) {
return null;
}
return (String[]) arrayList.toArray(new String[arrayList.size()]);
}
static String b(String str, String str2, char c2, boolean z) {
String[] a2 = a(str, str2, c2, z);
if (a2 == null) {
return null;
}
return a2[0];
}
private static int a(CharSequence charSequence, int i) {
int i2 = 0;
for (int i3 = i - 1; i3 >= 0 && charSequence.charAt(i3) == '\\'; i3--) {
i2++;
}
return i2;
}
}