MCPcopy Create free account
hub / github.com/LibPDF-js/core / readLiteralString

Method readLiteralString

src/parser/token-reader.ts:377–447  ·  view source on GitHub ↗
(position: number)

Source from the content-addressed store, hash-verified

375 }
376
377 private readLiteralString(position: number): StringToken {
378 // Skip opening (
379 this.scanner.advance();
380
381 const bytes: number[] = [];
382 let parenDepth = 1;
383
384 while (parenDepth > 0) {
385 const byte = this.scanner.peek();
386
387 if (byte === -1) {
388 // Unterminated string - return what we have
389 break;
390 }
391
392 this.scanner.advance();
393
394 if (byte === CHAR_PARENTHESIS_OPEN) {
395 // Nested (
396 parenDepth++;
397 bytes.push(byte);
398 continue;
399 }
400
401 if (byte === CHAR_PARENTHESIS_CLOSE) {
402 // Closing )
403 parenDepth--;
404
405 if (parenDepth > 0) {
406 bytes.push(byte);
407 }
408
409 continue;
410 }
411
412 if (byte === CHAR_BACKSLASH) {
413 // Escape sequence
414 const escaped = this.readEscapeSequence();
415
416 if (escaped !== null) {
417 if (Array.isArray(escaped)) {
418 bytes.push(...escaped);
419 } else {
420 bytes.push(escaped);
421 }
422 }
423
424 continue;
425 }
426
427 // Normalize line endings to LF
428 if (byte === CR) {
429 // Check for CRLF
430 if (this.scanner.peek() === LF) {
431 this.scanner.advance();
432 }
433
434 bytes.push(LF);

Callers 1

readTokenMethod · 0.95

Calls 4

readEscapeSequenceMethod · 0.95
advanceMethod · 0.80
pushMethod · 0.80
peekMethod · 0.45

Tested by

no test coverage detected