Address review: clearer position code and docs

- position_source gets clear(); set_scalar() returns early for new values,
  switches on node_kind, and uses no local copies; the one position_source
  per materialize() call is documented
- no npos + 1 for containers without a position; a comment on why the end
  of a container is reported as its closing bracket
- less duplication under #if in materialize() and the builder
- diagnostic_positions sets npos explicitly
- docs: positions of basic_json values after changes, positions in images
  depend on how the document was parsed, when next is set, and the cost of
  positions while parsing

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-10-28 07:09:19 +01:00
1 parent 31cc438265
commit eb7d77e448
7 files changed
+221 -138

No files matched your search

+3 -3
View File
@@ -15632,7 +15632,7 @@ struct diagnostic_positions
// (npos: a value without a source position, see materialize() of
// json_view)
const std::size_t read = lexer->get_chars_read_total();
v.start_position = read == std::string::npos ? read : read - 1;
v.start_position = read == std::string::npos ? std::string::npos : read - 1;
}
}
@@ -15651,7 +15651,7 @@ struct diagnostic_positions
{
// a range has both ends or none (exception::diagnostics()
// prints only complete ones)
v.start_position = v.end_position;
v.start_position = std::string::npos;
}
}
}
@@ -15672,7 +15672,7 @@ struct diagnostic_positions
if (v.end_position == std::string::npos)
{
// a value without a source position
v.start_position = v.end_position;
v.start_position = std::string::npos;
return;
}