Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
02f5bca
Add implementation to retrieve start and end positions of json during…
sushshring Oct 28, 2024
311861f
Add more unit tests and add start/stop parsing for arrays
sushshring Nov 5, 2024
226d79b
Merge branch 'nlohmann:develop' into develop
sushshring Nov 6, 2024
b3f6499
Add raw value for all types
sushshring Nov 8, 2024
ab744aa
Merge branch 'develop' of https://github.com/sushshring/json into dev…
sushshring Nov 8, 2024
d321cdb
Add more tests and fix compiler warning
sushshring Nov 8, 2024
64ad6ce
Amalgamate
Nov 13, 2024
e820747
Fix CLang GCC warnings
Nov 13, 2024
3629ceb
Fix error in build
Nov 13, 2024
b42036b
Style using astyle 3.1
Nov 13, 2024
2575678
Fix whitespace changes
Nov 18, 2024
9de6ed1
revert
Nov 18, 2024
3bbca5e
more whitespace reverts
Nov 18, 2024
fa32e81
Address PR comments
Nov 19, 2024
b806d44
Fix failing issues
Nov 19, 2024
7d662ec
More whitespace reverts
Nov 19, 2024
3625875
Address remaining PR comments
Nov 21, 2024
9359441
Address comments
Nov 25, 2024
79e6513
Merge remote-tracking branch 'nlohmann/develop' into develop
Nov 25, 2024
a31d8b8
Switch to using custom base class instead of default basic_json
Nov 27, 2024
1d70d2b
Adding a basic using for a json using the new base class. Also addres…
Dec 4, 2024
814f367
Address decltype comments
Dec 6, 2024
4986e99
Diagnostic positions macro (#4)
sushshring Dec 12, 2024
b96a5d1
Fix missed include deletion
Dec 12, 2024
4406594
Add docs and address other PR comments (#5)
sushshring Dec 13, 2024
8c67186
Address new PR comments and fix CI tests for documentation
Dec 16, 2024
6c04575
Update documentation based on feedback (#6)
sushshring Dec 17, 2024
3d425d6
Merge branch 'develop' into develop
sushshring Dec 17, 2024
94505ba
Address std::size_t and other comments
Dec 17, 2024
556ab6b
Fix new CI issues
Dec 17, 2024
7f599cf
Fix lcov
Dec 17, 2024
5592cb3
Improve lcov case with update to handle_diagnostic_positions call for…
Dec 17, 2024
920e9a7
Fix indentation of LCOV_EXCL_STOP comments
sushshring Dec 18, 2024
aa14b15
fix amalgamation astyle issue
Dec 18, 2024
c4d1091
Merge remote-tracking branch 'nlohmann/develop' into develop
Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix new CI issues
  • Loading branch information
Sush Shringarputale committed Dec 17, 2024
commit 556ab6b6cf2f5a1fe29d14242dcd4311b669d857
13 changes: 8 additions & 5 deletions docs/mkdocs/docs/api/macros/json_diagnostic_positions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

This macro enables position diagnostics for generated JSON objects.

When enabled, two new properties: `start_pos()` and `end_pos()` are added to `nlohmann::basic_json` objects and fields. `start_pos()` returns the start position of
that JSON object/field in the original string the object was parsed from. Likewise, `end_pos()` returns the end position of that JSON object/field in the
original string the object was parsed from.

`start_pos()` returns the first character of a given element in the original JSON string, while `end_pos()` returns the character following the last character. For objects and arrays, the first and last characters correspond to the opening or closing braces/brackets, respectively. For fields, the first and last character represent the opening and closing quotes or the first and last character of the field's numerical or predefined value (true/false/null), respectively.
When enabled, two new properties: `start_pos()` and `end_pos()` are added to `nlohmann::basic_json` objects and fields. `start_pos()` returns the start
position of that JSON object/field in the original string the object was parsed from. Likewise, `end_pos()` returns the end position of that JSON
object/field in the original string the object was parsed from.

`start_pos()` returns the first character of a given element in the original JSON string, while `end_pos()` returns the character following the last
character. For objects and arrays, the first and last characters correspond to the opening or closing braces/brackets, respectively. For fields, the first
and last character represent the opening and closing quotes or the first and last character of the field's numerical or predefined value
(true/false/null), respectively.

Given the above, `end_pos() - start_pos()` for an object or field provides the length of the string representation for that object or field, including the
opening or closing braces, brackets, or quotes.
Expand Down
8 changes: 7 additions & 1 deletion include/nlohmann/detail/input/json_sax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,12 +751,16 @@ class json_sax_dom_callback_parser
break;
}

// As we handle the start and end positions for values before calling the callback
// we do not expect this to be called.
// LCOV_EXCL_START
case value_t::discarded:
{
v.end_position = std::string::npos;
v.start_position = v.end_position;
break;
}
// LCOV_EXCL_STOP
case value_t::binary:
case value_t::number_integer:
case value_t::number_unsigned:
Expand All @@ -772,11 +776,13 @@ class json_sax_dom_callback_parser
// skip setting the values here.
break;
}
// LCOV_EXCL_START
default:
{
// Handle all possible types discretely, default handler should never be reached.
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert,-warnings-as-errors)
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert,-warnings-as-errors) // LCOV_EXCL_LINE
}
// LCOV_EXCL_STOP
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,8 +1225,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
: json_base_class_t(std::forward<json_base_class_t>(other)),
m_data(std::move(other.m_data)) // cppcheck-suppress[accessForwarded] TODO check
#if JSON_DIAGNOSTIC_POSITIONS
, start_position(other.start_position)
, end_position(other.end_position)
, start_position(other.start_position) // cppcheck-suppress[accessForwarded] TODO check
, end_position(other.end_position) // cppcheck-suppress[accessForwarded] TODO check
#endif
{
// check that passed value is valid
Expand Down
12 changes: 9 additions & 3 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9277,12 +9277,16 @@ class json_sax_dom_callback_parser
break;
}

// As we handle the start and end positions for values before calling the callback
// we do not expect this to be called.
// LCOV_EXCL_START
case value_t::discarded:
{
v.end_position = std::string::npos;
v.start_position = v.end_position;
break;
}
// LCOV_EXCL_STOP
case value_t::binary:
case value_t::number_integer:
case value_t::number_unsigned:
Expand All @@ -9298,11 +9302,13 @@ class json_sax_dom_callback_parser
// skip setting the values here.
break;
}
// LCOV_EXCL_START
default:
{
// Handle all possible types discretely, default handler should never be reached.
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert,-warnings-as-errors)
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert,-warnings-as-errors) // LCOV_EXCL_LINE
}
// LCOV_EXCL_STOP
}
}
}
Expand Down Expand Up @@ -21060,8 +21066,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
: json_base_class_t(std::forward<json_base_class_t>(other)),
m_data(std::move(other.m_data)) // cppcheck-suppress[accessForwarded] TODO check
#if JSON_DIAGNOSTIC_POSITIONS
, start_position(other.start_position)
, end_position(other.end_position)
, start_position(other.start_position) // cppcheck-suppress[accessForwarded] TODO check
, end_position(other.end_position) // cppcheck-suppress[accessForwarded] TODO check
#endif
{
// check that passed value is valid
Expand Down
Loading