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

Function dg_shape

internal/cbm/diagram.c:368–402  ·  view source on GitHub ↗

The closing bracket of a node shape opened at s[i]: the shape's text in * *label, the position after it. */

Source from the content-addressed store, hash-verified

366/* The closing bracket of a node shape opened at s[i]: the shape's text in
367 * *label, the position after it. */
368static size_t dg_shape(dg_str_t s, size_t i, dg_str_t *label) {
369 static const char *const opens[] = {"(((", "([", "[[", "[(", "((", "{{", "[/",
370 "[\\", "[", "(", "{", ">", NULL};
371 static const char *const closes[] = {")))", "])", "]]", ")]", "))", "}}", "/]",
372 "\\]", "]", ")", "}", "]", NULL};
373 for (int k = 0; opens[k]; k++) {
374 size_t ol = strlen(opens[k]);
375 if (i + ol > s.n || memcmp(s.p + i, opens[k], ol) != 0) {
376 continue;
377 }
378 size_t cl = strlen(closes[k]);
379 bool quoted = false;
380 for (size_t j = i + ol; j + cl <= s.n; j++) {
381 if (s.p[j] == '"') {
382 quoted = !quoted;
383 }
384 if (!quoted && memcmp(s.p + j, closes[k], cl) == 0) {
385 *label = dg_s(s.p + i + ol, j - i - ol);
386 return j + cl;
387 }
388 }
389 /* `[/text\]` and `[\text/]` close with the other slash */
390 if (k == CBM_SZ_6 || k == CBM_SZ_7) {
391 const char *alt = k == CBM_SZ_6 ? "\\]" : "/]";
392 for (size_t j = i + ol; j + PAIR_LEN <= s.n; j++) {
393 if (memcmp(s.p + j, alt, PAIR_LEN) == 0) {
394 *label = dg_s(s.p + i + ol, j - i - ol);
395 return j + PAIR_LEN;
396 }
397 }
398 }
399 return i;
400 }
401 return i;
402}
403
404/* A node at s[i]: its id and label; the position after it (i when none). */
405static size_t dg_flow_node(dg_str_t s, size_t i, dg_str_t *id, dg_str_t *label) {

Callers 2

dg_flow_nodeFunction · 0.85
dg_flow_statementFunction · 0.85

Calls 1

dg_sFunction · 0.85

Tested by

no test coverage detected