typesxml
Version:
Open source XML library written in TypeScript
69 lines • 2.8 kB
JavaScript
;
/*******************************************************************************
* 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.SchemaAll = void 0;
const SchemaParticle_js_1 = require("./SchemaParticle.js");
class SchemaAll extends SchemaParticle_js_1.SchemaParticle {
particles;
constructor(particles, minOccurs = 1, maxOccurs = 1) {
super(minOccurs, maxOccurs);
this.particles = particles;
}
matchOnce(children, pos, nsMap, childNamespaces) {
const indices = [];
for (let i = 0; i < this.particles.length; i++) {
indices.push(i);
}
return this.matchRemaining(children, pos, indices, nsMap, childNamespaces);
}
matchRemaining(children, pos, remaining, nsMap, childNamespaces) {
const results = new Set();
// All remaining particles optional → current position is a valid end.
let allOptional = true;
for (let i = 0; i < remaining.length; i++) {
if (this.particles[remaining[i]].minOccurs > 0) {
allOptional = false;
break;
}
}
if (allOptional || remaining.length === 0) {
results.add(pos);
}
if (pos >= children.length || remaining.length === 0) {
return Array.from(results);
}
for (let i = 0; i < remaining.length; i++) {
const idx = remaining[i];
const particle = this.particles[idx];
const matched = particle.matchRepeated(children, pos, nsMap, childNamespaces);
for (const nextPos of matched) {
if (nextPos > pos) {
// Remove slot i from remaining and recurse.
const newRemaining = [];
for (let j = 0; j < remaining.length; j++) {
if (j !== i) {
newRemaining.push(remaining[j]);
}
}
const further = this.matchRemaining(children, nextPos, newRemaining, nsMap, childNamespaces);
for (const p of further) {
results.add(p);
}
}
}
}
return Array.from(results);
}
}
exports.SchemaAll = SchemaAll;
//# sourceMappingURL=SchemaAll.js.map