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

Function toml_parse_assignment

src/cli/config_toml_edit.c:1515–1606  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1513}
1514
1515static int toml_parse_assignment(const char *data, const toml_line_t *line,
1516 toml_assignment_t *assignment) {
1517 memset(assignment, 0, sizeof(*assignment));
1518 size_t start = line->start;
1519 size_t end = line->content_end;
1520 if (start == 0U && end >= 3U && (unsigned char)data[0] == 0xefU &&
1521 (unsigned char)data[1] == 0xbbU && (unsigned char)data[2] == 0xbfU) {
1522 start = 3U;
1523 }
1524 while (start < end && (data[start] == ' ' || data[start] == '\t')) {
1525 start++;
1526 }
1527 if (start == end || data[start] == '#') {
1528 return TOML_EDIT_OK;
1529 }
1530
1531 size_t equals = SIZE_MAX;
1532 char quote = '\0';
1533 int escaped = 0;
1534 for (size_t pos = start; pos < end; ++pos) {
1535 char ch = data[pos];
1536 if (quote) {
1537 if (quote == '"' && !escaped && ch == '\\') {
1538 escaped = 1;
1539 } else {
1540 if (!escaped && ch == quote) {
1541 quote = '\0';
1542 }
1543 escaped = 0;
1544 }
1545 continue;
1546 }
1547 if (ch == '"' || ch == '\'') {
1548 quote = ch;
1549 } else if (ch == '=') {
1550 equals = pos;
1551 break;
1552 } else if (ch == '#') {
1553 break;
1554 }
1555 }
1556 if (quote || equals == SIZE_MAX) {
1557 return TOML_EDIT_OK;
1558 }
1559 size_t key_end = equals;
1560 toml_trim(data, &start, &key_end);
1561 if (toml_parse_key_path(data, start, key_end, &assignment->key) != TOML_EDIT_OK) {
1562 return TOML_EDIT_ERR;
1563 }
1564
1565 size_t value_start = equals + 1U;
1566 while (value_start < end && (data[value_start] == ' ' || data[value_start] == '\t')) {
1567 value_start++;
1568 }
1569 size_t value_end = end;
1570 quote = '\0';
1571 escaped = 0;
1572 for (size_t pos = value_start; pos < end; ++pos) {

Callers 8

toml_scan_named_tablesFunction · 0.85
toml_validate_table_bodyFunction · 0.85
toml_merge_named_tableFunction · 0.85
toml_codex_owned_spanFunction · 0.85
toml_codex_scan_inlineFunction · 0.85

Calls 3

toml_trimFunction · 0.85
toml_parse_key_pathFunction · 0.85
toml_key_path_disposeFunction · 0.85

Tested by

no test coverage detected