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

Method encode

src/core/datamatrix/encoder/EdifactEncoder.ts:13–48  ·  view source on GitHub ↗
(context: EncoderContext)

Source from the content-addressed store, hash-verified

11 }
12
13 public encode(context: EncoderContext) {
14 // step F
15 const buffer = new StringBuilder();
16 while (context.hasMoreCharacters()) {
17 const c = context.getCurrentChar();
18 this.encodeChar(c, buffer);
19 context.pos++;
20
21 const count = buffer.length();
22 if (count >= 4) {
23 context.writeCodewords(this.encodeToCodewords(buffer.toString()));
24
25 const test = buffer.toString().substring(4);
26 buffer.setLengthToZero();
27 buffer.append(test);
28
29 // buffer.delete(0, 4);
30 // for (let i = 0; i < 4; i++) {
31 // buffer.deleteCharAt(i);
32 // }
33
34 const newMode = HighLevelEncoder.lookAheadTest(
35 context.getMessage(),
36 context.pos,
37 this.getEncodingMode()
38 );
39 if (newMode !== this.getEncodingMode()) {
40 // Return to ASCII encodation, which will actually handle latch to new mode
41 context.signalEncoderChange(ASCII_ENCODATION);
42 break;
43 }
44 }
45 }
46 buffer.append(StringUtils.getCharAt(31)); // Unlatch
47 this.handleEOD(context, buffer);
48 }
49
50 /**
51 * Handle "end of data" situations

Callers

nothing calls this directly

Calls 15

encodeCharMethod · 0.95
lengthMethod · 0.95
encodeToCodewordsMethod · 0.95
toStringMethod · 0.95
setLengthToZeroMethod · 0.95
appendMethod · 0.95
getEncodingModeMethod · 0.95
handleEODMethod · 0.95
hasMoreCharactersMethod · 0.80
getCurrentCharMethod · 0.80
writeCodewordsMethod · 0.80
substringMethod · 0.80

Tested by

no test coverage detected