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

Function ts_doc_lines

internal/cbm/doclink_ts.c:178–226  ·  view source on GitHub ↗

The doc's lines, its opening and closing marks cut off. */

Source from the content-addressed store, hash-verified

176
177/* The doc's lines, its opening and closing marks cut off. */
178static int ts_doc_lines(CBMArena *a, const char *doc, uint32_t doc_line, ts_line_t **out) {
179 size_t dl = strlen(doc);
180 if (dl < TS_PREFIX_LEN || strncmp(doc, "/**", TS_PREFIX_LEN) != 0) {
181 return 0;
182 }
183 const char *b = doc + TS_PREFIX_LEN;
184 const char *e = doc + dl;
185 if (e - b >= PAIR_LEN && e[-SKIP_ONE] == '/' && e[-PAIR_LEN] == '*') {
186 e -= PAIR_LEN;
187 }
188 int cap = SKIP_ONE;
189 for (const char *p = b; p < e; p++) {
190 cap += *p == '\n';
191 }
192 ts_line_t *lines = (ts_line_t *)cbm_arena_alloc(a, (size_t)cap * sizeof(ts_line_t));
193 if (!lines) {
194 return 0;
195 }
196 int n = 0;
197 uint32_t line = doc_line;
198 for (const char *p = b; p <= e && n < cap;) {
199 const char *le = p;
200 while (le < e && *le != '\n') {
201 le++;
202 }
203 const char *s = p;
204 while (s < le && (*s == ' ' || *s == '\t')) {
205 s++;
206 }
207 if (s < le && *s == '*') {
208 s++;
209 if (s < le && *s == ' ') {
210 s++;
211 }
212 }
213 const char *t = le;
214 while (t > s && (t[-SKIP_ONE] == ' ' || t[-SKIP_ONE] == '\t' || t[-SKIP_ONE] == '\r')) {
215 t--;
216 }
217 lines[n++] = (ts_line_t){s, (size_t)(t - s), line};
218 line++;
219 if (le >= e) {
220 break;
221 }
222 p = le + SKIP_ONE;
223 }
224 *out = lines;
225 return n;
226}
227
228/* Mark the bytes of a line that sit in a code span (backticks paired on the
229 * line). */

Callers 1

cbm_doclink_ts_parse_docFunction · 0.85

Calls 1

cbm_arena_allocFunction · 0.70

Tested by

no test coverage detected