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

Function md_join

internal/cbm/doclink_md.c:564–606  ·  view source on GitHub ↗

Split s[0..n) at every `sep`, check that each piece is an identifier (type * arguments dropped), and join the pieces with '.' in place. A first piece in * `skip_first` (Rust's `crate`, an instance's `self`) is dropped and *skipped * says so. False when a piece is no identifier or fewer than two remain. */

Source from the content-addressed store, hash-verified

562 * `skip_first` (Rust's `crate`, an instance's `self`) is dropped and *skipped
563 * says so. False when a piece is no identifier or fewer than two remain. */
564static bool md_join(char *s, size_t n, const char *sep, const char *const *skip_first,
565 bool *skipped, CBMDocLinkMdPath *out) {
566 size_t sl = strlen(sep);
567 size_t pieces = 0;
568 size_t w = 0;
569 size_t i = 0;
570 *skipped = false;
571 for (;;) {
572 size_t e = i;
573 while (e + sl <= n && memcmp(s + e, sep, sl) != 0) {
574 e++;
575 }
576 bool last_piece = e + sl > n;
577 if (last_piece) {
578 e = n;
579 }
580 size_t len = md_strip_generics(s + i, e - i);
581 if (pieces == 0 && !*skipped && skip_first && !last_piece &&
582 md_in_list(s + i, len, skip_first, false)) {
583 *skipped = true;
584 } else {
585 if (!md_ident(s + i, len)) {
586 return false;
587 }
588 if (w > 0) {
589 s[w++] = '.';
590 }
591 memmove(s + w, s + i, len);
592 w += len;
593 pieces++;
594 }
595 if (last_piece) {
596 break;
597 }
598 i = e + sl;
599 }
600 s[w] = '\0';
601 if (pieces < PAIR_LEN) {
602 return false;
603 }
604 md_shape(out, CBM_DOCLINK_MD_QUALIFIED, s, NULL, 0, 0);
605 return true;
606}
607
608/* `main.rs::run`: a file name with a member (an identifier). */
609static bool md_filename_member(char *s, char *sep, uint32_t first, uint32_t last,

Callers 1

md_classify_nameFunction · 0.85

Calls 4

md_strip_genericsFunction · 0.85
md_in_listFunction · 0.85
md_identFunction · 0.85
md_shapeFunction · 0.85

Tested by

no test coverage detected