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

Function rs_doc_lines

internal/cbm/doclink_rs.c:686–740  ·  view source on GitHub ↗

Split the stored doc text into Markdown lines. NULL (and *out_n 0) when it * is no rustdoc comment or memory ran out. */

Source from the content-addressed store, hash-verified

684/* Split the stored doc text into Markdown lines. NULL (and *out_n 0) when it
685 * is no rustdoc comment or memory ran out. */
686static rs_line_t *rs_doc_lines(CBMArena *a, const char *doc, uint32_t doc_line, int *out_n) {
687 *out_n = 0;
688 int style = rs_doc_style(doc);
689 if (style == RS_DOC_NONE) {
690 return NULL;
691 }
692 size_t total = strlen(doc);
693 const char *body = doc;
694 if (style == RS_DOC_BLOCK) {
695 while (total > 0 && isspace((unsigned char)doc[total - SKIP_ONE])) {
696 total--;
697 }
698 if (total >= RS_MARK_LEN + PAIR_LEN && doc[total - PAIR_LEN] == '*' &&
699 doc[total - SKIP_ONE] == '/') {
700 total -= PAIR_LEN;
701 }
702 }
703 int count = SKIP_ONE;
704 for (size_t i = 0; i < total; i++) {
705 count += doc[i] == '\n';
706 }
707 rs_line_t *lines = (rs_line_t *)cbm_arena_alloc(a, (size_t)count * sizeof(rs_line_t));
708 if (!lines) {
709 return NULL;
710 }
711 int n = 0;
712 size_t start = 0;
713 for (size_t i = 0; i <= total && n < count; i++) {
714 if (i < total && body[i] != '\n') {
715 continue;
716 }
717 size_t end = i;
718 while (end > start && body[end - SKIP_ONE] == '\r') {
719 end--;
720 }
721 lines[n] = (rs_line_t){.p = body + start,
722 .len = (uint32_t)(end - start),
723 .line = doc_line + (uint32_t)n,
724 .kind = RS_L_BLANK};
725 n++;
726 start = i + SKIP_ONE;
727 }
728 if (style == RS_DOC_LINE) {
729 for (int i = 0; i < n; i++) {
730 rs_line_content(&lines[i]);
731 }
732 } else {
733 lines[0].p += RS_MARK_LEN;
734 lines[0].len = lines[0].len >= RS_MARK_LEN ? lines[0].len - RS_MARK_LEN : 0;
735 rs_block_stars(lines, n);
736 }
737 rs_unindent(lines, n);
738 *out_n = n;
739 return lines;
740}
741
742/* text[0..*n) without the white space at both ends. */
743static const char *rs_trimmed(const char *text, size_t *n) {

Callers 1

rs_parse_textFunction · 0.85

Calls 5

rs_doc_styleFunction · 0.85
rs_line_contentFunction · 0.85
rs_block_starsFunction · 0.85
rs_unindentFunction · 0.85
cbm_arena_allocFunction · 0.70

Tested by

no test coverage detected