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

Function php_doc_lines

internal/cbm/doclink_php.c:182–230  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 1

cbm_arena_allocFunction · 0.70

Tested by

no test coverage detected