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

Function toml_parse_header

src/cli/config_toml_edit.c:1521–1595  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1519}
1520
1521static int toml_parse_header(const char *data, const toml_line_t *line, const char *target_name,
1522 toml_header_t *header) {
1523 memset(header, 0, sizeof(*header));
1524 size_t start = line->start;
1525 size_t end = line->content_end;
1526 header->edit_start = line->start;
1527 if (line->start == 0 && end - start >= 3 && (unsigned char)data[start] == 0xef &&
1528 (unsigned char)data[start + 1] == 0xbb && (unsigned char)data[start + 2] == 0xbf) {
1529 start += 3;
1530 header->edit_start = start;
1531 }
1532 while (start < end && (data[start] == ' ' || data[start] == '\t')) {
1533 ++start;
1534 }
1535 if (start >= end || data[start] != '[') {
1536 return TOML_EDIT_OK;
1537 }
1538
1539 int array = start + 1 < end && data[start + 1] == '[';
1540 size_t inner_start = start + (array ? 2u : 1u);
1541 size_t pos = inner_start;
1542 char quote = '\0';
1543 int escaped = 0;
1544 size_t close_start = SIZE_MAX;
1545 size_t close_end = SIZE_MAX;
1546 while (pos < end) {
1547 char ch = data[pos];
1548 if (quote) {
1549 if (quote == '"' && !escaped && ch == '\\') {
1550 escaped = 1;
1551 } else {
1552 if (!escaped && ch == quote) {
1553 quote = '\0';
1554 }
1555 escaped = 0;
1556 }
1557 ++pos;
1558 continue;
1559 }
1560 if (ch == '"' || ch == '\'') {
1561 quote = ch;
1562 ++pos;
1563 continue;
1564 }
1565 if (ch == ']' && (!array || (pos + 1 < end && data[pos + 1] == ']'))) {
1566 close_start = pos;
1567 close_end = pos + (array ? 2u : 1u);
1568 break;
1569 }
1570 ++pos;
1571 }
1572 if (quote || close_start == SIZE_MAX) {
1573 return TOML_EDIT_ERR;
1574 }
1575 size_t inner_end = close_start;
1576 toml_trim(data, &inner_start, &inner_end);
1577 if (inner_start == inner_end) {
1578 return TOML_EDIT_ERR;

Callers 9

toml_section_endFunction · 0.85
toml_section_atFunction · 0.85
toml_scan_named_tablesFunction · 0.85
toml_validate_table_bodyFunction · 0.85
toml_strip_legacy_tableFunction · 0.85
toml_codex_scan_inlineFunction · 0.85

Calls 3

toml_trimFunction · 0.85
toml_parse_key_pathFunction · 0.85
toml_key_path_is_singleFunction · 0.85

Tested by

no test coverage detected