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

Function md_classify_path

internal/cbm/doclink_md.c:466–555  ·  view source on GitHub ↗

The path branch: `s` has a slash (or a Windows path with an extension). */

Source from the content-addressed store, hash-verified

464
465/* The path branch: `s` has a slash (or a Windows path with an extension). */
466static bool md_classify_path(char *s, size_t n, CBMDocLinkMdPath *out) {
467 for (size_t i = 0; i < n; i++) {
468 if (s[i] == '\\') {
469 s[i] = '/';
470 }
471 }
472 if (n >= PAIR_LEN && s[0] == '/' && s[SKIP_ONE] == '/') {
473 return false;
474 }
475 uint32_t first = 0;
476 uint32_t last = 0;
477 (void)md_line_suffix(s, &n, &first, &last);
478 s[n] = '\0';
479 const char *member = NULL;
480 char *sep = strstr(s, "::");
481 if (sep) {
482 *sep = '\0';
483 member = sep + PAIR_LEN;
484 n = (size_t)(sep - s);
485 if (!member[0]) {
486 member = NULL;
487 }
488 }
489 if (n == 0) {
490 return false;
491 }
492 bool named = false;
493 for (size_t i = 0; i < n && !named; i++) {
494 named = md_word((unsigned char)s[i]);
495 }
496 if (!named) {
497 return false; /* `../`, `./`, `/`: a traversal or a root, naming no directory */
498 }
499 /* an import path (`github.com/x/y`, `k8s.io/client-go`): a host-like first
500 * segment -- dot-separated word groups -- and a last segment (as written,
501 * a trailing slash leaves it empty) without a file extension */
502 size_t host = 0;
503 while (host < n && s[host] != '/') {
504 host++;
505 }
506 bool hostlike = host > 0 && host < n && md_has(s, host, '.') && md_all_of(s, host, ".-") &&
507 s[0] != '.' && s[host - SKIP_ONE] != '.';
508 for (size_t i = 0; hostlike && i + SKIP_ONE < host; i++) {
509 hostlike = !(s[i] == '.' && s[i + SKIP_ONE] == '.');
510 }
511 size_t tail = n;
512 while (tail > 0 && s[tail - SKIP_ONE] != '/') {
513 tail--;
514 }
515 if (hostlike && !md_ext_ok(s + tail, n - tail)) {
516 return false;
517 }
518 /* the base name, after any trailing slashes */
519 size_t end = n;
520 while (end > 0 && s[end - SKIP_ONE] == '/') {
521 end--;
522 }
523 size_t base = end;

Callers 1

Calls 8

md_line_suffixFunction · 0.85
md_wordFunction · 0.85
md_hasFunction · 0.85
md_all_ofFunction · 0.85
md_ext_okFunction · 0.85
md_shapeFunction · 0.85
md_identFunction · 0.85
md_in_listFunction · 0.85

Tested by

no test coverage detected