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

Function toml_parse_string

src/cli/config_toml_edit.c:1294–1382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1292}
1293
1294static int toml_parse_string(const char *text, size_t len, toml_string_t *parsed) {
1295 if (!text || !parsed || len < 2 || (text[0] != '"' && text[0] != '\'')) {
1296 return TOML_EDIT_ERR;
1297 }
1298 char quote = text[0];
1299 if (len >= 3 && text[1] == quote && text[2] == quote) {
1300 return TOML_EDIT_ERR;
1301 }
1302 toml_buffer_t value = {0};
1303 size_t pos = 1;
1304 while (pos < len) {
1305 unsigned char ch = (unsigned char)text[pos++];
1306 if (ch == (unsigned char)quote) {
1307 if (!value.data && toml_buffer_reserve(&value, 0) != TOML_EDIT_OK) {
1308 return TOML_EDIT_ERR;
1309 }
1310 parsed->data = value.data;
1311 parsed->len = value.len;
1312 parsed->consumed = pos;
1313 return TOML_EDIT_OK;
1314 }
1315 if (ch < 0x20 && ch != '\t') {
1316 toml_buffer_dispose(&value);
1317 return TOML_EDIT_ERR;
1318 }
1319 if (ch == 0x7f) {
1320 toml_buffer_dispose(&value);
1321 return TOML_EDIT_ERR;
1322 }
1323 if (quote == '\'' || ch != '\\') {
1324 if (toml_buffer_append_char(&value, (char)ch) != TOML_EDIT_OK) {
1325 toml_buffer_dispose(&value);
1326 return TOML_EDIT_ERR;
1327 }
1328 continue;
1329 }
1330 if (pos >= len) {
1331 toml_buffer_dispose(&value);
1332 return TOML_EDIT_ERR;
1333 }
1334 unsigned char escaped = (unsigned char)text[pos++];
1335 char decoded;
1336 switch (escaped) {
1337 case 'b':
1338 decoded = '\b';
1339 break;
1340 case 't':
1341 decoded = '\t';
1342 break;
1343 case 'n':
1344 decoded = '\n';
1345 break;
1346 case 'f':
1347 decoded = '\f';
1348 break;
1349 case 'r':
1350 decoded = '\r';
1351 break;

Callers 6

toml_parse_key_pathFunction · 0.85
toml_codex_take_stringFunction · 0.85
toml_codex_owned_spanFunction · 0.85

Calls 5

toml_buffer_reserveFunction · 0.85
toml_buffer_disposeFunction · 0.85
toml_buffer_append_charFunction · 0.85
toml_append_codepointFunction · 0.85

Tested by

no test coverage detected