Skip to content

Commit 8c67186

Browse files
author
Sush Shringarputale
committed
Address new PR comments and fix CI tests for documentation
1 parent 4406594 commit 8c67186

File tree

7 files changed

+54
-55
lines changed

7 files changed

+54
-55
lines changed

docs/examples/diagnostic_positions.output

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
Root diagnostic positions:
2-
start_pos: 5
3-
end_pos:109
1+
Root diagnostic positions:
2+
start_pos: 5
3+
end_pos:109
44

5-
address diagnostic positions:
6-
start_pos:26
7-
end_pos:103
5+
address diagnostic positions:
6+
start_pos:26
7+
end_pos:103
88

9-
street diagnostic positions:
10-
start_pos:50
11-
end_pos:63
9+
street diagnostic positions:
10+
start_pos:50
11+
end_pos:63
12+
13+
housenumber diagnostic positions:
14+
start_pos:92
15+
end_pos:93
1216

13-
housenumber diagnostic positions:
14-
start_pos:92
15-
end_pos:93

docs/mkdocs/docs/api/macros/json_diagnostic_positions.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
77
This macro enables position diagnostics for generated JSON objects.
88
9-
When enabled, two new properties: `start_pos()` and `end_pos()` are added to `nlohmann::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.
9+
When enabled, two new properties: `start_pos()` and `end_pos()` are added to `nlohmann::json` objects and fields. `start_pos()` returns the start position of
10+
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
11+
original string the object was parsed from.
1012
11-
For objects and arrays, the start and end positions represent the positions of the opening and closing braces or brackets, respectively. For fields, the start and end positions represent either the opening and closing quotes for that field's value or the first and character after last in the field's numerical or predefined true/false/null values.
13+
For objects and arrays, the start and end positions represent the positions of the opening and closing braces or brackets, respectively. For fields, the start
14+
and end positions represent either the opening and closing quotes for that field's value or the first and character after last in the field's numerical or
15+
predefined true/false/null values.
1216
1317
`start_pos()` and `end_pos()` are only set if the JSON object was parsed using `json::parse()`. For all other cases, `std::string::npos` will be returned.
1418

include/nlohmann/detail/abi_macros.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
#endif
4242

4343
#if JSON_DIAGNOSTIC_POSITIONS
44-
#define NLOHMANN_JSON_ABI_TAG_JSON_DIAGNOSTIC_POSITIONS _dp
44+
#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS _dp
4545
#else
46-
#define NLOHMANN_JSON_ABI_TAG_JSON_DIAGNOSTIC_POSITIONS
46+
#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS
4747
#endif
4848

4949
#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
@@ -65,7 +65,7 @@
6565
NLOHMANN_JSON_ABI_TAGS_CONCAT( \
6666
NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \
6767
NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON, \
68-
NLOHMANN_JSON_ABI_TAG_JSON_DIAGNOSTIC_POSITIONS)
68+
NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS)
6969

7070
// Construct the namespace version component
7171
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \

include/nlohmann/detail/input/json_sax.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010

1111
#include <cstddef>
1212
#include <string> // string
13+
#include <type_traits> // enable_if_t
1314
#include <utility> // move
1415
#include <vector> // vector
15-
#include <type_traits> // enable_if_t
1616

1717
#include <nlohmann/detail/exceptions.hpp>
18+
#include <nlohmann/detail/input/lexer.hpp>
1819
#include <nlohmann/detail/macro_scope.hpp>
1920
#include <nlohmann/detail/string_concat.hpp>
20-
#include <nlohmann/detail/input/lexer.hpp>
21-
2221
NLOHMANN_JSON_NAMESPACE_BEGIN
2322

2423
/*!

include/nlohmann/json.hpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
847847
detail::enable_if_t <
848848
detail::is_basic_json<BasicJsonType>::value&& !std::is_same<basic_json, BasicJsonType>::value, int > = 0 >
849849
basic_json(const BasicJsonType& val)
850+
#if JSON_DIAGNOSTIC_POSITIONS
851+
: start_position(val.start_position),
852+
end_position(val.end_position)
853+
#endif
850854
{
851855
using other_boolean_t = typename BasicJsonType::boolean_t;
852856
using other_number_float_t = typename BasicJsonType::number_float_t;
@@ -894,11 +898,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
894898
}
895899
JSON_ASSERT(m_data.m_type == val.type());
896900

897-
#if JSON_DIAGNOSTIC_POSITIONS
898-
start_position = val.start_position;
899-
end_position = val.end_position;
900-
#endif
901-
902901
set_parents();
903902
assert_invariant();
904903
}
@@ -1150,6 +1149,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
11501149
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/
11511150
basic_json(const basic_json& other)
11521151
: json_base_class_t(other)
1152+
#if JSON_DIAGNOSTIC_POSITIONS
1153+
, start_position(other.start_position)
1154+
, end_position(other.end_position)
1155+
#endif
11531156
{
11541157
m_data.m_type = other.m_data.m_type;
11551158
// check of passed value is valid
@@ -1211,11 +1214,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
12111214
break;
12121215
}
12131216

1214-
#if JSON_DIAGNOSTIC_POSITIONS
1215-
start_position = other.start_position;
1216-
end_position = other.end_position;
1217-
#endif
1218-
12191217
set_parents();
12201218
assert_invariant();
12211219
}
@@ -1226,8 +1224,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
12261224
: json_base_class_t(std::forward<json_base_class_t>(other)),
12271225
m_data(std::move(other.m_data))
12281226
#if JSON_DIAGNOSTIC_POSITIONS
1229-
, start_position(other.start_position),
1230-
end_position(other.end_position)
1227+
, start_position(other.start_position)
1228+
, end_position(other.end_position)
12311229
#endif
12321230
{
12331231
// check that passed value is valid

single_include/nlohmann/json.hpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@
8888
#endif
8989

9090
#if JSON_DIAGNOSTIC_POSITIONS
91-
#define NLOHMANN_JSON_ABI_TAG_JSON_DIAGNOSTIC_POSITIONS _dp
91+
#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS _dp
9292
#else
93-
#define NLOHMANN_JSON_ABI_TAG_JSON_DIAGNOSTIC_POSITIONS
93+
#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS
9494
#endif
9595

9696
#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
@@ -112,7 +112,7 @@
112112
NLOHMANN_JSON_ABI_TAGS_CONCAT( \
113113
NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \
114114
NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON, \
115-
NLOHMANN_JSON_ABI_TAG_JSON_DIAGNOSTIC_POSITIONS)
115+
NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS)
116116

117117
// Construct the namespace version component
118118
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \
@@ -6757,16 +6757,12 @@ NLOHMANN_JSON_NAMESPACE_END
67576757

67586758
#include <cstddef>
67596759
#include <string> // string
6760+
#include <type_traits> // enable_if_t
67606761
#include <utility> // move
67616762
#include <vector> // vector
6762-
#include <type_traits> // enable_if_t
67636763

67646764
// #include <nlohmann/detail/exceptions.hpp>
67656765

6766-
// #include <nlohmann/detail/macro_scope.hpp>
6767-
6768-
// #include <nlohmann/detail/string_concat.hpp>
6769-
67706766
// #include <nlohmann/detail/input/lexer.hpp>
67716767
// __ _____ _____ _____
67726768
// __| | __| | | | JSON for Modern C++
@@ -8416,6 +8412,9 @@ class lexer : public lexer_base<BasicJsonType>
84168412
} // namespace detail
84178413
NLOHMANN_JSON_NAMESPACE_END
84188414

8415+
// #include <nlohmann/detail/macro_scope.hpp>
8416+
8417+
// #include <nlohmann/detail/string_concat.hpp>
84198418

84208419
NLOHMANN_JSON_NAMESPACE_BEGIN
84218420

@@ -20503,6 +20502,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
2050320502
detail::enable_if_t <
2050420503
detail::is_basic_json<BasicJsonType>::value&& !std::is_same<basic_json, BasicJsonType>::value, int > = 0 >
2050520504
basic_json(const BasicJsonType& val)
20505+
#if JSON_DIAGNOSTIC_POSITIONS
20506+
: start_position(val.start_position),
20507+
end_position(val.end_position)
20508+
#endif
2050620509
{
2050720510
using other_boolean_t = typename BasicJsonType::boolean_t;
2050820511
using other_number_float_t = typename BasicJsonType::number_float_t;
@@ -20550,11 +20553,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
2055020553
}
2055120554
JSON_ASSERT(m_data.m_type == val.type());
2055220555

20553-
#if JSON_DIAGNOSTIC_POSITIONS
20554-
start_position = val.start_position;
20555-
end_position = val.end_position;
20556-
#endif
20557-
2055820556
set_parents();
2055920557
assert_invariant();
2056020558
}
@@ -20806,6 +20804,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
2080620804
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/
2080720805
basic_json(const basic_json& other)
2080820806
: json_base_class_t(other)
20807+
#if JSON_DIAGNOSTIC_POSITIONS
20808+
, start_position(other.start_position)
20809+
, end_position(other.end_position)
20810+
#endif
2080920811
{
2081020812
m_data.m_type = other.m_data.m_type;
2081120813
// check of passed value is valid
@@ -20867,11 +20869,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
2086720869
break;
2086820870
}
2086920871

20870-
#if JSON_DIAGNOSTIC_POSITIONS
20871-
start_position = other.start_position;
20872-
end_position = other.end_position;
20873-
#endif
20874-
2087520872
set_parents();
2087620873
assert_invariant();
2087720874
}
@@ -20882,8 +20879,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
2088220879
: json_base_class_t(std::forward<json_base_class_t>(other)),
2088320880
m_data(std::move(other.m_data))
2088420881
#if JSON_DIAGNOSTIC_POSITIONS
20885-
, start_position(other.start_position),
20886-
end_position(other.end_position)
20882+
, start_position(other.start_position)
20883+
, end_position(other.end_position)
2088720884
#endif
2088820885
{
2088920886
// check that passed value is valid

single_include/nlohmann/json_fwd.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959
#endif
6060

6161
#if JSON_DIAGNOSTIC_POSITIONS
62-
#define NLOHMANN_JSON_ABI_TAG_JSON_DIAGNOSTIC_POSITIONS _dp
62+
#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS _dp
6363
#else
64-
#define NLOHMANN_JSON_ABI_TAG_JSON_DIAGNOSTIC_POSITIONS
64+
#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS
6565
#endif
6666

6767
#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
@@ -83,7 +83,7 @@
8383
NLOHMANN_JSON_ABI_TAGS_CONCAT( \
8484
NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \
8585
NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON, \
86-
NLOHMANN_JSON_ABI_TAG_JSON_DIAGNOSTIC_POSITIONS)
86+
NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS)
8787

8888
// Construct the namespace version component
8989
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \

0 commit comments

Comments
 (0)