UNPKG

jspurefix

Version:
92 lines 3.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SegmentDescription = void 0; const definition_1 = require("../../dictionary/definition"); const segment_type_1 = require("./segment-type"); const elastic_buffer_1 = require("../elastic-buffer"); class SegmentDescription { constructor(name, startTag, set, startPosition, depth, type) { this.name = name; this.startTag = startTag; this.set = set; this.startPosition = startPosition; this.depth = depth; this.type = type; this.endTag = 0; this.endPosition = 0; this.delimiterTag = 0; } toString() { var _a; const buffer = new elastic_buffer_1.ElasticBuffer(); buffer.writeString(`name = ${this.name}, `); buffer.writeString(`startTag = ${this.startTag}, `); buffer.writeString(`startPosition = ${this.startPosition}, `); buffer.writeString(`type = ${this.type}, `); buffer.writeString(`depth = ${this.depth}, `); buffer.writeString(`index = ${this.index}, `); buffer.writeString(`endTag = ${this.endTag}, `); buffer.writeString(`endPosition = ${this.endPosition}, `); buffer.writeString(`delimiterTag = ${this.delimiterTag}, `); buffer.writeString(`delimiterPositions = ${this.delimiterPositions}, `); buffer.writeString(`currentField = ${this.currentField}, `); buffer.writeString(`set = ${(_a = this.set) === null || _a === void 0 ? void 0 : _a.keys()}`); return buffer.toString(); } contains(segment) { return segment.startPosition >= this.startPosition && segment.endPosition <= this.endPosition; } getInstance(instance) { var _a, _b, _c, _d; const delimiters = this.delimiterPositions; if (!delimiters) { return null; } if (instance < 0 || instance >= delimiters.length) { return null; } const start = delimiters[instance]; const end = instance < delimiters.length - 1 ? delimiters[instance + 1] - 1 : this.endPosition; const name = this.type === segment_type_1.SegmentType.Batch ? (_b = (_a = this.set) === null || _a === void 0 ? void 0 : _a.abbreviation) !== null && _b !== void 0 ? _b : this.name : (_d = (_c = this.name) !== null && _c !== void 0 ? _c : this.name) !== null && _d !== void 0 ? _d : 'na'; const d = new SegmentDescription(name, this.startTag, this.set, start, this.depth, this.type); d.endPosition = end; d.endTag = this.endTag; return d; } startGroup(tag) { this.delimiterTag = tag; this.delimiterPositions = []; this.containedDelimiterPositions = {}; } addDelimiterPosition(position) { if (this.containedDelimiterPositions[position]) { return false; } this.delimiterPositions[this.delimiterPositions.length] = position; this.containedDelimiterPositions[position] = true; return true; } setCurrentField(tag) { var _a, _b, _c, _d; this.currentField = (_d = (_b = (_a = this.set) === null || _a === void 0 ? void 0 : _a.localTag[tag]) !== null && _b !== void 0 ? _b : (_c = this.set) === null || _c === void 0 ? void 0 : _c.tagToField[tag]) !== null && _d !== void 0 ? _d : null; } groupAddDelimiter(tag, position) { let delimiter = false; if (this.set instanceof definition_1.GroupFieldDefinition) { if (this.delimiterTag && tag === this.delimiterTag) { delimiter = this.addDelimiterPosition(position); } } return delimiter; } end(i, pos, endTag) { this.index = i; this.currentField = null; this.endPosition = pos; this.endTag = endTag; } } exports.SegmentDescription = SegmentDescription; //# sourceMappingURL=segment-description.js.map