Skip to content

Commit

Permalink
Ported r2387 from ZXing
Browse files Browse the repository at this point in the history
Original commit message: "Issue 1332 fix EDIFACT decoding"
  • Loading branch information
cwalcott committed Feb 14, 2013
1 parent ac141cb commit 1b4b5ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions ZXingObjC/common/ZXBitSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions ZXingObjC/datamatrix/decoder/ZXDataMatrixDecodedBitStreamParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}


Expand Down

0 comments on commit 1b4b5ce

Please sign in to comment.