mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Issue 1376 Check EAN13 checksum when encoding
git-svn-id: https://zxing.googlecode.com/svn/trunk@2454 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
191f541f4a
commit
91a71dba0b
|
@ -18,6 +18,7 @@ package com.google.zxing.oned;
|
||||||
|
|
||||||
import com.google.zxing.BarcodeFormat;
|
import com.google.zxing.BarcodeFormat;
|
||||||
import com.google.zxing.EncodeHintType;
|
import com.google.zxing.EncodeHintType;
|
||||||
|
import com.google.zxing.FormatException;
|
||||||
import com.google.zxing.WriterException;
|
import com.google.zxing.WriterException;
|
||||||
import com.google.zxing.common.BitMatrix;
|
import com.google.zxing.common.BitMatrix;
|
||||||
|
|
||||||
|
@ -55,6 +56,13 @@ public final class EAN13Writer extends UPCEANWriter {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Requested contents should be 13 digits long, but got " + contents.length());
|
"Requested contents should be 13 digits long, but got " + contents.length());
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
if (!UPCEANReader.checkStandardUPCEANChecksum(contents)) {
|
||||||
|
throw new IllegalArgumentException("Contents do not pass checksum");
|
||||||
|
}
|
||||||
|
} catch (FormatException fe) {
|
||||||
|
throw new IllegalArgumentException("Illegal contents");
|
||||||
|
}
|
||||||
|
|
||||||
int firstDigit = Integer.parseInt(contents.substring(0, 1));
|
int firstDigit = Integer.parseInt(contents.substring(0, 1));
|
||||||
int parities = EAN13Reader.FIRST_DIGIT_ENCODINGS[firstDigit];
|
int parities = EAN13Reader.FIRST_DIGIT_ENCODINGS[firstDigit];
|
||||||
|
|
|
@ -224,7 +224,7 @@ public abstract class UPCEANReader extends OneDReader {
|
||||||
* @return true iff string of digits passes the UPC/EAN checksum algorithm
|
* @return true iff string of digits passes the UPC/EAN checksum algorithm
|
||||||
* @throws FormatException if the string does not contain only digits
|
* @throws FormatException if the string does not contain only digits
|
||||||
*/
|
*/
|
||||||
private static boolean checkStandardUPCEANChecksum(CharSequence s) throws FormatException {
|
static boolean checkStandardUPCEANChecksum(CharSequence s) throws FormatException {
|
||||||
int length = s.length();
|
int length = s.length();
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue