Skip to content

Commit 4c93c34

Browse files
committed
code cleanup
1 parent aaaecfc commit 4c93c34

31 files changed

+267
-349
lines changed

doc/ref/corelib/basic_json_parser.md

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,6 @@ temp_allocator_type |TempAllocator
4646
std::function<bool(json_errc,const ser_context&)> err_handler, (4) (deprecated since 0.171.0)
4747
const TempAllocator& temp_alloc = TempAllocator());
4848

49-
basic_json_parser(
50-
std::function<bool(basic_parser_input<CharT>& input, std::error_code& ec)> read_chunk,
51-
const TempAllocator& temp_alloc = TempAllocator()); (5) (since 1.0.0)
52-
53-
basic_json_parser(
54-
std::function<bool(basic_parser_input<CharT>& input, std::error_code& ec)> read_chunk,
55-
const basic_json_decode_options<CharT>& options,
56-
const TempAllocator& temp_alloc = TempAllocator()); (6) (since 1.0.0)
57-
5849

5950
(1) Constructs a `json_parser` that uses default [basic_json_options](basic_json_options.md)
6051
and a default [err_handler](err_handler.md).
@@ -71,12 +62,9 @@ and a specified [err_handler](err_handler.md).
7162
#### Member functions
7263

7364
void update(const string_view_type& sv)
74-
void update(const CharT* data, std::size_t length) (deprecated in 1.0.0)
65+
void update(const CharT* data, std::size_t length) (until 1.0.0, since 1.1.0)
7566
Update the parser with a chunk of JSON
7667

77-
void set_buffer(const CharT* data, std::size_t length) final (since 1.0.0)
78-
Initializes the buffer to parse from with a chunk of JSON text
79-
8068
bool done() const
8169
Returns `true` when the parser has consumed a complete JSON text, `false` otherwise
8270

@@ -190,7 +178,7 @@ B: inf
190178
C: -inf
191179
```
192180

193-
#### Incremental parsing (until 1.0.0)
181+
#### Incremental parsing (until 1.0.0, since 1.1.0)
194182

195183
```cpp
196184
#include <jsoncons/json.hpp>
@@ -252,62 +240,3 @@ Output:
252240
(7) [false,90]
253241
```
254242

255-
#### Incremental parsing (since 1.0.0)
256-
257-
```cpp
258-
#include <jsoncons/json.hpp>
259-
#include <iostream>
260-
261-
int main()
262-
{
263-
std::vector<std::string> chunks = {"[fal", "se,", "9", "0]"};
264-
std::size_t index = 0;
265-
266-
auto read_chunk = [&](jsoncons::parser_input& input, std::error_code& /*ec*/) -> bool
267-
{
268-
if (index < chunks.size())
269-
{
270-
input.set_buffer(chunks[index].data(), chunks[index].size());
271-
++index;
272-
return true;
273-
}
274-
else
275-
{
276-
return false;
277-
}
278-
};
279-
280-
jsoncons::json_decoder<jsoncons::json> decoder;
281-
jsoncons::json_parser parser{read_chunk};
282-
283-
parser.reset();
284-
try
285-
{
286-
parser.parse_some(decoder);
287-
std::cout << "(1) done: " << std::boolalpha << parser.done() << ", source_exhausted: " << parser.source_exhausted() << "\n\n";
288-
parser.finish_parse(decoder);
289-
std::cout << "(2) done: " << std::boolalpha << parser.done() << ", source_exhausted: " << parser.source_exhausted() << "\n\n";
290-
parser.check_done();
291-
std::cout << "(3) done: " << std::boolalpha << parser.done() << ", source_exhausted: " << parser.source_exhausted() << "\n\n";
292-
293-
jsoncons::json j = decoder.get_result();
294-
std::cout << "(4) " << j << "\n\n";
295-
}
296-
catch (const jsoncons::ser_error& e)
297-
{
298-
std::cout << e.what() << '\n';
299-
}
300-
}
301-
```
302-
303-
Output:
304-
305-
```
306-
(1) done: false, source_exhausted: true
307-
308-
(2) done: true, source_exhausted: true
309-
310-
(3) done: true, source_exhausted: true
311-
312-
(4) [false,90]
313-
```

doc/ref/corelib/basic_parser_input.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

include/jsoncons/basic_json.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,7 +2594,7 @@ namespace jsoncons {
25942594
}
25952595
else
25962596
{
2597-
return it->value();
2597+
return (*it).value();
25982598
}
25992599
break;
26002600
}
@@ -2622,7 +2622,7 @@ namespace jsoncons {
26222622
}
26232623
else
26242624
{
2625-
return it->value();
2625+
return (*it).value();
26262626
}
26272627
break;
26282628
}
@@ -2954,7 +2954,7 @@ namespace jsoncons {
29542954
return 0;
29552955
}
29562956
std::size_t count = 0;
2957-
while (it != cast<object_storage>().value().end()&& it->key() == key)
2957+
while (it != cast<object_storage>().value().end()&& (*it).key() == key)
29582958
{
29592959
++count;
29602960
++it;
@@ -3595,7 +3595,7 @@ namespace jsoncons {
35953595
{
35963596
JSONCONS_THROW(key_not_found(key.data(),key.length()));
35973597
}
3598-
return it->value();
3598+
return (*it).value();
35993599
}
36003600
case json_storage_kind::json_reference:
36013601
return cast<json_reference_storage>().value().at(key);
@@ -3617,7 +3617,7 @@ namespace jsoncons {
36173617
{
36183618
JSONCONS_THROW(key_not_found(key.data(),key.length()));
36193619
}
3620-
return it->value();
3620+
return (*it).value();
36213621
}
36223622
case json_storage_kind::json_const_reference:
36233623
return cast<json_const_reference_storage>().value().at(key);
@@ -3714,7 +3714,7 @@ namespace jsoncons {
37143714
auto it = cast<object_storage>().value().find(key);
37153715
if (it != cast<object_storage>().value().end())
37163716
{
3717-
return it->value();
3717+
return (*it).value();
37183718
}
37193719
else
37203720
{
@@ -3747,7 +3747,7 @@ namespace jsoncons {
37473747
auto it = cast<object_storage>().value().find(key);
37483748
if (it != cast<object_storage>().value().end())
37493749
{
3750-
return it->value().template as<T>();
3750+
return (*it).value().template as<T>();
37513751
}
37523752
else
37533753
{
@@ -4473,8 +4473,8 @@ namespace jsoncons {
44734473
const object& o = cast<object_storage>().value();
44744474
for (auto it = o.begin(); more && it != o.end(); ++it)
44754475
{
4476-
visitor.key(string_view_type((it->key()).data(),it->key().length()), context, ec);
4477-
it->value().dump_noflush(visitor, ec);
4476+
visitor.key(string_view_type(((*it).key()).data(),(*it).key().length()), context, ec);
4477+
(*it).value().dump_noflush(visitor, ec);
44784478
}
44794479
if (more)
44804480
{
@@ -4488,7 +4488,7 @@ namespace jsoncons {
44884488
const array& o = cast<array_storage>().value();
44894489
for (const_array_iterator it = o.begin(); more && it != o.end(); ++it)
44904490
{
4491-
it->dump_noflush(visitor, ec);
4491+
(*it).dump_noflush(visitor, ec);
44924492
}
44934493
if (more)
44944494
{

include/jsoncons/encode_traits.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ namespace jsoncons {
337337
if (ec) {return;}
338338
for (auto it = std::begin(val); it != std::end(val); ++it)
339339
{
340-
encoder.key(it->first);
341-
encode_traits<mapped_type,CharT>::encode(it->second, encoder, proto, ec);
340+
encoder.key((*it).first);
341+
encode_traits<mapped_type,CharT>::encode((*it).second, encoder, proto, ec);
342342
if (ec) {return;}
343343
}
344344
encoder.end_object(ser_context(), ec);
@@ -368,9 +368,9 @@ namespace jsoncons {
368368
for (auto it = std::begin(val); it != std::end(val); ++it)
369369
{
370370
std::basic_string<typename Json::char_type> s;
371-
jsoncons::detail::from_integer(it->first,s);
371+
jsoncons::detail::from_integer((*it).first,s);
372372
encoder.key(s);
373-
encode_traits<mapped_type,CharT>::encode(it->second, encoder, proto, ec);
373+
encode_traits<mapped_type,CharT>::encode((*it).second, encoder, proto, ec);
374374
if (ec) {return;}
375375
}
376376
encoder.end_object(ser_context(), ec);

include/jsoncons/json_decoder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class json_decoder final : public basic_json_visitor<typename Json::char_type>
197197
auto last = first + size;
198198
for (auto it = first; it != last; ++it)
199199
{
200-
container.push_back(std::move(it->value));
200+
container.push_back(std::move((*it).value));
201201
}
202202
item_stack_.erase(first, item_stack_.end());
203203
}

0 commit comments

Comments
 (0)