diff --git a/ZXingObjC/common/ZXBitSource.h b/ZXingObjC/common/ZXBitSource.h index 659b3646c..c4c316010 100644 --- a/ZXingObjC/common/ZXBitSource.h +++ b/ZXingObjC/common/ZXBitSource.h @@ -24,6 +24,7 @@ @interface ZXBitSource : NSObject +@property (nonatomic, assign, readonly) int bitOffset; @property (nonatomic, assign, readonly) int byteOffset; - (id)initWithBytes:(unsigned char *)bytes length:(unsigned int)length; diff --git a/ZXingObjC/datamatrix/decoder/ZXDataMatrixDecodedBitStreamParser.m b/ZXingObjC/datamatrix/decoder/ZXDataMatrixDecodedBitStreamParser.m index 390dc6346..45c3934e4 100644 --- a/ZXingObjC/datamatrix/decoder/ZXDataMatrixDecodedBitStreamParser.m +++ b/ZXingObjC/datamatrix/decoder/ZXDataMatrixDecodedBitStreamParser.m @@ -435,7 +435,6 @@ + (void)parseTwoBytes:(int)firstByte secondByte:(int)secondByte result:(int[])re * See ISO 16022:2006, 5.2.8 and Annex C Table C.3 */ + (void)decodeEdifactSegment:(ZXBitSource *)bits result:(NSMutableString *)result { - BOOL unlatch = NO; do { // If there is only two or less bytes left then it will be encoded as ASCII if (bits.available <= 16) { @@ -447,19 +446,20 @@ + (void)decodeEdifactSegment:(ZXBitSource *)bits result:(NSMutableString *)resul // Check for the unlatch character if (edifactValue == 0x1F) { // 011111 - unlatch = YES; - // If we encounter the unlatch code then continue reading because the Codeword triple - // is padded with 0's + // Read rest of byte, which should be 0, and stop + int bitsLeft = 8 - bits.bitOffset; + if (bitsLeft != 8) { + [bits readBits:bitsLeft]; + } + return; } - if (!unlatch) { - if ((edifactValue & 0x20) == 0) { // no 1 in the leading (6th) bit - edifactValue |= 0x40; // Add a leading 01 to the 6 bit binary value - } - [result appendFormat:@"%c", (char)edifactValue]; + if ((edifactValue & 0x20) == 0) { // no 1 in the leading (6th) bit + edifactValue |= 0x40; // Add a leading 01 to the 6 bit binary value } + [result appendFormat:@"%c", (char)edifactValue]; } - } while (!unlatch && bits.available > 0); + } while (bits.available > 0); }