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

Function adr_fm_value

internal/cbm/doc_adr.c:277–322  ·  view source on GitHub ↗

The value of front-matter key `key` (a list joined with ", "), or NULL. */

Source from the content-addressed store, hash-verified

275
276/* The value of front-matter key `key` (a list joined with ", "), or NULL. */
277static char *adr_fm_value(CBMArena *a, const adr_lines_t *L, const char *key) {
278 size_t kl = strlen(key);
279 for (int k = SKIP_ONE; k < L->fm_end - SKIP_ONE; k++) {
280 const adr_line_t *l = &L->v[k];
281 if ((size_t)l->n <= kl || l->s[0] == ' ' || l->s[0] == '\t' ||
282 !adr_starts_ci(l->s, (size_t)l->n, key) || l->s[kl] != ':') {
283 continue;
284 }
285 const char *v = l->s + kl + SKIP_ONE;
286 size_t vn = (size_t)l->n - kl - SKIP_ONE;
287 adr_trim(&v, &vn);
288 if (vn > 0 && v[0] == '[' && v[vn - SKIP_ONE] == ']') {
289 v++;
290 vn -= PAIR_LEN;
291 }
292 if (vn > 0) {
293 return adr_plain(a, v, vn, ADR_FIELD_MAX);
294 }
295 /* a block list on the following lines */
296 char buf[ADR_FIELD_MAX + SKIP_ONE];
297 size_t w = 0;
298 for (int j = k + SKIP_ONE; j < L->fm_end - SKIP_ONE; j++) {
299 const adr_line_t *it = &L->v[j];
300 int i = 0;
301 while (i < it->n && adr_blank(it->s[i])) {
302 i++;
303 }
304 if (i == 0 || i >= it->n || it->s[i] != '-') {
305 break;
306 }
307 const char *iv = it->s + i + SKIP_ONE;
308 size_t ivn = (size_t)(it->n - i - SKIP_ONE);
309 adr_trim(&iv, &ivn);
310 if (ivn > 0 && w + ivn + PAIR_LEN < sizeof(buf)) {
311 if (w > 0) {
312 buf[w++] = ',';
313 buf[w++] = ' ';
314 }
315 memcpy(buf + w, iv, ivn);
316 w += ivn;
317 }
318 }
319 return w > 0 ? adr_plain(a, buf, w, ADR_FIELD_MAX) : NULL;
320 }
321 return NULL;
322}
323
324/* ── Headings (the file's Section definitions) ───────────────────── */
325

Callers 1

cbm_adr_extractFunction · 0.85

Calls 4

adr_starts_ciFunction · 0.85
adr_trimFunction · 0.85
adr_plainFunction · 0.85
adr_blankFunction · 0.85

Tested by

no test coverage detected