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

Function parse_line_directive

internal/cbm/preprocessor.cpp:332–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

330}
331
332static bool parse_line_directive(const char *line, size_t len, uint32_t *out_line,
333 std::string *out_file) {
334 size_t i = 0;
335 while (i < len && (line[i] == ' ' || line[i] == '\t')) {
336 i++;
337 }
338 if (i >= len || line[i++] != '#') {
339 return false;
340 }
341 while (i < len && (line[i] == ' ' || line[i] == '\t')) {
342 i++;
343 }
344 static const char prefix[] = "line";
345 if (i + sizeof(prefix) - 1 > len || strncmp(line + i, prefix, sizeof(prefix) - 1) != 0) {
346 return false;
347 }
348 i += sizeof(prefix) - 1;
349 if (i >= len || (line[i] != ' ' && line[i] != '\t')) {
350 return false;
351 }
352 while (i < len && (line[i] == ' ' || line[i] == '\t')) {
353 i++;
354 }
355 if (i >= len || line[i] < '0' || line[i] > '9') {
356 return false;
357 }
358 uint64_t parsed_line = 0;
359 while (i < len && line[i] >= '0' && line[i] <= '9') {
360 parsed_line = parsed_line * 10u + (uint64_t)(line[i] - '0');
361 if (parsed_line > UINT32_MAX) {
362 return false;
363 }
364 i++;
365 }
366 while (i < len && (line[i] == ' ' || line[i] == '\t')) {
367 i++;
368 }
369 if (i >= len || line[i++] != '"') {
370 return false;
371 }
372 size_t file_start = i;
373 while (i < len && line[i] != '"') {
374 i++;
375 }
376 if (i >= len) {
377 return false;
378 }
379 *out_line = (uint32_t)parsed_line;
380 *out_file = std::string(line + file_start, i - file_start);
381 return true;
382}
383
384// True when `prev` and `tok` touched in the source text: same file and line,
385// `prev` ending exactly where `tok` starts (simplecpp's own adjacency test),

Callers 1

build_line_mapFunction · 0.85

Calls 1

stringFunction · 0.85

Tested by

no test coverage detected