A page's docstring (its snippet): the page text, up to PDF_PAGE_DOC_MAX bytes * cut on a character boundary and then said so. A page holds a few kilobytes; * only a crafted text layer reaches the bound, and the mentions are still read * from the whole text. */
| 1327 | * only a crafted text layer reaches the bound, and the mentions are still read |
| 1328 | * from the whole text. */ |
| 1329 | static const char *page_doc(CBMArena *a, const cbm_pdf_page_t *pg) { |
| 1330 | if (pg->len <= PDF_PAGE_DOC_MAX) { |
| 1331 | return pg->text; |
| 1332 | } |
| 1333 | size_t cut = PDF_PAGE_DOC_MAX; |
| 1334 | while (cut > 0 && ((unsigned char)pg->text[cut] & 0xC0U) == 0x80U) { |
| 1335 | cut--; /* not inside a UTF-8 sequence */ |
| 1336 | } |
| 1337 | const char *doc = cbm_arena_sprintf(a, "%.*s\n[page text cut at %zu of %zu bytes]", (int)cut, |
| 1338 | pg->text, cut, pg->len); |
| 1339 | return doc ? doc : pg->text; |
| 1340 | } |
| 1341 | |
| 1342 | void cbm_pdf_extract_document(CBMExtractCtx *ctx) { |
| 1343 | CBMFileResult *result = ctx->result; |
no test coverage detected