From: alasdair.john.mackintosh Date: Fri, 7 Dec 2007 21:06:26 +0000 (+0000) Subject: Don't calculate 1st digit unless checkBothParities is true X-Git-Url: http://git.rot13.org/?p=zxing.git;a=commitdiff_plain;h=fcaa79bb370be77e968bee4652bec13ebb2899f3 Don't calculate 1st digit unless checkBothParities is true git-svn-id: http://zxing.googlecode.com/svn/trunk@102 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- diff --git a/core/src/com/google/zxing/upc/UPCDecoder.java b/core/src/com/google/zxing/upc/UPCDecoder.java index c2621e45..493f771b 100755 --- a/core/src/com/google/zxing/upc/UPCDecoder.java +++ b/core/src/com/google/zxing/upc/UPCDecoder.java @@ -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; }