mirror of
https://github.com/zxing/zxing.git
synced 2024-11-10 04:54:04 -08:00
More on #679 : convert UPC-E to A before getting check digit
This commit is contained in:
parent
aa0ee28cec
commit
c219e28d56
|
@ -173,7 +173,10 @@ public final class UPCEReader extends UPCEANReader {
|
|||
result.append(lastChar);
|
||||
break;
|
||||
}
|
||||
result.append(upce.charAt(7));
|
||||
// Only append check digit in conversion if supplied
|
||||
if (upce.length() >= 8) {
|
||||
result.append(upce.charAt(7));
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ public final class UPCEWriter extends UPCEANWriter {
|
|||
// No check digit present, calculate it and add it
|
||||
int check;
|
||||
try {
|
||||
check = UPCEANReader.getStandardUPCEANChecksum(contents);
|
||||
check = UPCEANReader.getStandardUPCEANChecksum(UPCEReader.convertUPCEtoUPCA(contents));
|
||||
} catch (FormatException fe) {
|
||||
throw new IllegalArgumentException(fe);
|
||||
}
|
||||
|
@ -75,6 +75,11 @@ public final class UPCEWriter extends UPCEANWriter {
|
|||
throw new IllegalArgumentException(
|
||||
"Requested contents should be 8 digits long, but got " + length);
|
||||
}
|
||||
|
||||
int firstDigit = Character.digit(contents.charAt(0), 10);
|
||||
if (firstDigit != 0 && firstDigit != 1) {
|
||||
throw new IllegalArgumentException("Number system must be 0 or 1");
|
||||
}
|
||||
|
||||
int checkDigit = Character.digit(contents.charAt(7), 10);
|
||||
int parities = UPCEReader.CHECK_DIGIT_ENCODINGS[checkDigit];
|
||||
|
|
Loading…
Reference in a new issue