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

Function pl_entity_number

internal/cbm/doclink_perl.c:347–370  ·  view source on GitHub ↗

The number an E<> body writes (decimal, 0x hex, 0 octal); false for a name. */

Source from the content-addressed store, hash-verified

345
346/* The number an E<> body writes (decimal, 0x hex, 0 octal); false for a name. */
347static bool pl_entity_number(const char *e, size_t n, unsigned long *cp) {
348 enum { DEC = 10, HEX = 16, OCT = 8 };
349 int base = DEC;
350 size_t i = 0;
351 if (n > PAIR_LEN && e[0] == '0' && (e[1] == 'x' || e[1] == 'X')) {
352 base = HEX;
353 i = PAIR_LEN;
354 } else if (n > SKIP_ONE && e[0] == '0') {
355 base = OCT;
356 i = SKIP_ONE;
357 }
358 unsigned long v = 0;
359 for (; i < n; i++) {
360 int d = isdigit((unsigned char)e[i]) ? e[i] - '0'
361 : isxdigit((unsigned char)e[i]) ? tolower((unsigned char)e[i]) - 'a' + DEC
362 : base;
363 if (d >= base) {
364 return false;
365 }
366 v = (v * (unsigned long)base) + (unsigned long)d;
367 }
368 *cp = v;
369 return n > 0;
370}
371
372/* Append what E<body> renders; an unknown body stays as written. */
373static void pl_out_entity(pl_out_t *o, const char *body, size_t n, bool closed) {

Callers 1

pl_out_entityFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected