338 lines
13 KiB
Java
338 lines
13 KiB
Java
package com.google.zxing.client.result;
|
|
|
|
import com.google.zxing.Result;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.net.URI;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class VCardResultParser extends ResultParser {
|
|
private static final Pattern e = Pattern.compile("BEGIN:VCARD", 2);
|
|
private static final Pattern f = Pattern.compile("\\d{4}-?\\d{2}-?\\d{2}");
|
|
private static final Pattern g = Pattern.compile("\r\n[ \t]");
|
|
private static final Pattern h = Pattern.compile("\\\\[nN]");
|
|
private static final Pattern i = Pattern.compile("\\\\([,;\\\\])");
|
|
private static final Pattern j = Pattern.compile("=");
|
|
private static final Pattern k = Pattern.compile(";");
|
|
private static final Pattern l = Pattern.compile("(?<!\\\\);+");
|
|
private static final Pattern m = Pattern.compile(",");
|
|
private static final Pattern n = Pattern.compile("[;,]");
|
|
|
|
static List<List<String>> b(CharSequence charSequence, String str, boolean z, boolean z2) {
|
|
ArrayList arrayList;
|
|
boolean z3;
|
|
String str2;
|
|
String str3;
|
|
int indexOf;
|
|
String replaceAll;
|
|
int length = str.length();
|
|
int i2 = 0;
|
|
int i3 = 0;
|
|
ArrayList arrayList2 = null;
|
|
while (i3 < length) {
|
|
int i4 = 2;
|
|
Matcher matcher = Pattern.compile("(?:^|\n)" + ((Object) charSequence) + "(?:;([^:]*))?:", 2).matcher(str);
|
|
if (i3 > 0) {
|
|
i3--;
|
|
}
|
|
if (!matcher.find(i3)) {
|
|
break;
|
|
}
|
|
int end = matcher.end(i2);
|
|
String group = matcher.group(1);
|
|
if (group != null) {
|
|
String[] split = k.split(group);
|
|
int length2 = split.length;
|
|
int i5 = 0;
|
|
arrayList = null;
|
|
z3 = false;
|
|
str2 = null;
|
|
str3 = null;
|
|
while (i5 < length2) {
|
|
String str4 = split[i5];
|
|
if (arrayList == null) {
|
|
arrayList = new ArrayList(1);
|
|
}
|
|
arrayList.add(str4);
|
|
String[] split2 = j.split(str4, i4);
|
|
if (split2.length > 1) {
|
|
String str5 = split2[0];
|
|
String str6 = split2[1];
|
|
if ("ENCODING".equalsIgnoreCase(str5) && "QUOTED-PRINTABLE".equalsIgnoreCase(str6)) {
|
|
z3 = true;
|
|
} else if ("CHARSET".equalsIgnoreCase(str5)) {
|
|
str2 = str6;
|
|
} else if ("VALUE".equalsIgnoreCase(str5)) {
|
|
str3 = str6;
|
|
}
|
|
}
|
|
i5++;
|
|
i4 = 2;
|
|
}
|
|
} else {
|
|
arrayList = null;
|
|
z3 = false;
|
|
str2 = null;
|
|
str3 = null;
|
|
}
|
|
int i6 = end;
|
|
while (true) {
|
|
indexOf = str.indexOf(10, i6);
|
|
if (indexOf < 0) {
|
|
break;
|
|
}
|
|
if (indexOf < str.length() - 1) {
|
|
int i7 = indexOf + 1;
|
|
if (str.charAt(i7) == ' ' || str.charAt(i7) == '\t') {
|
|
i6 = indexOf + 2;
|
|
}
|
|
}
|
|
if (!z3) {
|
|
break;
|
|
}
|
|
if (indexOf > 0) {
|
|
if (str.charAt(indexOf - 1) == '=') {
|
|
i6 = indexOf + 1;
|
|
}
|
|
}
|
|
if (indexOf < 2) {
|
|
break;
|
|
}
|
|
if (str.charAt(indexOf - 2) != '=') {
|
|
break;
|
|
}
|
|
i6 = indexOf + 1;
|
|
}
|
|
if (indexOf < 0) {
|
|
i3 = length;
|
|
} else {
|
|
if (indexOf > end) {
|
|
if (arrayList2 == null) {
|
|
arrayList2 = new ArrayList(1);
|
|
}
|
|
if (indexOf > 0 && str.charAt(indexOf - 1) == '\r') {
|
|
indexOf--;
|
|
}
|
|
String substring = str.substring(end, indexOf);
|
|
if (z) {
|
|
substring = substring.trim();
|
|
}
|
|
if (z3) {
|
|
replaceAll = a(substring, str2);
|
|
if (z2) {
|
|
replaceAll = l.matcher(replaceAll).replaceAll("\n").trim();
|
|
}
|
|
} else {
|
|
if (z2) {
|
|
substring = l.matcher(substring).replaceAll("\n").trim();
|
|
}
|
|
replaceAll = i.matcher(h.matcher(g.matcher(substring).replaceAll("")).replaceAll("\n")).replaceAll("$1");
|
|
}
|
|
if ("uri".equals(str3)) {
|
|
try {
|
|
replaceAll = URI.create(replaceAll).getSchemeSpecificPart();
|
|
} catch (IllegalArgumentException unused) {
|
|
}
|
|
}
|
|
if (arrayList == null) {
|
|
ArrayList arrayList3 = new ArrayList(1);
|
|
arrayList3.add(replaceAll);
|
|
arrayList2.add(arrayList3);
|
|
} else {
|
|
arrayList.add(0, replaceAll);
|
|
arrayList2.add(arrayList);
|
|
i3 = indexOf + 1;
|
|
}
|
|
}
|
|
i3 = indexOf + 1;
|
|
}
|
|
i2 = 0;
|
|
}
|
|
return arrayList2;
|
|
}
|
|
|
|
@Override // com.google.zxing.client.result.ResultParser
|
|
public AddressBookParsedResult a(Result result) {
|
|
String b = ResultParser.b(result);
|
|
Matcher matcher = e.matcher(b);
|
|
if (!matcher.find() || matcher.start() != 0) {
|
|
return null;
|
|
}
|
|
List<List<String>> b2 = b((CharSequence) "FN", b, true, false);
|
|
if (b2 == null) {
|
|
b2 = b((CharSequence) "N", b, true, false);
|
|
a((Iterable<List<String>>) b2);
|
|
}
|
|
List<String> a = a((CharSequence) "NICKNAME", b, true, false);
|
|
String[] split = a == null ? null : m.split(a.get(0));
|
|
List<List<String>> b3 = b((CharSequence) "TEL", b, true, false);
|
|
List<List<String>> b4 = b((CharSequence) "EMAIL", b, true, false);
|
|
List<String> a2 = a((CharSequence) "NOTE", b, false, false);
|
|
List<List<String>> b5 = b((CharSequence) "ADR", b, true, true);
|
|
List<String> a3 = a((CharSequence) "ORG", b, true, true);
|
|
List<String> a4 = a((CharSequence) "BDAY", b, true, false);
|
|
List<String> list = (a4 == null || a((CharSequence) a4.get(0))) ? a4 : null;
|
|
List<String> a5 = a((CharSequence) "TITLE", b, true, false);
|
|
List<List<String>> b6 = b((CharSequence) "URL", b, true, false);
|
|
List<String> a6 = a((CharSequence) "IMPP", b, true, false);
|
|
List<String> a7 = a((CharSequence) "GEO", b, true, false);
|
|
String[] split2 = a7 == null ? null : n.split(a7.get(0));
|
|
return new AddressBookParsedResult(a((Collection<List<String>>) b2), split, null, a((Collection<List<String>>) b3), b(b3), a((Collection<List<String>>) b4), b(b4), a(a6), a(a2), a((Collection<List<String>>) b5), b(b5), a(a3), a(list), a(a5), a((Collection<List<String>>) b6), (split2 == null || split2.length == 2) ? split2 : null);
|
|
}
|
|
|
|
private static String a(CharSequence charSequence, String str) {
|
|
char charAt;
|
|
int length = charSequence.length();
|
|
StringBuilder sb = new StringBuilder(length);
|
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
int i2 = 0;
|
|
while (i2 < length) {
|
|
char charAt2 = charSequence.charAt(i2);
|
|
if (charAt2 != '\n' && charAt2 != '\r') {
|
|
if (charAt2 != '=') {
|
|
a(byteArrayOutputStream, str, sb);
|
|
sb.append(charAt2);
|
|
} else if (i2 < length - 2 && (charAt = charSequence.charAt(i2 + 1)) != '\r' && charAt != '\n') {
|
|
i2 += 2;
|
|
char charAt3 = charSequence.charAt(i2);
|
|
int a = ResultParser.a(charAt);
|
|
int a2 = ResultParser.a(charAt3);
|
|
if (a >= 0 && a2 >= 0) {
|
|
byteArrayOutputStream.write((a << 4) + a2);
|
|
}
|
|
}
|
|
}
|
|
i2++;
|
|
}
|
|
a(byteArrayOutputStream, str, sb);
|
|
return sb.toString();
|
|
}
|
|
|
|
private static String[] b(Collection<List<String>> collection) {
|
|
String str;
|
|
if (collection == null || collection.isEmpty()) {
|
|
return null;
|
|
}
|
|
ArrayList arrayList = new ArrayList(collection.size());
|
|
for (List<String> list : collection) {
|
|
String str2 = list.get(0);
|
|
if (str2 != null && !str2.isEmpty()) {
|
|
int i2 = 1;
|
|
while (true) {
|
|
if (i2 >= list.size()) {
|
|
str = null;
|
|
break;
|
|
}
|
|
String str3 = list.get(i2);
|
|
int indexOf = str3.indexOf(61);
|
|
if (indexOf < 0) {
|
|
str = str3;
|
|
break;
|
|
}
|
|
if ("TYPE".equalsIgnoreCase(str3.substring(0, indexOf))) {
|
|
str = str3.substring(indexOf + 1);
|
|
break;
|
|
}
|
|
i2++;
|
|
}
|
|
arrayList.add(str);
|
|
}
|
|
}
|
|
return (String[]) arrayList.toArray(new String[arrayList.size()]);
|
|
}
|
|
|
|
private static void a(ByteArrayOutputStream byteArrayOutputStream, String str, StringBuilder sb) {
|
|
String str2;
|
|
if (byteArrayOutputStream.size() > 0) {
|
|
byte[] byteArray = byteArrayOutputStream.toByteArray();
|
|
if (str == null) {
|
|
str2 = new String(byteArray, StandardCharsets.UTF_8);
|
|
} else {
|
|
try {
|
|
str2 = new String(byteArray, str);
|
|
} catch (UnsupportedEncodingException unused) {
|
|
str2 = new String(byteArray, StandardCharsets.UTF_8);
|
|
}
|
|
}
|
|
byteArrayOutputStream.reset();
|
|
sb.append(str2);
|
|
}
|
|
}
|
|
|
|
static List<String> a(CharSequence charSequence, String str, boolean z, boolean z2) {
|
|
List<List<String>> b = b(charSequence, str, z, z2);
|
|
if (b == null || b.isEmpty()) {
|
|
return null;
|
|
}
|
|
return b.get(0);
|
|
}
|
|
|
|
private static String a(List<String> list) {
|
|
if (list == null || list.isEmpty()) {
|
|
return null;
|
|
}
|
|
return list.get(0);
|
|
}
|
|
|
|
private static String[] a(Collection<List<String>> collection) {
|
|
if (collection == null || collection.isEmpty()) {
|
|
return null;
|
|
}
|
|
ArrayList arrayList = new ArrayList(collection.size());
|
|
Iterator<List<String>> it = collection.iterator();
|
|
while (it.hasNext()) {
|
|
String str = it.next().get(0);
|
|
if (str != null && !str.isEmpty()) {
|
|
arrayList.add(str);
|
|
}
|
|
}
|
|
return (String[]) arrayList.toArray(new String[arrayList.size()]);
|
|
}
|
|
|
|
private static boolean a(CharSequence charSequence) {
|
|
return charSequence == null || f.matcher(charSequence).matches();
|
|
}
|
|
|
|
private static void a(Iterable<List<String>> iterable) {
|
|
int indexOf;
|
|
if (iterable != null) {
|
|
for (List<String> list : iterable) {
|
|
String str = list.get(0);
|
|
String[] strArr = new String[5];
|
|
int i2 = 0;
|
|
int i3 = 0;
|
|
while (i2 < 4 && (indexOf = str.indexOf(59, i3)) >= 0) {
|
|
strArr[i2] = str.substring(i3, indexOf);
|
|
i2++;
|
|
i3 = indexOf + 1;
|
|
}
|
|
strArr[i2] = str.substring(i3);
|
|
StringBuilder sb = new StringBuilder(100);
|
|
a(strArr, 3, sb);
|
|
a(strArr, 1, sb);
|
|
a(strArr, 2, sb);
|
|
a(strArr, 0, sb);
|
|
a(strArr, 4, sb);
|
|
list.set(0, sb.toString().trim());
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void a(String[] strArr, int i2, StringBuilder sb) {
|
|
if (strArr[i2] == null || strArr[i2].isEmpty()) {
|
|
return;
|
|
}
|
|
if (sb.length() > 0) {
|
|
sb.append(' ');
|
|
}
|
|
sb.append(strArr[i2]);
|
|
}
|
|
}
|