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

Function lex_hstr

internal/cbm/pdf/pdf_obj.c:513–555  ·  view source on GitHub ↗

A hex string from data[i..] (after its "<"). */

Source from the content-addressed store, hash-verified

511
512/* A hex string from data[i..] (after its "<"). */
513static size_t lex_hstr(pdf_doc_t *d, const unsigned char *data, size_t len, size_t i,
514 pdf_tok_t *t) {
515 const unsigned char *gt = (const unsigned char *)memchr(data + i, '>', len - i);
516 size_t e = gt ? (size_t)(gt - data) : len;
517 t->kind = PT_STR;
518 size_t end = e < len ? e + 1 : len;
519 if (d->peek) {
520 t->s = NULL;
521 t->n = 0;
522 return end;
523 }
524 size_t nhex = 0;
525 for (size_t q = i; q < e; q++) {
526 nhex += hex_val(data[q]) >= 0;
527 }
528 unsigned char *o = (unsigned char *)pdf_alloc(d, (nhex + 1) / 2 + 1);
529 if (!o) {
530 t->s = (const unsigned char *)"";
531 t->n = 0;
532 return end;
533 }
534 size_t k = 0;
535 int hi = -1;
536 for (size_t q = i; q < e; q++) {
537 int v = hex_val(data[q]);
538 if (v < 0) {
539 continue;
540 }
541 if (hi < 0) {
542 hi = v;
543 } else {
544 o[k++] = (unsigned char)(hi * PDF_HEX_BASE + v);
545 hi = -1;
546 }
547 }
548 if (hi >= 0) {
549 o[k++] = (unsigned char)(hi * PDF_HEX_BASE);
550 }
551 o[k] = '\0';
552 t->s = o;
553 t->n = k;
554 return end;
555}
556
557void pdf_lex(pdf_doc_t *d, const unsigned char *data, size_t len, size_t *pos, pdf_tok_t *t) {
558 size_t p = *pos;

Callers 1

pdf_lexFunction · 0.85

Calls 2

pdf_allocFunction · 0.85
hex_valFunction · 0.70

Tested by

no test coverage detected