MCPcopy
hub / github.com/zxing-js/library / getEncodedData

Method getEncodedData

src/core/aztec/decoder/Decoder.ts:97–154  ·  view source on GitHub ↗

* Gets the string encoded in the aztec code bits * * @return the decoded string

(correctedBits: boolean[])

Source from the content-addressed store, hash-verified

95 * @return the decoded string
96 */
97 private static getEncodedData(correctedBits: boolean[]): string {
98 let endIndex: number = correctedBits.length;
99 let latchTable = Table.UPPER; // table most recently latched to
100 let shiftTable = Table.UPPER; // table to use for the next read
101 let result: string = '';
102 let index = 0;
103 while (index < endIndex) {
104 if (shiftTable === Table.BINARY) {
105 if (endIndex - index < 5) {
106 break;
107 }
108 let length = Decoder.readCode(correctedBits, index, 5);
109 index += 5;
110 if (length === 0) {
111 if (endIndex - index < 11) {
112 break;
113 }
114 length = Decoder.readCode(correctedBits, index, 11) + 31;
115 index += 11;
116 }
117 for (let charCount = 0; charCount < length; charCount++) {
118 if (endIndex - index < 8) {
119 index = endIndex; // Force outer loop to exit
120 break;
121 }
122 const code: int = Decoder.readCode(correctedBits, index, 8);
123 result += /*(char)*/ StringUtils.castAsNonUtf8Char(code);
124 index += 8;
125 }
126 // Go back to whatever mode we had been in
127 shiftTable = latchTable;
128 } else {
129 let size = shiftTable === Table.DIGIT ? 4 : 5;
130 if (endIndex - index < size) {
131 break;
132 }
133 let code = Decoder.readCode(correctedBits, index, size);
134 index += size;
135 let str = Decoder.getCharacter(shiftTable, code);
136 if (str.startsWith('CTRL_')) {
137 // Table changes
138 // ISO/IEC 24778:2008 prescribes ending a shift sequence in the mode from which it was invoked.
139 // That's including when that mode is a shift.
140 // Our test case dlusbs.png for issue #642 exercises that.
141 latchTable = shiftTable; // Latch the current mode, so as to return to Upper after U/S B/S
142 shiftTable = Decoder.getTable(str.charAt(5));
143 if (str.charAt(6) === 'L') {
144 latchTable = shiftTable;
145 }
146 } else {
147 result += str;
148 // Go back to whatever mode we had been in
149 shiftTable = latchTable;
150 }
151 }
152 }
153 return result;
154 }

Callers 2

highLevelDecodeMethod · 0.95
decodeMethod · 0.80

Calls 5

readCodeMethod · 0.80
castAsNonUtf8CharMethod · 0.80
getCharacterMethod · 0.80
getTableMethod · 0.80
charAtMethod · 0.65

Tested by

no test coverage detected