UNPKG

typesxml

Version:

Open source XML library written in TypeScript

69 lines 2.57 kB
"use strict"; /******************************************************************************* * Copyright (c) 2023-2026 Maxprograms. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 1.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/org/documents/epl-v10.html * * Contributors: * Maxprograms - initial API and implementation *******************************************************************************/ Object.defineProperty(exports, "__esModule", { value: true }); exports.SchemaParticle = void 0; class SchemaParticle { minOccurs; maxOccurs; constructor(minOccurs = 1, maxOccurs = 1) { this.minOccurs = minOccurs; this.maxOccurs = maxOccurs; } matchRepeated(children, startPos, nsMap, childNamespaces) { const max = this.maxOccurs === 'unbounded' ? children.length + 1 : this.maxOccurs; let currentPositions = new Set([startPos]); const results = new Set(); if (this.minOccurs === 0) { results.add(startPos); } for (let count = 1; count <= max; count++) { const nextPositions = new Set(); for (const pos of currentPositions) { const matched = this.matchOnce(children, pos, nsMap, childNamespaces); for (const p of matched) { nextPositions.add(p); } } if (nextPositions.size === 0) { break; } if (count >= this.minOccurs) { for (const p of nextPositions) { results.add(p); } } // Only carry positions that made forward progress to avoid // infinite loops when a particle can match zero children. const advancingPositions = new Set(); for (const p of nextPositions) { let isNew = true; for (const cp of currentPositions) { if (cp === p) { isNew = false; break; } } if (isNew) { advancingPositions.add(p); } } if (advancingPositions.size === 0) { break; } currentPositions = advancingPositions; } return Array.from(results); } } exports.SchemaParticle = SchemaParticle; //# sourceMappingURL=SchemaParticle.js.map