Don't calculate 1st digit unless checkBothParities is true

git-svn-id: https://zxing.googlecode.com/svn/trunk@102 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
alasdair.john.mackintosh 2007-12-07 21:06:26 +00:00
parent 776c3db869
commit 852669ced6

View file

@ -251,18 +251,24 @@ final class UPCDecoder {
}
result.append(foundChar.character);
}
char firstDigit = '-';
for (int i = 0; i < FIRST_DIGIT_ENCODINGS.length; i++) {
if (firstDigitPattern == FIRST_DIGIT_ENCODINGS[i]) {
firstDigit = (char)((int)'0' + i);
break;
// If checkBothParities is true then we're potentially looking at the left
// hand side of an EAN-13 barcode, where the first digit is encoded by the
// parity pattern. In that case, calculate the first digit by checking
// the parity patterns.
if (checkBothParities) {
char firstDigit = '-';
for (int i = 0; i < FIRST_DIGIT_ENCODINGS.length; i++) {
if (firstDigitPattern == FIRST_DIGIT_ENCODINGS[i]) {
firstDigit = (char)((int)'0' + i);
break;
}
}
if (firstDigit == '-') {
return -1;
}
if (firstDigit != '0') {
result.insert(0, firstDigit);
}
}
if (firstDigit == '-') {
return -1;
}
if (firstDigit != '0') {
result.insert(0, firstDigit);
}
return rowOffset;
}