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

Function md_classify_name

internal/cbm/doclink_md.c:664–763  ·  view source on GitHub ↗

No slash: a file name, a special file, `file.ext::member`, or a qualified * name. A bare name is neither: at most a suggestion, never a link. */

Source from the content-addressed store, hash-verified

662/* No slash: a file name, a special file, `file.ext::member`, or a qualified
663 * name. A bare name is neither: at most a suggestion, never a link. */
664static bool md_classify_name(char *s, size_t n, CBMDocLinkMdPath *out) {
665 if (md_in_list(s, n, MD_SPECIAL_FILES, false)) {
666 md_shape(out, CBM_DOCLINK_MD_FILENAME, s, NULL, 0, 0);
667 return true;
668 }
669 uint32_t first = 0;
670 uint32_t last = 0;
671 size_t cut = n;
672 if (md_line_suffix(s, &cut, &first, &last)) {
673 const char *dot = NULL;
674 for (size_t i = cut; i > 0; i--) {
675 if (s[i - SKIP_ONE] == '.') {
676 dot = s + i - SKIP_ONE;
677 break;
678 }
679 }
680 size_t ext_len = dot ? cut - (size_t)(dot - s) - SKIP_ONE : 0;
681 if (dot && md_in_list(dot + SKIP_ONE, ext_len, MD_FILE_EXT, true)) {
682 n = cut;
683 s[n] = '\0';
684 } else {
685 first = 0;
686 last = 0;
687 }
688 }
689 bool skipped = false;
690 if (strstr(s, "::")) {
691 /* identifiers only: a qualified name; otherwise perhaps `file.ext::member` */
692 char copy[MD_SPAN_MAX + SKIP_ONE];
693 memcpy(copy, s, n + SKIP_ONE);
694 if (md_join(s, n, "::", MD_RUST_ROOTS, &skipped, out)) {
695 return true;
696 }
697 memcpy(s, copy, n + SKIP_ONE);
698 return md_filename_member(s, strstr(s, "::"), first, last, out);
699 }
700 if (md_has(s, n, '#')) {
701 if (!md_head_mark_tail(s, n, '#', false)) {
702 return false;
703 }
704 s[strcspn(s, "#")] = '.';
705 return md_join(s, n, ".", NULL, &skipped, out);
706 }
707 if (md_has(s, n, '\\')) {
708 while (n > 0 && s[n - SKIP_ONE] == '\\') {
709 n--;
710 }
711 size_t lead = 0;
712 while (lead < n && s[lead] == '\\') {
713 lead++;
714 }
715 return md_join(s + lead, n - lead, "\\", NULL, &skipped, out);
716 }
717 if (md_has(s, n, ':')) {
718 if (!md_head_mark_tail(s, n, ':', true)) {
719 return false;
720 }
721 s[strcspn(s, ":")] = '.';

Callers 1

Calls 10

md_in_listFunction · 0.85
md_shapeFunction · 0.85
md_line_suffixFunction · 0.85
md_joinFunction · 0.85
md_filename_memberFunction · 0.85
md_hasFunction · 0.85
md_head_mark_tailFunction · 0.85
md_identFunction · 0.85
md_all_ofFunction · 0.85
md_eq_ciFunction · 0.85

Tested by

no test coverage detected