jsoncons 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/jsoncons/extconf.rb +43 -0
- data/ext/jsoncons/jsoncons.cpp +161 -0
- data/ext/jsoncons/jsoncons.h +10 -0
- data/jsoncons.gemspec +44 -0
- data/lib/jsoncons/jsoncons/examples/input/address-book.json +13 -0
- data/lib/jsoncons/jsoncons/examples/input/books.json +28 -0
- data/lib/jsoncons/jsoncons/examples/input/countries.json +7 -0
- data/lib/jsoncons/jsoncons/examples/input/employees.json +30 -0
- data/lib/jsoncons/jsoncons/examples/input/jsonschema/name.json +15 -0
- data/lib/jsoncons/jsoncons/examples/input/multiple-json-objects.json +3 -0
- data/lib/jsoncons/jsoncons/examples/input/sales.csv +6 -0
- data/lib/jsoncons/jsoncons/examples/input/store.json +28 -0
- data/lib/jsoncons/jsoncons/examples/input/tasks.csv +6 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/allocator_holder.hpp +38 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/basic_json.hpp +5905 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/bigint.hpp +1611 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/byte_string.hpp +820 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/binary_config.hpp +226 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/compiler_support.hpp +375 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/jsoncons_config.hpp +309 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/version.hpp +40 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/conv_error.hpp +218 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/decode_json.hpp +209 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/decode_traits.hpp +651 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/endian.hpp +44 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/grisu3.hpp +312 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/optional.hpp +483 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/parse_number.hpp +1133 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/span.hpp +188 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_view.hpp +537 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_wrapper.hpp +370 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/write_number.hpp +567 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/encode_json.hpp +315 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/encode_traits.hpp +378 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json.hpp +18 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_array.hpp +324 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_content_handler.hpp +12 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_cursor.hpp +448 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_decoder.hpp +420 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_encoder.hpp +1587 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_error.hpp +156 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_exception.hpp +241 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_filter.hpp +653 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_fwd.hpp +23 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_object.hpp +1772 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_options.hpp +862 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_parser.hpp +2900 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_reader.hpp +731 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros.hpp +1072 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros_deprecated.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_type.hpp +206 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_type_traits.hpp +1830 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor.hpp +1560 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor2.hpp +2079 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/pretty_print.hpp +89 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/ser_context.hpp +62 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/sink.hpp +289 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/source.hpp +777 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/source_adaptor.hpp +148 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/staj2_cursor.hpp +1189 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/staj_cursor.hpp +1254 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/staj_iterator.hpp +449 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/tag_type.hpp +245 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/text_source_adaptor.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/traits_extension.hpp +884 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/typed_array_view.hpp +250 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/unicode_traits.hpp +1330 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/uri.hpp +635 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/value_converter.hpp +340 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson.hpp +23 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_cursor.hpp +320 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_decimal128.hpp +865 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_encoder.hpp +585 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_error.hpp +103 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_oid.hpp +245 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_options.hpp +75 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_parser.hpp +645 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_reader.hpp +92 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_type.hpp +44 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/decode_bson.hpp +201 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/encode_bson.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor.hpp +26 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor.hpp +351 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor2.hpp +265 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_detail.hpp +93 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_encoder.hpp +1766 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_error.hpp +105 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_options.hpp +113 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_parser.hpp +1942 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_reader.hpp +116 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/decode_cbor.hpp +203 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/encode_cbor.hpp +151 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv.hpp +17 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_cursor.hpp +358 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_encoder.hpp +954 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_error.hpp +85 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_options.hpp +973 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_parser.hpp +2099 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_reader.hpp +348 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_serializer.hpp +12 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/decode_csv.hpp +208 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/encode_csv.hpp +122 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath.hpp +5215 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath_error.hpp +215 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch.hpp +579 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch_error.hpp +121 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/expression.hpp +3329 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/flatten.hpp +432 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_location.hpp +445 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_query.hpp +115 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath.hpp +13 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_error.hpp +240 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp +2612 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp +1322 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer.hpp +1577 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer_error.hpp +119 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/format_validator.hpp +968 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/json_validator.hpp +120 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema.hpp +13 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_error.hpp +105 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_version.hpp +18 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator.hpp +1745 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator_factory.hpp +556 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_draft7.hpp +198 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_location.hpp +200 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_version.hpp +35 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/subschema.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/mergepatch/mergepatch.hpp +103 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/decode_msgpack.hpp +202 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/encode_msgpack.hpp +142 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack.hpp +24 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor.hpp +343 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor2.hpp +259 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_encoder.hpp +753 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_error.hpp +94 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_options.hpp +74 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_parser.hpp +748 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_reader.hpp +116 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_type.hpp +63 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/decode_ubjson.hpp +201 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/encode_ubjson.hpp +142 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson.hpp +23 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_cursor.hpp +307 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_encoder.hpp +502 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_error.hpp +100 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_options.hpp +87 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_parser.hpp +880 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_reader.hpp +92 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_type.hpp +43 -0
- data/lib/jsoncons/version.rb +5 -0
- data/lib/jsoncons.rb +33 -0
- data/test/jsoncons_test.rb +108 -0
- data/test/test_helper.rb +7 -0
- metadata +268 -0
@@ -0,0 +1,432 @@
|
|
1
|
+
// Copyright 2021 Daniel Parker
|
2
|
+
// Distributed under the Boost license, Version 1.0.
|
3
|
+
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
4
|
+
|
5
|
+
// See https://github.com/danielaparker/jsoncons for latest version
|
6
|
+
|
7
|
+
#ifndef JSONCONS_JSONPATH_FLATTEN_HPP
|
8
|
+
#define JSONCONS_JSONPATH_FLATTEN_HPP
|
9
|
+
|
10
|
+
#include <string>
|
11
|
+
#include <vector>
|
12
|
+
#include <memory>
|
13
|
+
#include <type_traits> // std::is_const
|
14
|
+
#include <limits> // std::numeric_limits
|
15
|
+
#include <utility> // std::move
|
16
|
+
#include <algorithm> // std::copy
|
17
|
+
#include <iterator> // std::back_inserter
|
18
|
+
#include <jsoncons_ext/jsonpath/jsonpath.hpp>
|
19
|
+
|
20
|
+
namespace jsoncons { namespace jsonpath {
|
21
|
+
|
22
|
+
template <class CharT, class Sink>
|
23
|
+
std::size_t escape_string(const CharT* s, std::size_t length,
|
24
|
+
Sink& sink)
|
25
|
+
{
|
26
|
+
std::size_t count = 0;
|
27
|
+
const CharT* begin = s;
|
28
|
+
const CharT* end = s + length;
|
29
|
+
for (const CharT* it = begin; it != end; ++it)
|
30
|
+
{
|
31
|
+
CharT c = *it;
|
32
|
+
switch (c)
|
33
|
+
{
|
34
|
+
case '\\':
|
35
|
+
sink.push_back('\\');
|
36
|
+
sink.push_back('\\');
|
37
|
+
count += 2;
|
38
|
+
break;
|
39
|
+
case '\'':
|
40
|
+
sink.push_back('\\');
|
41
|
+
sink.push_back('\'');
|
42
|
+
count += 2;
|
43
|
+
break;
|
44
|
+
case '\b':
|
45
|
+
sink.push_back('\\');
|
46
|
+
sink.push_back('b');
|
47
|
+
count += 2;
|
48
|
+
break;
|
49
|
+
case '\f':
|
50
|
+
sink.push_back('\\');
|
51
|
+
sink.push_back('f');
|
52
|
+
count += 2;
|
53
|
+
break;
|
54
|
+
case '\n':
|
55
|
+
sink.push_back('\\');
|
56
|
+
sink.push_back('n');
|
57
|
+
count += 2;
|
58
|
+
break;
|
59
|
+
case '\r':
|
60
|
+
sink.push_back('\\');
|
61
|
+
sink.push_back('r');
|
62
|
+
count += 2;
|
63
|
+
break;
|
64
|
+
case '\t':
|
65
|
+
sink.push_back('\\');
|
66
|
+
sink.push_back('t');
|
67
|
+
count += 2;
|
68
|
+
break;
|
69
|
+
default:
|
70
|
+
sink.push_back(c);
|
71
|
+
++count;
|
72
|
+
break;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
return count;
|
76
|
+
}
|
77
|
+
|
78
|
+
template<class Json>
|
79
|
+
void flatten_(const std::basic_string<typename Json::char_type>& parent_key,
|
80
|
+
const Json& parent_value,
|
81
|
+
Json& result)
|
82
|
+
{
|
83
|
+
using char_type = typename Json::char_type;
|
84
|
+
using string_type = std::basic_string<char_type>;
|
85
|
+
|
86
|
+
switch (parent_value.type())
|
87
|
+
{
|
88
|
+
case json_type::array_value:
|
89
|
+
{
|
90
|
+
if (parent_value.empty())
|
91
|
+
{
|
92
|
+
result.try_emplace(parent_key, parent_value);
|
93
|
+
}
|
94
|
+
else
|
95
|
+
{
|
96
|
+
for (std::size_t i = 0; i < parent_value.size(); ++i)
|
97
|
+
{
|
98
|
+
string_type key(parent_key);
|
99
|
+
key.push_back('[');
|
100
|
+
jsoncons::detail::from_integer(i,key);
|
101
|
+
key.push_back(']');
|
102
|
+
flatten_(key, parent_value.at(i), result);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
break;
|
106
|
+
}
|
107
|
+
|
108
|
+
case json_type::object_value:
|
109
|
+
{
|
110
|
+
if (parent_value.empty())
|
111
|
+
{
|
112
|
+
result.try_emplace(parent_key, Json());
|
113
|
+
}
|
114
|
+
else
|
115
|
+
{
|
116
|
+
for (const auto& item : parent_value.object_range())
|
117
|
+
{
|
118
|
+
string_type key(parent_key);
|
119
|
+
key.push_back('[');
|
120
|
+
key.push_back('\'');
|
121
|
+
escape_string(item.key().data(), item.key().length(), key);
|
122
|
+
key.push_back('\'');
|
123
|
+
key.push_back(']');
|
124
|
+
flatten_(key, item.value(), result);
|
125
|
+
}
|
126
|
+
}
|
127
|
+
break;
|
128
|
+
}
|
129
|
+
|
130
|
+
default:
|
131
|
+
{
|
132
|
+
result[parent_key] = parent_value;
|
133
|
+
break;
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
template<class Json>
|
139
|
+
Json flatten(const Json& value)
|
140
|
+
{
|
141
|
+
Json result;
|
142
|
+
std::basic_string<typename Json::char_type> parent_key = {'$'};
|
143
|
+
flatten_(parent_key, value, result);
|
144
|
+
return result;
|
145
|
+
}
|
146
|
+
|
147
|
+
enum class unflatten_state
|
148
|
+
{
|
149
|
+
start,
|
150
|
+
expect_lbracket,
|
151
|
+
lbracket,
|
152
|
+
single_quoted_name_state,
|
153
|
+
double_quoted_name_state,
|
154
|
+
index_state,
|
155
|
+
expect_rbracket,
|
156
|
+
double_quoted_string_escape_char,
|
157
|
+
single_quoted_string_escape_char
|
158
|
+
};
|
159
|
+
|
160
|
+
template<class Json>
|
161
|
+
Json unflatten(const Json& value)
|
162
|
+
{
|
163
|
+
using char_type = typename Json::char_type;
|
164
|
+
using string_type = std::basic_string<char_type>;
|
165
|
+
|
166
|
+
if (JSONCONS_UNLIKELY(!value.is_object()))
|
167
|
+
{
|
168
|
+
JSONCONS_THROW(jsonpath_error(jsonpath_errc::argument_to_unflatten_invalid));
|
169
|
+
}
|
170
|
+
|
171
|
+
Json result;
|
172
|
+
|
173
|
+
for (const auto& item : value.object_range())
|
174
|
+
{
|
175
|
+
Json* part = &result;
|
176
|
+
string_type buffer;
|
177
|
+
unflatten_state state = unflatten_state::start;
|
178
|
+
|
179
|
+
auto it = item.key().begin();
|
180
|
+
auto last = item.key().end();
|
181
|
+
|
182
|
+
for (; it != last; ++it)
|
183
|
+
{
|
184
|
+
switch (state)
|
185
|
+
{
|
186
|
+
case unflatten_state::start:
|
187
|
+
{
|
188
|
+
switch (*it)
|
189
|
+
{
|
190
|
+
case '$':
|
191
|
+
state = unflatten_state::expect_lbracket;
|
192
|
+
break;
|
193
|
+
default:
|
194
|
+
break;
|
195
|
+
}
|
196
|
+
break;
|
197
|
+
}
|
198
|
+
case unflatten_state::expect_lbracket:
|
199
|
+
{
|
200
|
+
switch (*it)
|
201
|
+
{
|
202
|
+
case '[':
|
203
|
+
state = unflatten_state::lbracket;
|
204
|
+
break;
|
205
|
+
default:
|
206
|
+
JSONCONS_THROW(jsonpath_error(jsonpath_errc::invalid_flattened_key));
|
207
|
+
break;
|
208
|
+
}
|
209
|
+
break;
|
210
|
+
}
|
211
|
+
case unflatten_state::lbracket:
|
212
|
+
{
|
213
|
+
switch (*it)
|
214
|
+
{
|
215
|
+
case '\'':
|
216
|
+
state = unflatten_state::single_quoted_name_state;
|
217
|
+
break;
|
218
|
+
case '\"':
|
219
|
+
state = unflatten_state::double_quoted_name_state;
|
220
|
+
break;
|
221
|
+
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8':case '9':
|
222
|
+
buffer.push_back(*it);
|
223
|
+
state = unflatten_state::index_state;
|
224
|
+
break;
|
225
|
+
default:
|
226
|
+
JSONCONS_THROW(jsonpath_error(jsonpath_errc::invalid_flattened_key));
|
227
|
+
break;
|
228
|
+
}
|
229
|
+
break;
|
230
|
+
}
|
231
|
+
case unflatten_state::single_quoted_name_state:
|
232
|
+
{
|
233
|
+
switch (*it)
|
234
|
+
{
|
235
|
+
case '\'':
|
236
|
+
if (it != last-2)
|
237
|
+
{
|
238
|
+
auto res = part->try_emplace(buffer,Json());
|
239
|
+
part = &(res.first->value());
|
240
|
+
}
|
241
|
+
else
|
242
|
+
{
|
243
|
+
auto res = part->try_emplace(buffer,item.value());
|
244
|
+
part = &(res.first->value());
|
245
|
+
}
|
246
|
+
buffer.clear();
|
247
|
+
state = unflatten_state::expect_rbracket;
|
248
|
+
break;
|
249
|
+
case '\\':
|
250
|
+
state = unflatten_state::single_quoted_string_escape_char;
|
251
|
+
break;
|
252
|
+
default:
|
253
|
+
buffer.push_back(*it);
|
254
|
+
break;
|
255
|
+
}
|
256
|
+
break;
|
257
|
+
}
|
258
|
+
case unflatten_state::double_quoted_name_state:
|
259
|
+
{
|
260
|
+
switch (*it)
|
261
|
+
{
|
262
|
+
case '\"':
|
263
|
+
if (it != last-2)
|
264
|
+
{
|
265
|
+
auto res = part->try_emplace(buffer,Json());
|
266
|
+
part = &(res.first->value());
|
267
|
+
}
|
268
|
+
else
|
269
|
+
{
|
270
|
+
auto res = part->try_emplace(buffer,item.value());
|
271
|
+
part = &(res.first->value());
|
272
|
+
}
|
273
|
+
buffer.clear();
|
274
|
+
state = unflatten_state::expect_rbracket;
|
275
|
+
break;
|
276
|
+
case '\\':
|
277
|
+
state = unflatten_state::double_quoted_string_escape_char;
|
278
|
+
break;
|
279
|
+
default:
|
280
|
+
buffer.push_back(*it);
|
281
|
+
break;
|
282
|
+
}
|
283
|
+
break;
|
284
|
+
}
|
285
|
+
case unflatten_state::double_quoted_string_escape_char:
|
286
|
+
switch (*it)
|
287
|
+
{
|
288
|
+
case '\"':
|
289
|
+
buffer.push_back('\"');
|
290
|
+
state = unflatten_state::double_quoted_name_state;
|
291
|
+
break;
|
292
|
+
case '\\':
|
293
|
+
buffer.push_back('\\');
|
294
|
+
state = unflatten_state::double_quoted_name_state;
|
295
|
+
break;
|
296
|
+
case '/':
|
297
|
+
buffer.push_back('/');
|
298
|
+
state = unflatten_state::double_quoted_name_state;
|
299
|
+
break;
|
300
|
+
case 'b':
|
301
|
+
buffer.push_back('\b');
|
302
|
+
state = unflatten_state::double_quoted_name_state;
|
303
|
+
break;
|
304
|
+
case 'f':
|
305
|
+
buffer.push_back('\f');
|
306
|
+
state = unflatten_state::double_quoted_name_state;
|
307
|
+
break;
|
308
|
+
case 'n':
|
309
|
+
buffer.push_back('\n');
|
310
|
+
state = unflatten_state::double_quoted_name_state;
|
311
|
+
break;
|
312
|
+
case 'r':
|
313
|
+
buffer.push_back('\r');
|
314
|
+
state = unflatten_state::double_quoted_name_state;
|
315
|
+
break;
|
316
|
+
case 't':
|
317
|
+
buffer.push_back('\t');
|
318
|
+
state = unflatten_state::double_quoted_name_state;
|
319
|
+
break;
|
320
|
+
default:
|
321
|
+
break;
|
322
|
+
}
|
323
|
+
break;
|
324
|
+
case unflatten_state::single_quoted_string_escape_char:
|
325
|
+
switch (*it)
|
326
|
+
{
|
327
|
+
case '\'':
|
328
|
+
buffer.push_back('\'');
|
329
|
+
state = unflatten_state::single_quoted_name_state;
|
330
|
+
break;
|
331
|
+
case '\\':
|
332
|
+
buffer.push_back('\\');
|
333
|
+
state = unflatten_state::double_quoted_name_state;
|
334
|
+
break;
|
335
|
+
case '/':
|
336
|
+
buffer.push_back('/');
|
337
|
+
state = unflatten_state::double_quoted_name_state;
|
338
|
+
break;
|
339
|
+
case 'b':
|
340
|
+
buffer.push_back('\b');
|
341
|
+
state = unflatten_state::double_quoted_name_state;
|
342
|
+
break;
|
343
|
+
case 'f':
|
344
|
+
buffer.push_back('\f');
|
345
|
+
state = unflatten_state::double_quoted_name_state;
|
346
|
+
break;
|
347
|
+
case 'n':
|
348
|
+
buffer.push_back('\n');
|
349
|
+
state = unflatten_state::double_quoted_name_state;
|
350
|
+
break;
|
351
|
+
case 'r':
|
352
|
+
buffer.push_back('\r');
|
353
|
+
state = unflatten_state::double_quoted_name_state;
|
354
|
+
break;
|
355
|
+
case 't':
|
356
|
+
buffer.push_back('\t');
|
357
|
+
state = unflatten_state::double_quoted_name_state;
|
358
|
+
break;
|
359
|
+
default:
|
360
|
+
break;
|
361
|
+
}
|
362
|
+
break;
|
363
|
+
case unflatten_state::index_state:
|
364
|
+
{
|
365
|
+
switch (*it)
|
366
|
+
{
|
367
|
+
case ']':
|
368
|
+
{
|
369
|
+
std::size_t n{0};
|
370
|
+
auto r = jsoncons::detail::to_integer(buffer.data(), buffer.size(), n);
|
371
|
+
if (r)
|
372
|
+
{
|
373
|
+
if (!part->is_array())
|
374
|
+
{
|
375
|
+
*part = Json(json_array_arg);
|
376
|
+
}
|
377
|
+
if (it != last-1)
|
378
|
+
{
|
379
|
+
if (n+1 > part->size())
|
380
|
+
{
|
381
|
+
Json& ref = part->emplace_back();
|
382
|
+
part = std::addressof(ref);
|
383
|
+
}
|
384
|
+
else
|
385
|
+
{
|
386
|
+
part = &part->at(n);
|
387
|
+
}
|
388
|
+
}
|
389
|
+
else
|
390
|
+
{
|
391
|
+
Json& ref = part->emplace_back(item.value());
|
392
|
+
part = std::addressof(ref);
|
393
|
+
}
|
394
|
+
}
|
395
|
+
buffer.clear();
|
396
|
+
state = unflatten_state::expect_lbracket;
|
397
|
+
break;
|
398
|
+
}
|
399
|
+
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8':case '9':
|
400
|
+
buffer.push_back(*it);
|
401
|
+
break;
|
402
|
+
default:
|
403
|
+
JSONCONS_THROW(jsonpath_error(jsonpath_errc::invalid_flattened_key));
|
404
|
+
break;
|
405
|
+
}
|
406
|
+
break;
|
407
|
+
}
|
408
|
+
case unflatten_state::expect_rbracket:
|
409
|
+
{
|
410
|
+
switch (*it)
|
411
|
+
{
|
412
|
+
case ']':
|
413
|
+
state = unflatten_state::expect_lbracket;
|
414
|
+
break;
|
415
|
+
default:
|
416
|
+
JSONCONS_THROW(jsonpath_error(jsonpath_errc::invalid_flattened_key));
|
417
|
+
break;
|
418
|
+
}
|
419
|
+
break;
|
420
|
+
}
|
421
|
+
default:
|
422
|
+
JSONCONS_UNREACHABLE();
|
423
|
+
break;
|
424
|
+
}
|
425
|
+
}
|
426
|
+
}
|
427
|
+
|
428
|
+
return result;
|
429
|
+
}
|
430
|
+
}}
|
431
|
+
|
432
|
+
#endif
|