Skip to content

Commit 3054d2c

Browse files
committed
str_ref
1 parent e6e081e commit 3054d2c

File tree

7 files changed

+200
-196
lines changed

7 files changed

+200
-196
lines changed

include/jsoncons/basic_json.hpp

Lines changed: 160 additions & 160 deletions
Large diffs are not rendered by default.

include/jsoncons/json_type.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,17 @@ namespace jsoncons {
172172

173173
enum class json_storage_kind : uint8_t
174174
{
175-
null = 0, // 0000
175+
str_ref = 0, // 0000
176176
boolean = 1, // 0001
177177
int64 = 2, // 0010
178178
uint64 = 3, // 0011
179179
empty_object = 4, // 0100
180180
float64 = 5, // 0101
181181
half_float = 6, // 0110
182182
short_str = 7, // 0111
183-
json_const_reference = 8, // 1000
184-
json_reference = 9, // 1001
183+
json_const_ref = 8, // 1000
184+
json_ref = 9, // 1001
185+
null = 10, // 1010
185186
byte_str = 12, // 1100
186187
object = 13, // 1101
187188
array = 14, // 1110
@@ -191,7 +192,7 @@ namespace jsoncons {
191192
inline bool is_string_storage(json_storage_kind storage_kind) noexcept
192193
{
193194
static const uint8_t mask{ uint8_t(json_storage_kind::short_str) & uint8_t(json_storage_kind::long_str) };
194-
return (uint8_t(storage_kind) & mask) == mask;
195+
return (uint8_t(storage_kind) & mask) == mask || !uint8_t(storage_kind);
195196
}
196197

197198
inline bool is_trivial_storage(json_storage_kind storage_kind) noexcept
@@ -281,12 +282,12 @@ namespace jsoncons {
281282
os << object_value;
282283
break;
283284
}
284-
case json_storage_kind::json_const_reference:
285+
case json_storage_kind::json_const_ref:
285286
{
286287
os << json_const_reference;
287288
break;
288289
}
289-
case json_storage_kind::json_reference:
290+
case json_storage_kind::json_ref:
290291
{
291292
os << json_reference;
292293
break;

include/jsoncons/reflect/json_conv_traits.hpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ has_can_convert = ext_traits::is_detected<traits_can_convert_t, Json, T>;
848848
struct json_conv_traits<Json, T,
849849
typename std::enable_if<!is_json_conv_traits_declared<T>::value &&
850850
ext_traits::is_map_like<T>::value &&
851-
ext_traits::is_constructible_from_const_pointer_and_size<typename T::key_type>::value &&
851+
ext_traits::is_string<typename T::key_type>::value &&
852852
is_json_conv_traits_specialized<Json,typename T::mapped_type>::value>::type
853853
>
854854
{
@@ -902,7 +902,7 @@ has_can_convert = ext_traits::is_detected<traits_can_convert_t, Json, T>;
902902
struct json_conv_traits<Json, T,
903903
typename std::enable_if<!is_json_conv_traits_declared<T>::value &&
904904
ext_traits::is_map_like<T>::value &&
905-
!ext_traits::is_constructible_from_const_pointer_and_size<typename T::key_type>::value &&
905+
!ext_traits::is_string<typename T::key_type>::value &&
906906
is_json_conv_traits_specialized<Json,typename T::key_type>::value &&
907907
is_json_conv_traits_specialized<Json,typename T::mapped_type>::value>::type
908908
>
@@ -932,18 +932,23 @@ has_can_convert = ext_traits::is_detected<traits_can_convert_t, Json, T>;
932932
}
933933

934934
template <typename Alloc, typename TempAlloc>
935-
static result_type try_as(const allocator_set<Alloc,TempAlloc>&, const Json& val)
935+
static result_type try_as(const allocator_set<Alloc,TempAlloc>& aset, const Json& val)
936936
{
937937
T result;
938938
for (const auto& item : val.object_range())
939939
{
940940
Json j(item.key());
941-
auto r = json_conv_traits<Json,key_type>::try_as(make_alloc_set(), j);
942-
if (!r)
941+
auto r1 = json_conv_traits<Json,key_type>::try_as(aset, j);
942+
if (!r1)
943943
{
944-
return result_type(jsoncons::unexpect, r.error());
944+
return result_type(jsoncons::unexpect, r1.error());
945945
}
946-
result.emplace(std::move(r.value()), item.value().template as<mapped_type>());
946+
auto r2 = item.value().template as<mapped_type>(aset);
947+
if (!r2)
948+
{
949+
return result_type(jsoncons::unexpect, r2.error());
950+
}
951+
result.emplace(std::move(r1.value()), std::move(*r2));
947952
}
948953

949954
return result_type(std::move(result));

include/jsoncons/utility/byte_string.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ namespace detail {
101101
template <typename InputIt,typename F,typename Container>
102102
typename std::enable_if<ext_traits::is_back_insertable_byte_container<Container>::value,to_bytes_result<InputIt>>::type
103103
base64_to_bytes_generic(InputIt first, InputIt last,
104-
const uint8_t reverse_alphabet[256],
105-
F f,
106-
Container& result)
104+
const uint8_t reverse_alphabet[256], F f, Container& result)
107105
{
108106
uint8_t a4[4], a3[3];
109107
uint8_t i = 0;
@@ -236,8 +234,7 @@ namespace detail {
236234
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
237235
};
238236
auto retval = jsoncons::detail::base64_to_bytes_generic(first, last, reverse_alphabet,
239-
is_base64url<typename std::iterator_traits<InputIt>::value_type>,
240-
result);
237+
is_base64url<typename std::iterator_traits<InputIt>::value_type>, result);
241238
return retval.ec == conv_errc::success ? retval : to_bytes_result<InputIt>{retval.it, conv_errc::not_base64url};
242239
}
243240

@@ -264,8 +261,7 @@ namespace detail {
264261
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
265262
};
266263
auto retval = jsoncons::detail::base64_to_bytes_generic(first, last, reverse_alphabet,
267-
is_base64<typename std::iterator_traits<InputIt>::value_type>,
268-
result);
264+
is_base64<typename std::iterator_traits<InputIt>::value_type>, result);
269265
return retval.ec == conv_errc::success ? retval : to_bytes_result<InputIt>{retval.it, conv_errc::not_base64};
270266
}
271267

test/corelib/src/json_const_pointer_arg_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,19 @@ TEST_CASE("json_const_reference array tests")
5151
SECTION("copy")
5252
{
5353
json v(json_const_pointer_arg, &j);
54-
CHECK(v.storage_kind() == json_storage_kind::json_const_reference);
54+
CHECK(v.storage_kind() == json_storage_kind::json_const_ref);
5555

5656
json j2(v);
57-
CHECK(j2.storage_kind() == json_storage_kind::json_const_reference);
57+
CHECK(j2.storage_kind() == json_storage_kind::json_const_ref);
5858
}
5959
SECTION("assignment")
6060
{
6161
json v(json_const_pointer_arg, &j);
62-
CHECK(v.storage_kind() == json_storage_kind::json_const_reference);
62+
CHECK(v.storage_kind() == json_storage_kind::json_const_ref);
6363

6464
json j2;
6565
j2 = v;
66-
CHECK(j2.storage_kind() == json_storage_kind::json_const_reference);
66+
CHECK(j2.storage_kind() == json_storage_kind::json_const_ref);
6767
}
6868
}
6969

test/corelib/src/json_pointer_arg_tests.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ TEST_CASE("json_reference array tests")
8585
json expected = json::parse(R"( [1, "two", "four"] )");
8686

8787
json v(json_pointer_arg, &j);
88-
CHECK(v.storage_kind() == json_storage_kind::json_reference);
88+
CHECK(v.storage_kind() == json_storage_kind::json_ref);
8989
j[2] = "four";
9090

9191
CHECK(expected == v);
9292
}
9393
SECTION("const operator[]")
9494
{
9595
const json v(json_pointer_arg, &j);
96-
CHECK(v.storage_kind() == json_storage_kind::json_reference);
96+
CHECK(v.storage_kind() == json_storage_kind::json_ref);
9797

9898
CHECK("three" == v[2]);
9999
}
@@ -114,26 +114,26 @@ TEST_CASE("json_reference array tests")
114114
SECTION("copy")
115115
{
116116
json v(json_pointer_arg, &j);
117-
CHECK(v.storage_kind() == json_storage_kind::json_reference);
117+
CHECK(v.storage_kind() == json_storage_kind::json_ref);
118118

119119
json j2(v);
120-
CHECK(j2.storage_kind() == json_storage_kind::json_reference);
120+
CHECK(j2.storage_kind() == json_storage_kind::json_ref);
121121
}
122122
SECTION("assignment")
123123
{
124124
json v(json_pointer_arg, &j);
125-
CHECK(v.storage_kind() == json_storage_kind::json_reference);
125+
CHECK(v.storage_kind() == json_storage_kind::json_ref);
126126

127127
json j2;
128128
j2 = v;
129-
CHECK(j2.storage_kind() == json_storage_kind::json_reference);
129+
CHECK(j2.storage_kind() == json_storage_kind::json_ref);
130130
}
131131
SECTION("push_back")
132132
{
133133
json expected = json::parse(R"( [1, "two", "three", "four"] )");
134134

135135
json v(json_pointer_arg, &j);
136-
CHECK(v.storage_kind() == json_storage_kind::json_reference);
136+
CHECK(v.storage_kind() == json_storage_kind::json_ref);
137137
j.push_back("four");
138138

139139
CHECK(expected == v);
@@ -143,7 +143,7 @@ TEST_CASE("json_reference array tests")
143143
json expected = json::parse(R"( [1, "two", "three", "four"] )");
144144

145145
json v(json_pointer_arg, &j);
146-
CHECK(v.storage_kind() == json_storage_kind::json_reference);
146+
CHECK(v.storage_kind() == json_storage_kind::json_ref);
147147
j.emplace_back("four");
148148

149149
CHECK(expected == v);

test/corelib/src/json_storage_tests.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ TEST_CASE("test json_storage_kind")
2020
CHECK(is_trivial_storage(json_storage_kind::half_float));
2121
CHECK(is_trivial_storage(json_storage_kind::short_str));
2222
CHECK(is_trivial_storage(json_storage_kind::empty_object));
23-
CHECK(is_trivial_storage(json_storage_kind::json_const_reference));
24-
CHECK(is_trivial_storage(json_storage_kind::json_reference));
23+
CHECK(is_trivial_storage(json_storage_kind::json_const_ref));
24+
CHECK(is_trivial_storage(json_storage_kind::json_ref));
25+
CHECK(is_trivial_storage(json_storage_kind::str_ref));
2526
CHECK_FALSE(is_trivial_storage(json_storage_kind::long_str));
2627
CHECK_FALSE(is_trivial_storage(json_storage_kind::byte_str));
2728
CHECK_FALSE(is_trivial_storage(json_storage_kind::array));
@@ -35,9 +36,10 @@ TEST_CASE("test json_storage_kind")
3536
CHECK_FALSE(is_string_storage(json_storage_kind::int64));
3637
CHECK_FALSE(is_string_storage(json_storage_kind::half_float));
3738
CHECK(is_string_storage(json_storage_kind::short_str));
39+
CHECK(is_string_storage(json_storage_kind::str_ref));
3840
CHECK_FALSE(is_string_storage(json_storage_kind::empty_object));
39-
CHECK_FALSE(is_string_storage(json_storage_kind::json_const_reference));
40-
CHECK_FALSE(is_string_storage(json_storage_kind::json_reference));
41+
CHECK_FALSE(is_string_storage(json_storage_kind::json_const_ref));
42+
CHECK_FALSE(is_string_storage(json_storage_kind::json_ref));
4143
CHECK(is_string_storage(json_storage_kind::long_str));
4244
CHECK_FALSE(is_string_storage(json_storage_kind::byte_str));
4345
CHECK_FALSE(is_string_storage(json_storage_kind::array));

0 commit comments

Comments
 (0)