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,358 @@
|
|
1
|
+
// Copyright 2018 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_CSV_CSV_CURSOR_HPP
|
8
|
+
#define JSONCONS_CSV_CSV_CURSOR_HPP
|
9
|
+
|
10
|
+
#include <memory> // std::allocator
|
11
|
+
#include <string>
|
12
|
+
#include <vector>
|
13
|
+
#include <stdexcept>
|
14
|
+
#include <system_error>
|
15
|
+
#include <ios>
|
16
|
+
#include <istream> // std::basic_istream
|
17
|
+
#include <jsoncons/byte_string.hpp>
|
18
|
+
#include <jsoncons/config/jsoncons_config.hpp>
|
19
|
+
#include <jsoncons/json_visitor.hpp>
|
20
|
+
#include <jsoncons/json_exception.hpp>
|
21
|
+
#include <jsoncons_ext/csv/csv_parser.hpp>
|
22
|
+
#include <jsoncons/staj_cursor.hpp>
|
23
|
+
#include <jsoncons/source.hpp>
|
24
|
+
#include <jsoncons/source_adaptor.hpp>
|
25
|
+
|
26
|
+
namespace jsoncons { namespace csv {
|
27
|
+
|
28
|
+
template<class CharT,class Source=jsoncons::stream_source<CharT>,class Allocator=std::allocator<char>>
|
29
|
+
class basic_csv_cursor : public basic_staj_cursor<CharT>, private virtual ser_context
|
30
|
+
{
|
31
|
+
public:
|
32
|
+
using source_type = Source;
|
33
|
+
using char_type = CharT;
|
34
|
+
using allocator_type = Allocator;
|
35
|
+
private:
|
36
|
+
static constexpr size_t default_max_buffer_size = 16384;
|
37
|
+
|
38
|
+
typedef typename std::allocator_traits<allocator_type>:: template rebind_alloc<CharT> char_allocator_type;
|
39
|
+
|
40
|
+
text_source_adaptor<Source> source_;
|
41
|
+
basic_csv_parser<CharT,Allocator> parser_;
|
42
|
+
basic_staj_visitor<CharT> cursor_visitor_;
|
43
|
+
|
44
|
+
// Noncopyable and nonmoveable
|
45
|
+
basic_csv_cursor(const basic_csv_cursor&) = delete;
|
46
|
+
basic_csv_cursor& operator=(const basic_csv_cursor&) = delete;
|
47
|
+
|
48
|
+
public:
|
49
|
+
using string_view_type = jsoncons::basic_string_view<CharT>;
|
50
|
+
|
51
|
+
// Constructors that throw parse exceptions
|
52
|
+
|
53
|
+
template <class Sourceable>
|
54
|
+
basic_csv_cursor(Sourceable&& source,
|
55
|
+
const basic_csv_decode_options<CharT>& options = basic_csv_decode_options<CharT>(),
|
56
|
+
std::function<bool(csv_errc,const ser_context&)> err_handler = default_csv_parsing(),
|
57
|
+
const Allocator& alloc = Allocator(),
|
58
|
+
typename std::enable_if<!std::is_constructible<jsoncons::basic_string_view<CharT>,Sourceable>::value>::type* = 0)
|
59
|
+
: source_(std::forward<Sourceable>(source)),
|
60
|
+
parser_(options,err_handler,alloc),
|
61
|
+
cursor_visitor_(accept_all)
|
62
|
+
{
|
63
|
+
if (!done())
|
64
|
+
{
|
65
|
+
next();
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
template <class Sourceable>
|
70
|
+
basic_csv_cursor(Sourceable&& source,
|
71
|
+
const basic_csv_decode_options<CharT>& options = basic_csv_decode_options<CharT>(),
|
72
|
+
std::function<bool(csv_errc,const ser_context&)> err_handler = default_csv_parsing(),
|
73
|
+
const Allocator& alloc = Allocator(),
|
74
|
+
typename std::enable_if<std::is_constructible<jsoncons::basic_string_view<CharT>,Sourceable>::value>::type* = 0)
|
75
|
+
: source_(),
|
76
|
+
parser_(options,err_handler,alloc),
|
77
|
+
cursor_visitor_(accept_all)
|
78
|
+
{
|
79
|
+
jsoncons::basic_string_view<CharT> sv(std::forward<Sourceable>(source));
|
80
|
+
initialize_with_string_view(sv);
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
// Constructors that set parse error codes
|
85
|
+
template <class Sourceable>
|
86
|
+
basic_csv_cursor(Sourceable&& source,
|
87
|
+
std::error_code& ec)
|
88
|
+
: basic_csv_cursor(std::allocator_arg, Allocator(),
|
89
|
+
std::forward<Sourceable>(source),
|
90
|
+
basic_csv_decode_options<CharT>(),
|
91
|
+
default_csv_parsing(),
|
92
|
+
ec)
|
93
|
+
{
|
94
|
+
}
|
95
|
+
|
96
|
+
template <class Sourceable>
|
97
|
+
basic_csv_cursor(Sourceable&& source,
|
98
|
+
const basic_csv_decode_options<CharT>& options,
|
99
|
+
std::error_code& ec)
|
100
|
+
: basic_csv_cursor(std::allocator_arg, Allocator(),
|
101
|
+
std::forward<Sourceable>(source),
|
102
|
+
options,
|
103
|
+
default_csv_parsing(),
|
104
|
+
ec)
|
105
|
+
{
|
106
|
+
}
|
107
|
+
|
108
|
+
template <class Sourceable>
|
109
|
+
basic_csv_cursor(Sourceable&& source,
|
110
|
+
const basic_csv_decode_options<CharT>& options,
|
111
|
+
std::function<bool(csv_errc,const ser_context&)> err_handler,
|
112
|
+
std::error_code& ec)
|
113
|
+
: basic_csv_cursor(std::allocator_arg, Allocator(),
|
114
|
+
std::forward<Sourceable>(source),
|
115
|
+
options,
|
116
|
+
err_handler,
|
117
|
+
ec)
|
118
|
+
{
|
119
|
+
}
|
120
|
+
|
121
|
+
template <class Sourceable>
|
122
|
+
basic_csv_cursor(std::allocator_arg_t, const Allocator& alloc,
|
123
|
+
Sourceable&& source,
|
124
|
+
const basic_csv_decode_options<CharT>& options,
|
125
|
+
std::function<bool(csv_errc,const ser_context&)> err_handler,
|
126
|
+
std::error_code& ec,
|
127
|
+
typename std::enable_if<!std::is_constructible<jsoncons::basic_string_view<CharT>,Sourceable>::value>::type* = 0)
|
128
|
+
: source_(std::forward<Sourceable>(source)),
|
129
|
+
parser_(options,err_handler,alloc),
|
130
|
+
cursor_visitor_(accept_all)
|
131
|
+
{
|
132
|
+
if (!done())
|
133
|
+
{
|
134
|
+
next(ec);
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
template <class Sourceable>
|
139
|
+
basic_csv_cursor(std::allocator_arg_t, const Allocator& alloc,
|
140
|
+
Sourceable&& source,
|
141
|
+
const basic_csv_decode_options<CharT>& options,
|
142
|
+
std::function<bool(csv_errc,const ser_context&)> err_handler,
|
143
|
+
std::error_code& ec,
|
144
|
+
typename std::enable_if<std::is_constructible<jsoncons::basic_string_view<CharT>,Sourceable>::value>::type* = 0)
|
145
|
+
: source_(),
|
146
|
+
parser_(options,err_handler,alloc),
|
147
|
+
cursor_visitor_(accept_all)
|
148
|
+
{
|
149
|
+
jsoncons::basic_string_view<CharT> sv(std::forward<Sourceable>(source));
|
150
|
+
initialize_with_string_view(sv, ec);
|
151
|
+
}
|
152
|
+
|
153
|
+
template <class Sourceable>
|
154
|
+
typename std::enable_if<!std::is_constructible<jsoncons::basic_string_view<CharT>,Sourceable>::value>::type
|
155
|
+
reset(Sourceable&& source)
|
156
|
+
{
|
157
|
+
source_ = std::forward<Sourceable>(source);
|
158
|
+
parser_.reinitialize();
|
159
|
+
cursor_visitor_.reset();
|
160
|
+
if (!done())
|
161
|
+
{
|
162
|
+
next();
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
template <class Sourceable>
|
167
|
+
typename std::enable_if<std::is_constructible<jsoncons::basic_string_view<CharT>,Sourceable>::value>::type
|
168
|
+
reset(Sourceable&& source)
|
169
|
+
{
|
170
|
+
source_ = {};
|
171
|
+
parser_.reinitialize();
|
172
|
+
cursor_visitor_.reset();
|
173
|
+
initialize_with_string_view(std::forward<Sourceable>(source));
|
174
|
+
}
|
175
|
+
|
176
|
+
template <class Sourceable>
|
177
|
+
typename std::enable_if<!std::is_constructible<jsoncons::basic_string_view<CharT>,Sourceable>::value>::type
|
178
|
+
reset(Sourceable&& source, std::error_code& ec)
|
179
|
+
{
|
180
|
+
source_ = std::forward<Sourceable>(source);
|
181
|
+
parser_.reinitialize();
|
182
|
+
cursor_visitor_.reset();
|
183
|
+
if (!done())
|
184
|
+
{
|
185
|
+
next(ec);
|
186
|
+
}
|
187
|
+
}
|
188
|
+
|
189
|
+
template <class Sourceable>
|
190
|
+
typename std::enable_if<std::is_constructible<jsoncons::basic_string_view<CharT>,Sourceable>::value>::type
|
191
|
+
reset(Sourceable&& source, std::error_code& ec)
|
192
|
+
{
|
193
|
+
source_ = {};
|
194
|
+
parser_.reinitialize();
|
195
|
+
initialize_with_string_view(std::forward<Sourceable>(source), ec);
|
196
|
+
}
|
197
|
+
|
198
|
+
bool done() const override
|
199
|
+
{
|
200
|
+
return parser_.done();
|
201
|
+
}
|
202
|
+
|
203
|
+
const basic_staj_event<CharT>& current() const override
|
204
|
+
{
|
205
|
+
return cursor_visitor_.event();
|
206
|
+
}
|
207
|
+
|
208
|
+
void read_to(basic_json_visitor<CharT>& visitor) override
|
209
|
+
{
|
210
|
+
std::error_code ec;
|
211
|
+
read_to(visitor, ec);
|
212
|
+
if (ec)
|
213
|
+
{
|
214
|
+
JSONCONS_THROW(ser_error(ec,parser_.line(),parser_.column()));
|
215
|
+
}
|
216
|
+
}
|
217
|
+
|
218
|
+
void read_to(basic_json_visitor<CharT>& visitor,
|
219
|
+
std::error_code& ec) override
|
220
|
+
{
|
221
|
+
if (send_json_event(cursor_visitor_.event(), visitor, *this, ec))
|
222
|
+
{
|
223
|
+
read_next(visitor, ec);
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
void next() override
|
228
|
+
{
|
229
|
+
std::error_code ec;
|
230
|
+
next(ec);
|
231
|
+
if (ec)
|
232
|
+
{
|
233
|
+
JSONCONS_THROW(ser_error(ec,parser_.line(),parser_.column()));
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
237
|
+
void next(std::error_code& ec) override
|
238
|
+
{
|
239
|
+
read_next(ec);
|
240
|
+
}
|
241
|
+
|
242
|
+
static bool accept_all(const basic_staj_event<CharT>&, const ser_context&)
|
243
|
+
{
|
244
|
+
return true;
|
245
|
+
}
|
246
|
+
|
247
|
+
const ser_context& context() const override
|
248
|
+
{
|
249
|
+
return *this;
|
250
|
+
}
|
251
|
+
|
252
|
+
bool eof() const
|
253
|
+
{
|
254
|
+
return parser_.source_exhausted() && source_.eof();
|
255
|
+
}
|
256
|
+
|
257
|
+
std::size_t line() const override
|
258
|
+
{
|
259
|
+
return parser_.line();
|
260
|
+
}
|
261
|
+
|
262
|
+
std::size_t column() const override
|
263
|
+
{
|
264
|
+
return parser_.column();
|
265
|
+
}
|
266
|
+
|
267
|
+
friend
|
268
|
+
basic_staj_filter_view<CharT> operator|(basic_csv_cursor& cursor,
|
269
|
+
std::function<bool(const basic_staj_event<CharT>&, const ser_context&)> pred)
|
270
|
+
{
|
271
|
+
return basic_staj_filter_view<CharT>(cursor, pred);
|
272
|
+
}
|
273
|
+
|
274
|
+
#if !defined(JSONCONS_NO_DEPRECATED)
|
275
|
+
|
276
|
+
JSONCONS_DEPRECATED_MSG("Instead, use read_to(basic_json_visitor<CharT>&)")
|
277
|
+
void read(basic_json_visitor<CharT>& visitor)
|
278
|
+
{
|
279
|
+
read_to(visitor);
|
280
|
+
}
|
281
|
+
|
282
|
+
JSONCONS_DEPRECATED_MSG("Instead, use read_to(basic_json_visitor<CharT>&, std::error_code&)")
|
283
|
+
void read(basic_json_visitor<CharT>& visitor,
|
284
|
+
std::error_code& ec)
|
285
|
+
{
|
286
|
+
read_to(visitor, ec);
|
287
|
+
}
|
288
|
+
#endif
|
289
|
+
private:
|
290
|
+
|
291
|
+
void initialize_with_string_view(string_view_type sv)
|
292
|
+
{
|
293
|
+
auto r = unicode_traits::detect_json_encoding(sv.data(), sv.size());
|
294
|
+
if (!(r.encoding == unicode_traits::encoding_kind::utf8 || r.encoding == unicode_traits::encoding_kind::undetected))
|
295
|
+
{
|
296
|
+
JSONCONS_THROW(ser_error(json_errc::illegal_unicode_character,parser_.line(),parser_.column()));
|
297
|
+
}
|
298
|
+
std::size_t offset = (r.ptr - sv.data());
|
299
|
+
parser_.update(sv.data()+offset,sv.size()-offset);
|
300
|
+
if (!done())
|
301
|
+
{
|
302
|
+
next();
|
303
|
+
}
|
304
|
+
}
|
305
|
+
|
306
|
+
void initialize_with_string_view(string_view_type sv, std::error_code& ec)
|
307
|
+
{
|
308
|
+
auto r = unicode_traits::detect_encoding_from_bom(sv.data(), sv.size());
|
309
|
+
if (!(r.encoding == unicode_traits::encoding_kind::utf8 || r.encoding == unicode_traits::encoding_kind::undetected))
|
310
|
+
{
|
311
|
+
ec = json_errc::illegal_unicode_character;
|
312
|
+
return;
|
313
|
+
}
|
314
|
+
std::size_t offset = (r.ptr - sv.data());
|
315
|
+
parser_.update(sv.data()+offset,sv.size()-offset);
|
316
|
+
if (!done())
|
317
|
+
{
|
318
|
+
next(ec);
|
319
|
+
}
|
320
|
+
}
|
321
|
+
|
322
|
+
void read_next(std::error_code& ec)
|
323
|
+
{
|
324
|
+
read_next(cursor_visitor_, ec);
|
325
|
+
}
|
326
|
+
|
327
|
+
void read_next(basic_json_visitor<CharT>& visitor, std::error_code& ec)
|
328
|
+
{
|
329
|
+
parser_.restart();
|
330
|
+
while (!parser_.stopped())
|
331
|
+
{
|
332
|
+
if (parser_.source_exhausted())
|
333
|
+
{
|
334
|
+
auto s = source_.read_buffer(ec);
|
335
|
+
if (ec) return;
|
336
|
+
if (s.size() > 0)
|
337
|
+
{
|
338
|
+
parser_.update(s.data(),s.size());
|
339
|
+
}
|
340
|
+
}
|
341
|
+
parser_.parse_some(visitor, ec);
|
342
|
+
if (ec) return;
|
343
|
+
}
|
344
|
+
}
|
345
|
+
};
|
346
|
+
|
347
|
+
using csv_stream_cursor = basic_csv_cursor<char,jsoncons::stream_source<char>>;
|
348
|
+
using csv_string_cursor = basic_csv_cursor<char,jsoncons::string_source<char>>;
|
349
|
+
using wcsv_stream_cursor = basic_csv_cursor<wchar_t,jsoncons::stream_source<wchar_t>>;
|
350
|
+
using wcsv_string_cursor = basic_csv_cursor<wchar_t,jsoncons::string_source<wchar_t>>;
|
351
|
+
|
352
|
+
using csv_cursor = basic_csv_cursor<char>;
|
353
|
+
using wcsv_cursor = basic_csv_cursor<wchar_t>;
|
354
|
+
|
355
|
+
}}
|
356
|
+
|
357
|
+
#endif
|
358
|
+
|