MCPcopy Create free account
hub / github.com/denoland/std / AttributeIteratorImpl

Class AttributeIteratorImpl

xml/_parser.ts:55–120  ·  view source on GitHub ↗

* Reusable attribute iterator implementation. * * This class reuses internal arrays across elements to avoid allocations. * The iterator is valid only until the next element is processed.

Source from the content-addressed store, hash-verified

53 * The iterator is valid only until the next element is processed.
54 */
55class AttributeIteratorImpl implements XmlAttributeIterator {
56 #names: string[] = [];
57 #values: string[] = [];
58 #colonIndices: number[] = [];
59 #uris: (string | undefined)[] = [];
60 #count = 0;
61 #nameSet: Set<string> | null = null;
62
63 get count(): number {
64 return this.#count;
65 }
66
67 getName(index: number): string {
68 return this.#names[index]!;
69 }
70
71 getValue(index: number): string {
72 return this.#values[index]!;
73 }
74
75 getColonIndex(index: number): number {
76 return this.#colonIndices[index]!;
77 }
78
79 getUri(index: number): string | undefined {
80 return this.#uris[index];
81 }
82
83 /** @internal Reset the iterator for a new element. */
84 _reset(): void {
85 this.#count = 0;
86 this.#nameSet = null;
87 }
88
89 /** @internal Add an attribute (name already decoded, value raw). */
90 _add(name: string, value: string, xml11: boolean): void {
91 this.#names[this.#count] = name;
92 this.#values[this.#count] = normalizeAttributeValue(value, xml11);
93 this.#colonIndices[this.#count] = name.indexOf(":");
94 this.#uris[this.#count] = undefined;
95 this.#nameSet?.add(name);
96 this.#count++;
97 }
98
99 /** @internal Set the URI for an attribute at the given index. */
100 _setUri(index: number, uri: string | undefined): void {
101 this.#uris[index] = uri;
102 }
103
104 /** @internal Check if an attribute with this name already exists. */
105 _has(name: string): boolean {
106 if (this.#count < ATTR_SET_THRESHOLD) {
107 for (let i = 0; i < this.#count; i++) {
108 if (this.#names[i] === name) return true;
109 }
110 return false;
111 }
112 if (!this.#nameSet) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected