195 lines
5.8 KiB
Java
195 lines
5.8 KiB
Java
package com.google.zxing.client.result;
|
|
|
|
import com.google.zxing.BarcodeFormat;
|
|
import com.google.zxing.Result;
|
|
import java.util.regex.Pattern;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class VINResultParser extends ResultParser {
|
|
private static final Pattern e = Pattern.compile("[IOQ]");
|
|
private static final Pattern f = Pattern.compile("[A-Z0-9]{17}");
|
|
|
|
private static int b(int i) {
|
|
if (i > 0 && i <= 7) {
|
|
return 9 - i;
|
|
}
|
|
if (i == 8) {
|
|
return 10;
|
|
}
|
|
if (i == 9) {
|
|
return 0;
|
|
}
|
|
if (i < 10 || i > 17) {
|
|
throw new IllegalArgumentException();
|
|
}
|
|
return 19 - i;
|
|
}
|
|
|
|
private static int c(char c) {
|
|
if (c >= 'A' && c <= 'I') {
|
|
return (c - 'A') + 1;
|
|
}
|
|
if (c >= 'J' && c <= 'R') {
|
|
return (c - 'J') + 1;
|
|
}
|
|
if (c >= 'S' && c <= 'Z') {
|
|
return (c - 'S') + 2;
|
|
}
|
|
if (c < '0' || c > '9') {
|
|
throw new IllegalArgumentException();
|
|
}
|
|
return c - '0';
|
|
}
|
|
|
|
private static int b(char c) {
|
|
if (c >= 'E' && c <= 'H') {
|
|
return (c - 'E') + 1984;
|
|
}
|
|
if (c >= 'J' && c <= 'N') {
|
|
return (c - 'J') + 1988;
|
|
}
|
|
if (c == 'P') {
|
|
return 1993;
|
|
}
|
|
if (c >= 'R' && c <= 'T') {
|
|
return (c - 'R') + 1994;
|
|
}
|
|
if (c >= 'V' && c <= 'Y') {
|
|
return (c - 'V') + 1997;
|
|
}
|
|
if (c >= '1' && c <= '9') {
|
|
return (c - '1') + 2001;
|
|
}
|
|
if (c < 'A' || c > 'D') {
|
|
throw new IllegalArgumentException();
|
|
}
|
|
return (c - 'A') + 2010;
|
|
}
|
|
|
|
@Override // com.google.zxing.client.result.ResultParser
|
|
public VINParsedResult a(Result result) {
|
|
if (result.a() != BarcodeFormat.CODE_39) {
|
|
return null;
|
|
}
|
|
String trim = e.matcher(result.e()).replaceAll("").trim();
|
|
if (!f.matcher(trim).matches()) {
|
|
return null;
|
|
}
|
|
try {
|
|
if (!a((CharSequence) trim)) {
|
|
return null;
|
|
}
|
|
String substring = trim.substring(0, 3);
|
|
return new VINParsedResult(trim, substring, trim.substring(3, 9), trim.substring(9, 17), b((CharSequence) substring), trim.substring(3, 8), b(trim.charAt(9)), trim.charAt(10), trim.substring(11));
|
|
} catch (IllegalArgumentException unused) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private static String b(CharSequence charSequence) {
|
|
char charAt = charSequence.charAt(0);
|
|
char charAt2 = charSequence.charAt(1);
|
|
if (charAt == '9') {
|
|
if (charAt2 >= 'A' && charAt2 <= 'E') {
|
|
return "BR";
|
|
}
|
|
if (charAt2 < '3' || charAt2 > '9') {
|
|
return null;
|
|
}
|
|
return "BR";
|
|
}
|
|
if (charAt == 'S') {
|
|
if (charAt2 >= 'A' && charAt2 <= 'M') {
|
|
return "UK";
|
|
}
|
|
if (charAt2 < 'N' || charAt2 > 'T') {
|
|
return null;
|
|
}
|
|
return "DE";
|
|
}
|
|
if (charAt == 'Z') {
|
|
if (charAt2 < 'A' || charAt2 > 'R') {
|
|
return null;
|
|
}
|
|
return "IT";
|
|
}
|
|
switch (charAt) {
|
|
case '1':
|
|
case '4':
|
|
case '5':
|
|
return "US";
|
|
case '2':
|
|
return "CA";
|
|
case '3':
|
|
if (charAt2 < 'A' || charAt2 > 'W') {
|
|
return null;
|
|
}
|
|
return "MX";
|
|
default:
|
|
switch (charAt) {
|
|
case 'J':
|
|
if (charAt2 < 'A' || charAt2 > 'T') {
|
|
return null;
|
|
}
|
|
return "JP";
|
|
case 'K':
|
|
if (charAt2 < 'L' || charAt2 > 'R') {
|
|
return null;
|
|
}
|
|
return "KO";
|
|
case 'L':
|
|
return "CN";
|
|
case 'M':
|
|
if (charAt2 < 'A' || charAt2 > 'E') {
|
|
return null;
|
|
}
|
|
return "IN";
|
|
default:
|
|
switch (charAt) {
|
|
case 'V':
|
|
if (charAt2 >= 'F' && charAt2 <= 'R') {
|
|
return "FR";
|
|
}
|
|
if (charAt2 < 'S' || charAt2 > 'W') {
|
|
return null;
|
|
}
|
|
return "ES";
|
|
case 'W':
|
|
return "DE";
|
|
case 'X':
|
|
if (charAt2 == '0') {
|
|
return "RU";
|
|
}
|
|
if (charAt2 < '3' || charAt2 > '9') {
|
|
return null;
|
|
}
|
|
return "RU";
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private static boolean a(CharSequence charSequence) {
|
|
int i = 0;
|
|
int i2 = 0;
|
|
while (i < charSequence.length()) {
|
|
int i3 = i + 1;
|
|
i2 += b(i3) * c(charSequence.charAt(i));
|
|
i = i3;
|
|
}
|
|
return charSequence.charAt(8) == a(i2 % 11);
|
|
}
|
|
|
|
private static char a(int i) {
|
|
if (i < 10) {
|
|
return (char) (i + 48);
|
|
}
|
|
if (i == 10) {
|
|
return 'X';
|
|
}
|
|
throw new IllegalArgumentException();
|
|
}
|
|
}
|