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
84
85
86
87
88
89
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EncoderContext = void 0;
var StringBuilder_1 = require("../../util/StringBuilder");
var SymbolInfo_1 = require("./SymbolInfo");
var EncoderContext = /** @class */ (function () {
    function EncoderContext(msg) {
        this.msg = msg;
        this.pos = 0;
        this.skipAtEnd = 0;
        // From this point on Strings are not Unicode anymore!
        var msgBinary = msg.split('').map(function (c) { return c.charCodeAt(0); });
        var sb = new StringBuilder_1.default();
        for (var i = 0, c = msgBinary.length; i < c; i++) {
            var 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_1.default();
        this.newEncoding = -1;
    }
    EncoderContext.prototype.setSymbolShape = function (shape) {
        this.shape = shape;
    };
    EncoderContext.prototype.setSizeConstraints = function (minSize, maxSize) {
        this.minSize = minSize;
        this.maxSize = maxSize;
    };
    EncoderContext.prototype.getMessage = function () {
        return this.msg;
    };
    EncoderContext.prototype.setSkipAtEnd = function (count) {
        this.skipAtEnd = count;
    };
    EncoderContext.prototype.getCurrentChar = function () {
        return this.msg.charCodeAt(this.pos);
    };
    EncoderContext.prototype.getCurrent = function () {
        return this.msg.charCodeAt(this.pos);
    };
    EncoderContext.prototype.getCodewords = function () {
        return this.codewords;
    };
    EncoderContext.prototype.writeCodewords = function (codewords) {
        this.codewords.append(codewords);
    };
    EncoderContext.prototype.writeCodeword = function (codeword) {
        this.codewords.append(codeword);
    };
    EncoderContext.prototype.getCodewordCount = function () {
        return this.codewords.length();
    };
    EncoderContext.prototype.getNewEncoding = function () {
        return this.newEncoding;
    };
    EncoderContext.prototype.signalEncoderChange = function (encoding) {
        this.newEncoding = encoding;
    };
    EncoderContext.prototype.resetEncoderSignal = function () {
        this.newEncoding = -1;
    };
    EncoderContext.prototype.hasMoreCharacters = function () {
        return this.pos < this.getTotalMessageCharCount();
    };
    EncoderContext.prototype.getTotalMessageCharCount = function () {
        return this.msg.length - this.skipAtEnd;
    };
    EncoderContext.prototype.getRemainingCharacters = function () {
        return this.getTotalMessageCharCount() - this.pos;
    };
    EncoderContext.prototype.getSymbolInfo = function () {
        return this.symbolInfo;
    };
    EncoderContext.prototype.updateSymbolInfo = function (len) {
        if (len === void 0) { len = this.getCodewordCount(); }
        if (this.symbolInfo == null || len > this.symbolInfo.getDataCapacity()) {
            this.symbolInfo = SymbolInfo_1.default.lookup(len, this.shape, this.minSize, this.maxSize, true);
        }
    };
    EncoderContext.prototype.resetSymbolInfo = function () {
        this.symbolInfo = null;
    };
    return EncoderContext;
}());
exports.EncoderContext = EncoderContext;