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

Function rs_strip_segment

internal/cbm/doclink_rs.c:371–405  ·  view source on GitHub ↗

One `::`-separated piece with its generics removed, appended to `out` * (joined by `::`). false when the angle brackets do not balance or hold * fully-qualified syntax (` `). */

Source from the content-addressed store, hash-verified

369 * (joined by `::`). false when the angle brackets do not balance or hold
370 * fully-qualified syntax (`<T as Trait>`). */
371static bool rs_strip_segment(const char *seg, size_t n, char *out, size_t *w) {
372 static const char as_kw[] = " as ";
373 const size_t as_len = sizeof(as_kw) - SKIP_ONE;
374 int depth = 0;
375 size_t start = *w;
376 size_t chunk = 0; /* start of the innermost generics text read so far */
377 if (start > 0) {
378 out[(*w)++] = ':';
379 out[(*w)++] = ':';
380 }
381 size_t body = *w;
382 for (size_t i = 0; i < n; i++) {
383 char c = seg[i];
384 if (c == '<') {
385 depth++;
386 chunk = i + SKIP_ONE;
387 } else if (c == '>') {
388 depth--;
389 for (size_t k = chunk; k + as_len <= i; k++) {
390 if (memcmp(seg + k, as_kw, as_len) == 0) {
391 return false;
392 }
393 }
394 } else if (depth == 0) {
395 out[(*w)++] = c;
396 }
397 }
398 if (depth != 0) {
399 return false;
400 }
401 if (*w == body) {
402 *w = start; /* nothing left of it: no separator either */
403 }
404 return true;
405}
406
407/* rustdoc's strip_generics_from_path, in place: `Vec<T>::new` -> `Vec::new`.
408 * false for malformed generics. A path without angle brackets is left as it

Callers 1

rs_strip_genericsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected