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

Function csx_entity

internal/cbm/doclink_cs.c:3408–3440  ·  view source on GitHub ↗

The entity at src[i] ('&' stands there): its code point and the index past * it; 0 when there is none. */

Source from the content-addressed store, hash-verified

3406/* The entity at src[i] ('&' stands there): its code point and the index past
3407 * it; 0 when there is none. */
3408static uint32_t csx_entity(const csx_t *x, uint32_t i, uint32_t end, uint32_t *cp) {
3409 static const struct {
3410 const char *ent;
3411 char ch;
3412 } ents[] = {{"&lt;", '<'}, {"&gt;", '>'}, {"&amp;", '&'}, {"&quot;", '"'}, {"&apos;", '\''}};
3413 const char *s = x->src;
3414 for (size_t e = 0; e < sizeof(ents) / sizeof(ents[0]); e++) {
3415 size_t el = strlen(ents[e].ent);
3416 if (i + el <= end && memcmp(s + i, ents[e].ent, el) == 0) {
3417 *cp = (unsigned char)ents[e].ch;
3418 return i + (uint32_t)el;
3419 }
3420 }
3421 if (i + PAIR_LEN < end && s[i + SKIP_ONE] == '#') {
3422 bool hex = s[i + PAIR_LEN] == 'x' || s[i + PAIR_LEN] == 'X';
3423 uint32_t k = i + PAIR_LEN + (hex ? SKIP_ONE : 0);
3424 uint32_t v = 0;
3425 uint32_t digits = 0;
3426 while (k < end && digits < CBM_SZ_8 &&
3427 (hex ? isxdigit((unsigned char)s[k]) : isdigit((unsigned char)s[k]))) {
3428 unsigned char d = (unsigned char)s[k];
3429 uint32_t dv = isdigit(d) ? (uint32_t)(d - '0') : (uint32_t)(tolower(d) - 'a') + 10U;
3430 v = (v * (hex ? 16U : 10U)) + dv;
3431 k++;
3432 digits++;
3433 }
3434 if (digits > 0 && k < end && s[k] == ';' && v > 0 && v <= 0x10FFFF) {
3435 *cp = v;
3436 return k + SKIP_ONE;
3437 }
3438 }
3439 return 0;
3440}
3441
3442/* The bytes src[i, end) of a project file that start at i into sb: a
3443 * well-formed UTF-8 sequence as it stands, a byte that starts none as

Callers 1

csx_put_textFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected