MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / lex_lstr

Function lex_lstr

internal/cbm/pdf/pdf_obj.c:417–510  ·  view source on GitHub ↗

A literal string from data[i..] (after its "("); returns the position after it. */

Source from the content-addressed store, hash-verified

415
416/* A literal string from data[i..] (after its "("); returns the position after it. */
417static size_t lex_lstr(pdf_doc_t *d, const unsigned char *data, size_t len, size_t i,
418 pdf_tok_t *t) {
419 int depth = 1;
420 size_t k = 0;
421 bool keep = !d->peek;
422 size_t end = len;
423 t->kind = PT_STR;
424 for (;;) {
425 size_t j = i;
426 while (j < len && !lstr_special(data[j])) {
427 j++;
428 }
429 if (keep && j > i) {
430 if (!pdf_scratch(d, k + (j - i) + PDF_OCT_DIGITS + 1)) {
431 keep = false;
432 } else {
433 memcpy(d->scratch + k, data + i, j - i);
434 k += j - i;
435 }
436 }
437 if (j >= len) {
438 end = len;
439 break;
440 }
441 if (keep && !pdf_scratch(d, k + 2)) {
442 keep = false;
443 }
444 unsigned char c = data[j];
445 int out = -1;
446 if (c == '\\') {
447 if (j + 1 >= len) {
448 end = len;
449 break;
450 }
451 unsigned char nx = data[j + 1];
452 static const char esc_from[] = "nrtbf()\\";
453 static const char esc_to[] = "\n\r\t\b\f()\\";
454 const char *e = (nx != 0) ? strchr(esc_from, nx) : NULL;
455 if (e) {
456 out = (unsigned char)esc_to[e - esc_from];
457 i = j + 2;
458 } else if (nx >= '0' && nx <= '7') {
459 size_t q = j + 1;
460 unsigned v = 0;
461 while (q < len && q < j + 1 + PDF_OCT_DIGITS && data[q] >= '0' && data[q] <= '7') {
462 v = v * PDF_BITS_PER_BYTE + (unsigned)(data[q] - '0');
463 q++;
464 }
465 out = (int)(v & 0xFFU);
466 i = q;
467 } else if (nx == '\r') {
468 i = (j + 2 < len && data[j + 2] == '\n') ? j + 3 : j + 2;
469 } else if (nx == '\n') {
470 i = j + 2;
471 } else {
472 out = nx;
473 i = j + 2;
474 }

Callers 1

pdf_lexFunction · 0.85

Calls 3

lstr_specialFunction · 0.85
pdf_scratchFunction · 0.85
pdf_allocFunction · 0.85

Tested by

no test coverage detected