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

Function dg_class_relation

internal/cbm/diagram.c:733–774  ·  view source on GitHub ↗

`A "1" op "*" B : label`: the relation of a class line, false when none. */

Source from the content-addressed store, hash-verified

731
732/* `A "1" op "*" B : label`: the relation of a class line, false when none. */
733static bool dg_class_relation(dg_t *dg, dg_str_t ln, uint32_t line) {
734 const char *colon = NULL;
735 bool quoted = false;
736 for (size_t i = 0; i < ln.n && !colon; i++) {
737 quoted = ln.p[i] == '"' ? !quoted : quoted;
738 colon = !quoted && ln.p[i] == ':' ? ln.p + i : NULL;
739 }
740 dg_str_t head = colon ? dg_s(ln.p, (size_t)(colon - ln.p)) : ln;
741 for (int k = 0; DG_CLASS_RELS[k].op; k++) {
742 size_t ol = strlen(DG_CLASS_RELS[k].op);
743 for (size_t i = 0; i + ol <= head.n; i++) {
744 if (memcmp(head.p + i, DG_CLASS_RELS[k].op, ol) != 0) {
745 continue;
746 }
747 dg_str_t l = dg_trim(dg_s(head.p, i));
748 dg_str_t r = dg_trim(dg_s(head.p + i + ol, head.n - i - ol));
749 if (l.n && l.p[l.n - SKIP_ONE] == '"') { /* a cardinality */
750 const char *q = memchr(l.p, '"', l.n - SKIP_ONE);
751 l = q ? dg_trim(dg_s(l.p, (size_t)(q - l.p))) : l;
752 }
753 if (r.n && r.p[0] == '"') {
754 const char *q = memchr(r.p + SKIP_ONE, '"', r.n - SKIP_ONE);
755 r = q ? dg_trim(dg_s(q + SKIP_ONE, (size_t)(r.p + r.n - q) - SKIP_ONE)) : r;
756 }
757 if (!l.n || !r.n) {
758 return false;
759 }
760 dg_str_t label = colon
761 ? dg_s(colon + SKIP_ONE, (size_t)(ln.p + ln.n - colon) - SKIP_ONE)
762 : dg_s(NULL, 0);
763 dg_element(dg, l, dg_s(NULL, 0), "class", line);
764 dg_element(dg, r, dg_s(NULL, 0), "class", line);
765 if (DG_CLASS_RELS[k].to_left) {
766 dg_arrow(dg, r, l, label, DG_CLASS_RELS[k].style, line);
767 } else {
768 dg_arrow(dg, l, r, label, DG_CLASS_RELS[k].style, line);
769 }
770 return true;
771 }
772 }
773 return false;
774}
775
776/* The name of `class Name~T~["Label"] {`, its label in *label. */
777static dg_str_t dg_class_decl(dg_str_t rest, dg_str_t *label) {

Callers 1

dg_classdiagramFunction · 0.85

Calls 4

dg_sFunction · 0.85
dg_trimFunction · 0.85
dg_elementFunction · 0.85
dg_arrowFunction · 0.85

Tested by

no test coverage detected