mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Issue 1332 fix EDIFACT decoding
git-svn-id: https://zxing.googlecode.com/svn/trunk@2387 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
0b3132e68f
commit
9add6f3992
|
@ -39,6 +39,13 @@ public final class BitSource {
|
|||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return index of next bit in current byte which would be read by the next call to {@link #readBits(int)}.
|
||||
*/
|
||||
public int getBitOffset() {
|
||||
return bitOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return index of next byte in input byte array which would be read by the next call to {@link #readBits(int)}.
|
||||
*/
|
||||
|
|
|
@ -413,7 +413,6 @@ final class DecodedBitStreamParser {
|
|||
* See ISO 16022:2006, 5.2.8 and Annex C Table C.3
|
||||
*/
|
||||
private static void decodeEdifactSegment(BitSource bits, StringBuilder result) {
|
||||
boolean unlatch = false;
|
||||
do {
|
||||
// If there is only two or less bytes left then it will be encoded as ASCII
|
||||
if (bits.available() <= 16) {
|
||||
|
@ -425,19 +424,20 @@ final class DecodedBitStreamParser {
|
|||
|
||||
// Check for the unlatch character
|
||||
if (edifactValue == 0x1F) { // 011111
|
||||
unlatch = true;
|
||||
// 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.getBitOffset();
|
||||
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.append((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.append((char) edifactValue);
|
||||
}
|
||||
} while (!unlatch && bits.available() > 0);
|
||||
} while (bits.available() > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue