| 250 | } |
| 251 | |
| 252 | static void DecodeContent(const BitArray& bits, Content& res) |
| 253 | { |
| 254 | Table latchTable = Table::UPPER; // table most recently latched to |
| 255 | Table shiftTable = Table::UPPER; // table to use for the next read |
| 256 | |
| 257 | auto remBits = BitArrayView(bits); |
| 258 | |
| 259 | while (remBits.size() >= (shiftTable == Table::DIGIT ? 4 : 5)) { // see ISO/IEC 24778:2008 7.3.1.2 regarding padding bits |
| 260 | if (shiftTable == Table::BINARY) { |
| 261 | int length = remBits.readBits(5); |
| 262 | if (length == 0) |
| 263 | length = remBits.readBits(11) + 31; |
| 264 | for (int i = 0; i < length; i++) |
| 265 | res.push_back(remBits.readBits(8)); |
| 266 | // Go back to whatever mode we had been in |
| 267 | shiftTable = latchTable; |
| 268 | } else { |
| 269 | int size = shiftTable == Table::DIGIT ? 4 : 5; |
| 270 | int code = remBits.readBits(size); |
| 271 | const char* str = GetCharacter(shiftTable, code); |
| 272 | if (std::strncmp(str, "CTRL_", 5) == 0) { |
| 273 | // Table changes |
| 274 | // ISO/IEC 24778:2008 prescibes ending a shift sequence in the mode from which it was invoked. |
| 275 | // That's including when that mode is a shift. |
| 276 | // Our test case dlusbs.png for issue #642 exercises that. |
| 277 | latchTable = shiftTable; // Latch the current mode, so as to return to Upper after U/S B/S |
| 278 | shiftTable = GetTable(str[5]); |
| 279 | if (str[6] == 'L') |
| 280 | latchTable = shiftTable; |
| 281 | } else if (std::strcmp(str, "FLGN") == 0) { |
| 282 | int flg = remBits.readBits(3); |
| 283 | if (flg == 0) { // FNC1 |
| 284 | res.push_back(29); // May be removed at end if first/second FNC1 |
| 285 | } else if (flg <= 6) { |
| 286 | // FLG(1) to FLG(6) ECI |
| 287 | res.switchEncoding(ParseECIValue(remBits, flg)); |
| 288 | } else { |
| 289 | // FLG(7) is invalid |
| 290 | } |
| 291 | shiftTable = latchTable; |
| 292 | } else { |
| 293 | res.append(str); |
| 294 | // Go back to whatever mode we had been in |
| 295 | shiftTable = latchTable; |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | ZXING_EXPORT_TEST_ONLY |
| 302 | DecoderResult Decode(const BitArray& bits) |
no test coverage detected