(position: number)
| 528 | } |
| 529 | |
| 530 | private readHexString(position: number): StringToken { |
| 531 | const bytes: number[] = []; |
| 532 | let pendingNibble: number | null = null; |
| 533 | |
| 534 | while (true) { |
| 535 | const byte = this.scanner.peek(); |
| 536 | |
| 537 | if (byte === -1 || byte === CHAR_ANGLE_BRACKET_CLOSE) { |
| 538 | // EOF or > |
| 539 | if (byte === CHAR_ANGLE_BRACKET_CLOSE) { |
| 540 | this.scanner.advance(); |
| 541 | } |
| 542 | |
| 543 | break; |
| 544 | } |
| 545 | |
| 546 | this.scanner.advance(); |
| 547 | |
| 548 | // Skip whitespace inside hex string |
| 549 | if (WHITESPACE.has(byte)) { |
| 550 | continue; |
| 551 | } |
| 552 | |
| 553 | if (isHexDigit(byte)) { |
| 554 | const nibble = hexValue(byte); |
| 555 | |
| 556 | if (pendingNibble === null) { |
| 557 | pendingNibble = nibble; |
| 558 | } else { |
| 559 | bytes.push((pendingNibble << 4) | nibble); |
| 560 | pendingNibble = null; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | // Invalid character - skip with warning (lenient) |
| 565 | // TODO: Add warning callback |
| 566 | } |
| 567 | |
| 568 | // Odd number of hex digits - pad with 0 |
| 569 | if (pendingNibble !== null) { |
| 570 | bytes.push(pendingNibble << 4); |
| 571 | } |
| 572 | |
| 573 | return { |
| 574 | type: "string", |
| 575 | value: new Uint8Array(bytes), |
| 576 | format: "hex", |
| 577 | position, |
| 578 | }; |
| 579 | } |
| 580 | |
| 581 | private readClosingAngle(position: number): DelimiterToken { |
| 582 | this.scanner.advance(); // Skip first > |
no test coverage detected