| 1378 | |
| 1379 | template <typename Json, typename Iterator> |
| 1380 | Json unflatten_object(Iterator first, Iterator last, std::size_t offset, unflatten_options options) |
| 1381 | { |
| 1382 | Json jo{json_object_arg}; |
| 1383 | |
| 1384 | std::size_t length = std::distance(first, last); |
| 1385 | |
| 1386 | auto it = first; |
| 1387 | while (it != last) |
| 1388 | { |
| 1389 | if (it->first.tokens().size() == offset && length == 1) |
| 1390 | { |
| 1391 | return *(it->second); |
| 1392 | } |
| 1393 | if (it->first.tokens().size() == offset) |
| 1394 | { |
| 1395 | ++it; |
| 1396 | } |
| 1397 | else if (it->first.tokens().size() < offset) |
| 1398 | { |
| 1399 | return jsoncons::optional<Json>{}; |
| 1400 | } |
| 1401 | else |
| 1402 | { |
| 1403 | auto jt = it->first.tokens().begin() + offset; |
| 1404 | if (offset + 1 == it->first.tokens().size()) |
| 1405 | { |
| 1406 | jo.try_emplace(*jt, *(it->second)); |
| 1407 | ++it; |
| 1408 | } |
| 1409 | else |
| 1410 | { |
| 1411 | auto inner_last = find_inner_last(it, last, offset, *jt); |
| 1412 | if (options == unflatten_options{}) |
| 1413 | { |
| 1414 | auto res = try_unflatten_array<Json,Iterator>(it, inner_last, offset+1); |
| 1415 | if (!res) |
| 1416 | { |
| 1417 | jo.try_emplace(*jt, unflatten_object<Json,Iterator>(it, inner_last, offset+1, options)); |
| 1418 | } |
| 1419 | else |
| 1420 | { |
| 1421 | jo.try_emplace(*jt, std::move(*res)); |
| 1422 | } |
| 1423 | } |
| 1424 | else |
| 1425 | { |
| 1426 | jo.try_emplace(*jt, unflatten_object<Json,Iterator>(it, inner_last, offset+1, options)); |
| 1427 | } |
| 1428 | it = inner_last; |
| 1429 | } |
| 1430 | } |
| 1431 | } |
| 1432 | return jsoncons::optional<Json>{std::move(jo)}; |
| 1433 | } |
| 1434 | |
| 1435 | template <typename Json, typename Iterator> |
| 1436 | jsoncons::optional<Json> try_unflatten_array(Iterator first, Iterator last, std::size_t offset) |
nothing calls this directly
no test coverage detected