MCPcopy Create free account
hub / github.com/KTH-RPL/dufomap / parse_key_value_pair_and_insert

Method parse_key_value_pair_and_insert

src/toml.hpp:15456–15528  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15454 }
15455
15456 TOML_NEVER_INLINE
15457 bool parse_key_value_pair_and_insert(table* tbl)
15458 {
15459 return_if_error({});
15460 assert_not_eof();
15461 TOML_ASSERT_ASSUME(is_string_delimiter(*cp) || is_bare_key_character(*cp));
15462 push_parse_scope("key-value pair"sv);
15463
15464 // read the key into the key buffer
15465 start_recording();
15466 parse_key();
15467 stop_recording(1u);
15468 return_if_error({});
15469 TOML_ASSERT(key_buffer.size() >= 1u);
15470
15471 // skip past any whitespace that followed the key
15472 consume_leading_whitespace();
15473 set_error_and_return_if_eof({});
15474
15475 // '='
15476 if (*cp != U'=')
15477 set_error_and_return_default("expected '=', saw '"sv, to_sv(*cp), "'"sv);
15478 advance_and_return_if_error_or_eof({});
15479
15480 // skip past any whitespace that followed the '='
15481 consume_leading_whitespace();
15482 return_if_error({});
15483 set_error_and_return_if_eof({});
15484
15485 // check that the next character could actually be a value
15486 if (is_value_terminator(*cp))
15487 set_error_and_return_default("expected value, saw '"sv, to_sv(*cp), "'"sv);
15488
15489 // if it's a dotted kvp we need to spawn the parent sub-tables if necessary,
15490 // and set the target table to the second-to-last one in the chain
15491 if (key_buffer.size() > 1u)
15492 {
15493 for (size_t i = 0; i < key_buffer.size() - 1u; i++)
15494 {
15495 const std::string_view segment = key_buffer[i];
15496 auto pit = tbl->lower_bound(segment);
15497
15498 // parent already existed
15499 if (pit != tbl->end() && pit->first == segment)
15500 {
15501 table* p = pit->second.as_table();
15502
15503 // redefinition
15504 if TOML_UNLIKELY(!p
15505 || !(impl::find(dotted_key_tables.begin(), dotted_key_tables.end(), p)
15506 || impl::find(implicit_tables.begin(), implicit_tables.end(), p)))
15507 {
15508 set_error_at(key_buffer.starts[i],
15509 "cannot redefine existing "sv,
15510 to_sv(pit->second.type()),
15511 " as dotted key-value pair"sv);
15512 return_after_error({});
15513 }

Callers

nothing calls this directly

Calls 3

findFunction · 0.85
sizeMethod · 0.80
push_backMethod · 0.45

Tested by

no test coverage detected