Skip to content

Commit 145e229

Browse files
committed
Updating example elements in README and tests; remove unused readUntil method from xmlParser
1 parent 67b8824 commit 145e229

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ The following XML:
2424
<?xml version="1.0" encoding="UTF-8"?>
2525
<root>
2626
<!-- my comment -->
27-
<element attribute="value" />
28-
<element attribute='value'></element>
27+
<self-closing attribute="value with double quotes" />
28+
<non-self-closing attribute='value with single quotes'></non-self-closing>
29+
<element-with-cdata><![CDATA[<html>]]></element-with-cdata>
2930
</root>
3031
```
3132

@@ -39,9 +40,11 @@ new XmlDocument([
3940
new XmlText('\n '),
4041
new XmlComment(' my comment '),
4142
new XmlText('\n '),
42-
new XmlElement('element', [new XmlAttribute('attribute', 'value')], [], ' ', true),
43+
new XmlElement('self-closing', [new XmlAttribute('attribute', 'value with double quotes')], [], ' ', true),
4344
new XmlText('\n '),
44-
new XmlElement('element', [new XmlAttribute('attribute', 'value', ' ', '', '', "'")], [], '', false),
45+
new XmlElement('non-self-closing', [new XmlAttribute('attribute', 'value with single quotes', ' ', '', '', "'")], [], '', false),
46+
new XmlText('\n '),
47+
new XmlElement('element-with-cdata', [], [new XmlCData('<html>')]),
4548
new XmlText('\n')
4649
])
4750
]);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"test": "bun test --coverage",
2020
"format": "prettier --write .",
2121
"typecheck": "tsc --noEmit",
22-
"prepack": "bun run build:types && bun run build:esm && bun run build:cjs",
22+
"prepack": "bun run build:types && bun run build:esm && bun run build:cjs"
2323
},
2424
"keywords": [
2525
"XML",

xmlParser.spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { XmlAttribute } from './model/xmlAttribute';
66
import { XmlElement } from './model/xmlElement';
77
import { XmlParser } from './xmlParser';
88
import { XmlDocument } from './model/xmlDocument';
9+
import { XmlCData } from './model/xmlCData';
910

1011
describe('XmlParser', () => {
1112
describe('parse', () => {
@@ -28,8 +29,9 @@ describe('XmlParser', () => {
2829
const xml = `<?xml version="1.0" encoding="UTF-8"?>
2930
<root>
3031
<!-- my comment -->
31-
<element attribute="value" />
32-
<element attribute='value'></element>
32+
<self-closing attribute="value with double quotes" />
33+
<non-self-closing attribute='value with single quotes'></non-self-closing>
34+
<element-with-cdata><![CDATA[<html>]]></element-with-cdata>
3335
</root>`;
3436
const doc = XmlParser.parse(xml);
3537
expect(doc).toEqual(new XmlDocument([
@@ -39,9 +41,11 @@ describe('XmlParser', () => {
3941
new XmlText('\n '),
4042
new XmlComment(' my comment '),
4143
new XmlText('\n '),
42-
new XmlElement('element', [new XmlAttribute('attribute', 'value')], [], ' ', true),
44+
new XmlElement('self-closing', [new XmlAttribute('attribute', 'value with double quotes')], [], ' ', true),
4345
new XmlText('\n '),
44-
new XmlElement('element', [new XmlAttribute('attribute', 'value', ' ', '', '', "'")], [], '', false),
46+
new XmlElement('non-self-closing', [new XmlAttribute('attribute', 'value with single quotes', ' ', '', '', "'")], [], '', false),
47+
new XmlText('\n '),
48+
new XmlElement('element-with-cdata', [], [new XmlCData('<html>')]),
4549
new XmlText('\n')
4650
])
4751
]));

xmlParser.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,18 +267,6 @@ export class XmlParser {
267267
return this.input.substring(start, this.pos);
268268
}
269269

270-
// Reads until the given pattern is matched.
271-
readUntil(pattern: RegExp): string {
272-
const start = this.pos;
273-
while (
274-
this.pos < this.input.length &&
275-
!pattern.test(this.input[this.pos])
276-
) {
277-
this.pos++;
278-
}
279-
return this.input.substring(start, this.pos);
280-
}
281-
282270
// Helper: check if input at current position starts with any string in the list.
283271
startsWithAny(strings: string[]): boolean {
284272
for (const s of strings) {

0 commit comments

Comments
 (0)