Houjie
2025-07-24 52a3ff1bce1417b39f6872d8e8cb378e9c2ccc6f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import StringBuilder from '../../util/StringBuilder';
import SymbolInfo from './SymbolInfo';
export class EncoderContext {
    constructor(msg) {
        this.msg = msg;
        this.pos = 0;
        this.skipAtEnd = 0;
        // From this point on Strings are not Unicode anymore!
        const msgBinary = msg.split('').map(c => c.charCodeAt(0));
        const sb = new StringBuilder();
        for (let i = 0, c = msgBinary.length; i < c; i++) {
            const ch = String.fromCharCode(msgBinary[i] & 0xff);
            if (ch === '?' && msg.charAt(i) !== '?') {
                throw new Error('Message contains characters outside ISO-8859-1 encoding.');
            }
            sb.append(ch);
        }
        this.msg = sb.toString(); // Not Unicode here!
        this.shape = 0 /* FORCE_NONE */;
        this.codewords = new StringBuilder();
        this.newEncoding = -1;
    }
    setSymbolShape(shape) {
        this.shape = shape;
    }
    setSizeConstraints(minSize, maxSize) {
        this.minSize = minSize;
        this.maxSize = maxSize;
    }
    getMessage() {
        return this.msg;
    }
    setSkipAtEnd(count) {
        this.skipAtEnd = count;
    }
    getCurrentChar() {
        return this.msg.charCodeAt(this.pos);
    }
    getCurrent() {
        return this.msg.charCodeAt(this.pos);
    }
    getCodewords() {
        return this.codewords;
    }
    writeCodewords(codewords) {
        this.codewords.append(codewords);
    }
    writeCodeword(codeword) {
        this.codewords.append(codeword);
    }
    getCodewordCount() {
        return this.codewords.length();
    }
    getNewEncoding() {
        return this.newEncoding;
    }
    signalEncoderChange(encoding) {
        this.newEncoding = encoding;
    }
    resetEncoderSignal() {
        this.newEncoding = -1;
    }
    hasMoreCharacters() {
        return this.pos < this.getTotalMessageCharCount();
    }
    getTotalMessageCharCount() {
        return this.msg.length - this.skipAtEnd;
    }
    getRemainingCharacters() {
        return this.getTotalMessageCharCount() - this.pos;
    }
    getSymbolInfo() {
        return this.symbolInfo;
    }
    updateSymbolInfo(len = this.getCodewordCount()) {
        if (this.symbolInfo == null || len > this.symbolInfo.getDataCapacity()) {
            this.symbolInfo = SymbolInfo.lookup(len, this.shape, this.minSize, this.maxSize, true);
        }
    }
    resetSymbolInfo() {
        this.symbolInfo = null;
    }
}