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,973 @@
|
|
1
|
+
// Copyright 2013 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_OPTIONS_HPP
|
8
|
+
#define JSONCONS_CSV_CSV_OPTIONS_HPP
|
9
|
+
|
10
|
+
#include <string>
|
11
|
+
#include <vector>
|
12
|
+
#include <utility> // std::pair
|
13
|
+
#include <unordered_map> // std::unordered_map
|
14
|
+
#include <map>
|
15
|
+
#include <limits> // std::numeric_limits
|
16
|
+
#include <cwchar>
|
17
|
+
#include <jsoncons/json_options.hpp>
|
18
|
+
|
19
|
+
namespace jsoncons { namespace csv {
|
20
|
+
|
21
|
+
enum class csv_column_type : uint8_t
|
22
|
+
{
|
23
|
+
string_t,integer_t,float_t,boolean_t,repeat_t
|
24
|
+
};
|
25
|
+
|
26
|
+
enum class quote_style_kind : uint8_t
|
27
|
+
{
|
28
|
+
minimal,all,nonnumeric,none
|
29
|
+
};
|
30
|
+
|
31
|
+
enum class csv_mapping_kind : uint8_t
|
32
|
+
{
|
33
|
+
n_rows = 1,
|
34
|
+
n_objects,
|
35
|
+
m_columns
|
36
|
+
};
|
37
|
+
|
38
|
+
#if !defined(JSONCONS_NO_DEPRECATED)
|
39
|
+
using mapping_kind = csv_mapping_kind;
|
40
|
+
JSONCONS_DEPRECATED_MSG("Instead, use quote_style_kind") typedef quote_style_kind quote_styles;
|
41
|
+
JSONCONS_DEPRECATED_MSG("Instead, use quote_style_kind") typedef quote_style_kind quote_style_type;
|
42
|
+
JSONCONS_DEPRECATED_MSG("Instead, use csv_mapping_kind") typedef csv_mapping_kind mapping_type;
|
43
|
+
#endif
|
44
|
+
|
45
|
+
enum class column_state {sequence,label};
|
46
|
+
|
47
|
+
struct csv_type_info
|
48
|
+
{
|
49
|
+
csv_type_info() = default;
|
50
|
+
csv_type_info(const csv_type_info&) = default;
|
51
|
+
csv_type_info(csv_type_info&&) = default;
|
52
|
+
|
53
|
+
csv_type_info(csv_column_type ctype, std::size_t lev, std::size_t repcount = 0) noexcept
|
54
|
+
{
|
55
|
+
col_type = ctype;
|
56
|
+
level = lev;
|
57
|
+
rep_count = repcount;
|
58
|
+
}
|
59
|
+
|
60
|
+
csv_column_type col_type;
|
61
|
+
std::size_t level;
|
62
|
+
std::size_t rep_count;
|
63
|
+
};
|
64
|
+
|
65
|
+
namespace detail {
|
66
|
+
|
67
|
+
template <class CharT,class Container>
|
68
|
+
void parse_column_names(const std::basic_string<CharT>& names,
|
69
|
+
Container& cont)
|
70
|
+
{
|
71
|
+
column_state state = column_state::sequence;
|
72
|
+
typename Container::value_type buffer(cont.get_allocator());
|
73
|
+
|
74
|
+
auto p = names.begin();
|
75
|
+
while (p != names.end())
|
76
|
+
{
|
77
|
+
switch (state)
|
78
|
+
{
|
79
|
+
case column_state::sequence:
|
80
|
+
{
|
81
|
+
switch (*p)
|
82
|
+
{
|
83
|
+
case ' ': case '\t':case '\r': case '\n':
|
84
|
+
++p;
|
85
|
+
break;
|
86
|
+
default:
|
87
|
+
buffer.clear();
|
88
|
+
state = column_state::label;
|
89
|
+
break;
|
90
|
+
}
|
91
|
+
break;
|
92
|
+
}
|
93
|
+
case column_state::label:
|
94
|
+
{
|
95
|
+
switch (*p)
|
96
|
+
{
|
97
|
+
case ',':
|
98
|
+
cont.push_back(buffer);
|
99
|
+
buffer.clear();
|
100
|
+
++p;
|
101
|
+
state = column_state::sequence;
|
102
|
+
break;
|
103
|
+
default:
|
104
|
+
buffer.push_back(*p);
|
105
|
+
++p;
|
106
|
+
break;
|
107
|
+
}
|
108
|
+
break;
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
if (state == column_state::label)
|
113
|
+
{
|
114
|
+
cont.push_back(buffer);
|
115
|
+
buffer.clear();
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
template <class CharT,class Container>
|
120
|
+
void parse_column_types(const std::basic_string<CharT>& types,
|
121
|
+
Container& column_types)
|
122
|
+
{
|
123
|
+
const std::map<jsoncons::basic_string_view<CharT>,csv_column_type> type_dictionary =
|
124
|
+
{
|
125
|
+
|
126
|
+
{JSONCONS_STRING_VIEW_CONSTANT(CharT,"string"),csv_column_type::string_t},
|
127
|
+
{JSONCONS_STRING_VIEW_CONSTANT(CharT,"integer"),csv_column_type::integer_t},
|
128
|
+
{JSONCONS_STRING_VIEW_CONSTANT(CharT,"float"),csv_column_type::float_t},
|
129
|
+
{JSONCONS_STRING_VIEW_CONSTANT(CharT,"boolean"),csv_column_type::boolean_t}
|
130
|
+
};
|
131
|
+
|
132
|
+
column_state state = column_state::sequence;
|
133
|
+
int depth = 0;
|
134
|
+
std::basic_string<CharT> buffer;
|
135
|
+
|
136
|
+
auto p = types.begin();
|
137
|
+
while (p != types.end())
|
138
|
+
{
|
139
|
+
switch (state)
|
140
|
+
{
|
141
|
+
case column_state::sequence:
|
142
|
+
{
|
143
|
+
switch (*p)
|
144
|
+
{
|
145
|
+
case ' ': case '\t':case '\r': case '\n':
|
146
|
+
++p;
|
147
|
+
break;
|
148
|
+
case '[':
|
149
|
+
++depth;
|
150
|
+
++p;
|
151
|
+
break;
|
152
|
+
case ']':
|
153
|
+
JSONCONS_ASSERT(depth > 0);
|
154
|
+
--depth;
|
155
|
+
++p;
|
156
|
+
break;
|
157
|
+
case '*':
|
158
|
+
{
|
159
|
+
JSONCONS_ASSERT(column_types.size() != 0);
|
160
|
+
std::size_t offset = 0;
|
161
|
+
std::size_t level = column_types.size() > 0 ? column_types.back().level: 0;
|
162
|
+
if (level > 0)
|
163
|
+
{
|
164
|
+
for (auto it = column_types.rbegin();
|
165
|
+
it != column_types.rend() && level == it->level;
|
166
|
+
++it)
|
167
|
+
{
|
168
|
+
++offset;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
else
|
172
|
+
{
|
173
|
+
offset = 1;
|
174
|
+
}
|
175
|
+
column_types.emplace_back(csv_column_type::repeat_t,depth,offset);
|
176
|
+
++p;
|
177
|
+
break;
|
178
|
+
}
|
179
|
+
default:
|
180
|
+
buffer.clear();
|
181
|
+
state = column_state::label;
|
182
|
+
break;
|
183
|
+
}
|
184
|
+
break;
|
185
|
+
}
|
186
|
+
case column_state::label:
|
187
|
+
{
|
188
|
+
switch (*p)
|
189
|
+
{
|
190
|
+
case '*':
|
191
|
+
{
|
192
|
+
auto it = type_dictionary.find(buffer);
|
193
|
+
if (it != type_dictionary.end())
|
194
|
+
{
|
195
|
+
column_types.emplace_back(it->second,depth);
|
196
|
+
buffer.clear();
|
197
|
+
}
|
198
|
+
else
|
199
|
+
{
|
200
|
+
JSONCONS_ASSERT(false);
|
201
|
+
}
|
202
|
+
state = column_state::sequence;
|
203
|
+
break;
|
204
|
+
}
|
205
|
+
case ',':
|
206
|
+
{
|
207
|
+
auto it = type_dictionary.find(buffer);
|
208
|
+
if (it != type_dictionary.end())
|
209
|
+
{
|
210
|
+
column_types.emplace_back(it->second,depth);
|
211
|
+
buffer.clear();
|
212
|
+
}
|
213
|
+
else
|
214
|
+
{
|
215
|
+
JSONCONS_ASSERT(false);
|
216
|
+
}
|
217
|
+
++p;
|
218
|
+
state = column_state::sequence;
|
219
|
+
break;
|
220
|
+
}
|
221
|
+
case ']':
|
222
|
+
{
|
223
|
+
JSONCONS_ASSERT(depth > 0);
|
224
|
+
auto it = type_dictionary.find(buffer);
|
225
|
+
if (it != type_dictionary.end())
|
226
|
+
{
|
227
|
+
column_types.emplace_back(it->second,depth);
|
228
|
+
buffer.clear();
|
229
|
+
}
|
230
|
+
else
|
231
|
+
{
|
232
|
+
JSONCONS_ASSERT(false);
|
233
|
+
}
|
234
|
+
--depth;
|
235
|
+
++p;
|
236
|
+
state = column_state::sequence;
|
237
|
+
break;
|
238
|
+
}
|
239
|
+
default:
|
240
|
+
{
|
241
|
+
buffer.push_back(*p);
|
242
|
+
++p;
|
243
|
+
break;
|
244
|
+
}
|
245
|
+
}
|
246
|
+
break;
|
247
|
+
}
|
248
|
+
}
|
249
|
+
}
|
250
|
+
if (state == column_state::label)
|
251
|
+
{
|
252
|
+
auto it = type_dictionary.find(buffer);
|
253
|
+
if (it != type_dictionary.end())
|
254
|
+
{
|
255
|
+
column_types.emplace_back(it->second,depth);
|
256
|
+
buffer.clear();
|
257
|
+
}
|
258
|
+
else
|
259
|
+
{
|
260
|
+
JSONCONS_ASSERT(false);
|
261
|
+
}
|
262
|
+
}
|
263
|
+
}
|
264
|
+
|
265
|
+
} // detail
|
266
|
+
|
267
|
+
template <class CharT>
|
268
|
+
class basic_csv_options;
|
269
|
+
|
270
|
+
template <class CharT>
|
271
|
+
class basic_csv_options_common
|
272
|
+
{
|
273
|
+
friend class basic_csv_options<CharT>;
|
274
|
+
public:
|
275
|
+
using char_type = CharT;
|
276
|
+
using string_type = std::basic_string<CharT>;
|
277
|
+
private:
|
278
|
+
char_type field_delimiter_;
|
279
|
+
char_type quote_char_;
|
280
|
+
char_type quote_escape_char_;
|
281
|
+
char_type subfield_delimiter_;
|
282
|
+
|
283
|
+
bool enable_nan_to_num_:1;
|
284
|
+
bool enable_inf_to_num_:1;
|
285
|
+
bool enable_neginf_to_num_:1;
|
286
|
+
bool enable_nan_to_str_:1;
|
287
|
+
bool enable_inf_to_str_:1;
|
288
|
+
bool enable_neginf_to_str_:1;
|
289
|
+
bool enable_str_to_nan_:1;
|
290
|
+
bool enable_str_to_inf_:1;
|
291
|
+
bool enable_str_to_neginf_:1;
|
292
|
+
|
293
|
+
string_type nan_to_num_;
|
294
|
+
string_type inf_to_num_;
|
295
|
+
string_type neginf_to_num_;
|
296
|
+
string_type nan_to_str_;
|
297
|
+
string_type inf_to_str_;
|
298
|
+
string_type neginf_to_str_;
|
299
|
+
string_type column_names_;
|
300
|
+
|
301
|
+
protected:
|
302
|
+
basic_csv_options_common()
|
303
|
+
: field_delimiter_(','),
|
304
|
+
quote_char_('\"'),
|
305
|
+
quote_escape_char_('\"'),
|
306
|
+
subfield_delimiter_(char_type()),
|
307
|
+
enable_nan_to_num_(false),
|
308
|
+
enable_inf_to_num_(false),
|
309
|
+
enable_neginf_to_num_(false),
|
310
|
+
enable_nan_to_str_(false),
|
311
|
+
enable_inf_to_str_(false),
|
312
|
+
enable_neginf_to_str_(false),
|
313
|
+
enable_str_to_nan_(false),
|
314
|
+
enable_str_to_inf_(false),
|
315
|
+
enable_str_to_neginf_(false)
|
316
|
+
{
|
317
|
+
}
|
318
|
+
|
319
|
+
basic_csv_options_common(const basic_csv_options_common&) = default;
|
320
|
+
basic_csv_options_common& operator=(const basic_csv_options_common&) = default;
|
321
|
+
|
322
|
+
virtual ~basic_csv_options_common() noexcept = default;
|
323
|
+
public:
|
324
|
+
|
325
|
+
char_type field_delimiter() const
|
326
|
+
{
|
327
|
+
return field_delimiter_;
|
328
|
+
}
|
329
|
+
|
330
|
+
const char_type subfield_delimiter() const
|
331
|
+
{
|
332
|
+
return subfield_delimiter_;
|
333
|
+
}
|
334
|
+
|
335
|
+
char_type quote_char() const
|
336
|
+
{
|
337
|
+
return quote_char_;
|
338
|
+
}
|
339
|
+
|
340
|
+
char_type quote_escape_char() const
|
341
|
+
{
|
342
|
+
return quote_escape_char_;
|
343
|
+
}
|
344
|
+
|
345
|
+
string_type column_names() const
|
346
|
+
{
|
347
|
+
return column_names_;
|
348
|
+
}
|
349
|
+
|
350
|
+
bool enable_nan_to_num() const
|
351
|
+
{
|
352
|
+
return enable_nan_to_num_;
|
353
|
+
}
|
354
|
+
|
355
|
+
bool enable_inf_to_num() const
|
356
|
+
{
|
357
|
+
return enable_inf_to_num_;
|
358
|
+
}
|
359
|
+
|
360
|
+
bool enable_neginf_to_num() const
|
361
|
+
{
|
362
|
+
return enable_neginf_to_num_ || enable_inf_to_num_;
|
363
|
+
}
|
364
|
+
|
365
|
+
bool enable_nan_to_str() const
|
366
|
+
{
|
367
|
+
return enable_nan_to_str_;
|
368
|
+
}
|
369
|
+
|
370
|
+
bool enable_str_to_nan() const
|
371
|
+
{
|
372
|
+
return enable_str_to_nan_;
|
373
|
+
}
|
374
|
+
|
375
|
+
bool enable_inf_to_str() const
|
376
|
+
{
|
377
|
+
return enable_inf_to_str_;
|
378
|
+
}
|
379
|
+
|
380
|
+
bool enable_str_to_inf() const
|
381
|
+
{
|
382
|
+
return enable_str_to_inf_;
|
383
|
+
}
|
384
|
+
|
385
|
+
bool enable_neginf_to_str() const
|
386
|
+
{
|
387
|
+
return enable_neginf_to_str_ || enable_inf_to_str_;
|
388
|
+
}
|
389
|
+
|
390
|
+
bool enable_str_to_neginf() const
|
391
|
+
{
|
392
|
+
return enable_str_to_neginf_ || enable_str_to_inf_;
|
393
|
+
}
|
394
|
+
|
395
|
+
string_type nan_to_num() const
|
396
|
+
{
|
397
|
+
return nan_to_num_;
|
398
|
+
}
|
399
|
+
|
400
|
+
string_type inf_to_num() const
|
401
|
+
{
|
402
|
+
return inf_to_num_;
|
403
|
+
}
|
404
|
+
|
405
|
+
string_type neginf_to_num() const
|
406
|
+
{
|
407
|
+
if (enable_neginf_to_num_)
|
408
|
+
{
|
409
|
+
return neginf_to_num_;
|
410
|
+
}
|
411
|
+
else if (enable_inf_to_num_)
|
412
|
+
{
|
413
|
+
string_type s;
|
414
|
+
s.push_back('-');
|
415
|
+
s.append(inf_to_num_);
|
416
|
+
return s;
|
417
|
+
}
|
418
|
+
else
|
419
|
+
{
|
420
|
+
return neginf_to_num_;
|
421
|
+
}
|
422
|
+
}
|
423
|
+
|
424
|
+
string_type nan_to_str() const
|
425
|
+
{
|
426
|
+
return nan_to_str_;
|
427
|
+
}
|
428
|
+
|
429
|
+
string_type inf_to_str() const
|
430
|
+
{
|
431
|
+
return inf_to_str_;
|
432
|
+
}
|
433
|
+
|
434
|
+
string_type neginf_to_str() const
|
435
|
+
{
|
436
|
+
if (enable_neginf_to_str_)
|
437
|
+
{
|
438
|
+
return neginf_to_str_;
|
439
|
+
}
|
440
|
+
else if (enable_inf_to_str_)
|
441
|
+
{
|
442
|
+
string_type s;
|
443
|
+
s.push_back('-');
|
444
|
+
s.append(inf_to_str_);
|
445
|
+
return s;
|
446
|
+
}
|
447
|
+
else
|
448
|
+
{
|
449
|
+
return neginf_to_str_; // empty string
|
450
|
+
}
|
451
|
+
}
|
452
|
+
};
|
453
|
+
|
454
|
+
template <class CharT>
|
455
|
+
class basic_csv_decode_options : public virtual basic_csv_options_common<CharT>
|
456
|
+
{
|
457
|
+
friend class basic_csv_options<CharT>;
|
458
|
+
using super_type = basic_csv_options_common<CharT>;
|
459
|
+
public:
|
460
|
+
using typename super_type::char_type;
|
461
|
+
using typename super_type::string_type;
|
462
|
+
|
463
|
+
private:
|
464
|
+
bool assume_header_:1;
|
465
|
+
bool ignore_empty_values_:1;
|
466
|
+
bool ignore_empty_lines_:1;
|
467
|
+
bool trim_leading_:1;
|
468
|
+
bool trim_trailing_:1;
|
469
|
+
bool trim_leading_inside_quotes_:1;
|
470
|
+
bool trim_trailing_inside_quotes_:1;
|
471
|
+
bool unquoted_empty_value_is_null_:1;
|
472
|
+
bool infer_types_:1;
|
473
|
+
bool lossless_number_:1;
|
474
|
+
char_type comment_starter_;
|
475
|
+
csv_mapping_kind mapping_;
|
476
|
+
std::size_t header_lines_;
|
477
|
+
std::size_t max_lines_;
|
478
|
+
string_type column_types_;
|
479
|
+
string_type column_defaults_;
|
480
|
+
public:
|
481
|
+
basic_csv_decode_options()
|
482
|
+
: assume_header_(false),
|
483
|
+
ignore_empty_values_(false),
|
484
|
+
ignore_empty_lines_(true),
|
485
|
+
trim_leading_(false),
|
486
|
+
trim_trailing_(false),
|
487
|
+
trim_leading_inside_quotes_(false),
|
488
|
+
trim_trailing_inside_quotes_(false),
|
489
|
+
unquoted_empty_value_is_null_(false),
|
490
|
+
infer_types_(true),
|
491
|
+
lossless_number_(false),
|
492
|
+
comment_starter_('\0'),
|
493
|
+
mapping_(),
|
494
|
+
header_lines_(0),
|
495
|
+
max_lines_((std::numeric_limits<std::size_t>::max)())
|
496
|
+
{}
|
497
|
+
|
498
|
+
basic_csv_decode_options(const basic_csv_decode_options& other) = default;
|
499
|
+
|
500
|
+
basic_csv_decode_options(basic_csv_decode_options&& other)
|
501
|
+
: super_type(std::forward<basic_csv_decode_options>(other)),
|
502
|
+
assume_header_(other.assume_header_),
|
503
|
+
ignore_empty_values_(other.ignore_empty_values_),
|
504
|
+
ignore_empty_lines_(other.ignore_empty_lines_),
|
505
|
+
trim_leading_(other.trim_leading_),
|
506
|
+
trim_trailing_(other.trim_trailing_),
|
507
|
+
trim_leading_inside_quotes_(other.trim_leading_inside_quotes_),
|
508
|
+
trim_trailing_inside_quotes_(other.trim_trailing_inside_quotes_),
|
509
|
+
unquoted_empty_value_is_null_(other.unquoted_empty_value_is_null_),
|
510
|
+
infer_types_(other.infer_types_),
|
511
|
+
lossless_number_(other.lossless_number_),
|
512
|
+
comment_starter_(other.comment_starter_),
|
513
|
+
mapping_(other.mapping_),
|
514
|
+
header_lines_(other.header_lines_),
|
515
|
+
max_lines_(other.max_lines_),
|
516
|
+
column_types_(std::move(other.column_types_)),
|
517
|
+
column_defaults_(std::move(other.column_defaults_))
|
518
|
+
{}
|
519
|
+
|
520
|
+
std::size_t header_lines() const
|
521
|
+
{
|
522
|
+
return (assume_header_ && header_lines_ <= 1) ? 1 : header_lines_;
|
523
|
+
}
|
524
|
+
|
525
|
+
bool assume_header() const
|
526
|
+
{
|
527
|
+
return assume_header_;
|
528
|
+
}
|
529
|
+
|
530
|
+
bool ignore_empty_values() const
|
531
|
+
{
|
532
|
+
return ignore_empty_values_;
|
533
|
+
}
|
534
|
+
|
535
|
+
bool ignore_empty_lines() const
|
536
|
+
{
|
537
|
+
return ignore_empty_lines_;
|
538
|
+
}
|
539
|
+
|
540
|
+
bool trim_leading() const
|
541
|
+
{
|
542
|
+
return trim_leading_;
|
543
|
+
}
|
544
|
+
|
545
|
+
bool trim_trailing() const
|
546
|
+
{
|
547
|
+
return trim_trailing_;
|
548
|
+
}
|
549
|
+
|
550
|
+
bool trim_leading_inside_quotes() const
|
551
|
+
{
|
552
|
+
return trim_leading_inside_quotes_;
|
553
|
+
}
|
554
|
+
|
555
|
+
bool trim_trailing_inside_quotes() const
|
556
|
+
{
|
557
|
+
return trim_trailing_inside_quotes_;
|
558
|
+
}
|
559
|
+
|
560
|
+
bool trim() const
|
561
|
+
{
|
562
|
+
return trim_leading_ && trim_trailing_;
|
563
|
+
}
|
564
|
+
|
565
|
+
bool trim_inside_quotes() const
|
566
|
+
{
|
567
|
+
return trim_leading_inside_quotes_ && trim_trailing_inside_quotes_;
|
568
|
+
}
|
569
|
+
|
570
|
+
bool unquoted_empty_value_is_null() const
|
571
|
+
{
|
572
|
+
return unquoted_empty_value_is_null_;
|
573
|
+
}
|
574
|
+
|
575
|
+
bool infer_types() const
|
576
|
+
{
|
577
|
+
return infer_types_;
|
578
|
+
}
|
579
|
+
|
580
|
+
bool lossless_number() const
|
581
|
+
{
|
582
|
+
return lossless_number_;
|
583
|
+
}
|
584
|
+
|
585
|
+
char_type comment_starter() const
|
586
|
+
{
|
587
|
+
return comment_starter_;
|
588
|
+
}
|
589
|
+
|
590
|
+
csv_mapping_kind mapping_kind() const
|
591
|
+
{
|
592
|
+
return mapping_ != csv_mapping_kind() ? mapping_ : (assume_header() || this->column_names().size() > 0 ? csv_mapping_kind::n_objects : csv_mapping_kind::n_rows);
|
593
|
+
}
|
594
|
+
|
595
|
+
#if !defined(JSONCONS_NO_DEPRECATED)
|
596
|
+
csv_mapping_kind mapping() const
|
597
|
+
{
|
598
|
+
return mapping_kind();
|
599
|
+
}
|
600
|
+
#endif
|
601
|
+
|
602
|
+
std::size_t max_lines() const
|
603
|
+
{
|
604
|
+
return max_lines_;
|
605
|
+
}
|
606
|
+
|
607
|
+
string_type column_types() const
|
608
|
+
{
|
609
|
+
return column_types_;
|
610
|
+
}
|
611
|
+
|
612
|
+
string_type column_defaults() const
|
613
|
+
{
|
614
|
+
return column_defaults_;
|
615
|
+
}
|
616
|
+
};
|
617
|
+
|
618
|
+
template <class CharT>
|
619
|
+
class basic_csv_encode_options : public virtual basic_csv_options_common<CharT>
|
620
|
+
{
|
621
|
+
friend class basic_csv_options<CharT>;
|
622
|
+
using super_type = basic_csv_options_common<CharT>;
|
623
|
+
public:
|
624
|
+
using typename super_type::char_type;
|
625
|
+
using typename super_type::string_type;
|
626
|
+
private:
|
627
|
+
quote_style_kind quote_style_;
|
628
|
+
float_chars_format float_format_;
|
629
|
+
int8_t precision_;
|
630
|
+
string_type line_delimiter_;
|
631
|
+
public:
|
632
|
+
basic_csv_encode_options()
|
633
|
+
: quote_style_(quote_style_kind::minimal),
|
634
|
+
float_format_(float_chars_format::general),
|
635
|
+
precision_(0)
|
636
|
+
{
|
637
|
+
line_delimiter_.push_back('\n');
|
638
|
+
}
|
639
|
+
|
640
|
+
basic_csv_encode_options(const basic_csv_encode_options& other) = default;
|
641
|
+
|
642
|
+
basic_csv_encode_options(basic_csv_encode_options&& other)
|
643
|
+
: super_type(std::forward<basic_csv_encode_options>(other)),
|
644
|
+
quote_style_(other.quote_style_),
|
645
|
+
float_format_(other.float_format_),
|
646
|
+
precision_(other.precision_),
|
647
|
+
line_delimiter_(std::move(other.line_delimiter_))
|
648
|
+
{
|
649
|
+
}
|
650
|
+
|
651
|
+
quote_style_kind quote_style() const
|
652
|
+
{
|
653
|
+
return quote_style_;
|
654
|
+
}
|
655
|
+
|
656
|
+
float_chars_format float_format() const
|
657
|
+
{
|
658
|
+
return float_format_;
|
659
|
+
}
|
660
|
+
|
661
|
+
int8_t precision() const
|
662
|
+
{
|
663
|
+
return precision_;
|
664
|
+
}
|
665
|
+
|
666
|
+
string_type line_delimiter() const
|
667
|
+
{
|
668
|
+
return line_delimiter_;
|
669
|
+
}
|
670
|
+
};
|
671
|
+
|
672
|
+
template <class CharT>
|
673
|
+
class basic_csv_options final : public basic_csv_decode_options<CharT>, public basic_csv_encode_options<CharT>
|
674
|
+
{
|
675
|
+
using char_type = CharT;
|
676
|
+
using string_type = std::basic_string<CharT>;
|
677
|
+
|
678
|
+
public:
|
679
|
+
using basic_csv_decode_options<CharT>::enable_str_to_nan;
|
680
|
+
using basic_csv_decode_options<CharT>::enable_str_to_inf;
|
681
|
+
using basic_csv_decode_options<CharT>::enable_str_to_neginf;
|
682
|
+
using basic_csv_decode_options<CharT>::nan_to_str;
|
683
|
+
using basic_csv_decode_options<CharT>::inf_to_str;
|
684
|
+
using basic_csv_decode_options<CharT>::neginf_to_str;
|
685
|
+
using basic_csv_decode_options<CharT>::nan_to_num;
|
686
|
+
using basic_csv_decode_options<CharT>::inf_to_num;
|
687
|
+
using basic_csv_decode_options<CharT>::neginf_to_num;
|
688
|
+
using basic_csv_decode_options<CharT>::field_delimiter;
|
689
|
+
using basic_csv_decode_options<CharT>::subfield_delimiter;
|
690
|
+
using basic_csv_decode_options<CharT>::quote_char;
|
691
|
+
using basic_csv_decode_options<CharT>::quote_escape_char;
|
692
|
+
using basic_csv_decode_options<CharT>::column_names;
|
693
|
+
using basic_csv_decode_options<CharT>::header_lines;
|
694
|
+
using basic_csv_decode_options<CharT>::assume_header;
|
695
|
+
using basic_csv_decode_options<CharT>::ignore_empty_values;
|
696
|
+
using basic_csv_decode_options<CharT>::ignore_empty_lines;
|
697
|
+
using basic_csv_decode_options<CharT>::trim_leading;
|
698
|
+
using basic_csv_decode_options<CharT>::trim_trailing;
|
699
|
+
using basic_csv_decode_options<CharT>::trim_leading_inside_quotes;
|
700
|
+
using basic_csv_decode_options<CharT>::trim_trailing_inside_quotes;
|
701
|
+
using basic_csv_decode_options<CharT>::trim;
|
702
|
+
using basic_csv_decode_options<CharT>::trim_inside_quotes;
|
703
|
+
using basic_csv_decode_options<CharT>::unquoted_empty_value_is_null;
|
704
|
+
using basic_csv_decode_options<CharT>::infer_types;
|
705
|
+
using basic_csv_decode_options<CharT>::lossless_number;
|
706
|
+
using basic_csv_decode_options<CharT>::comment_starter;
|
707
|
+
using basic_csv_decode_options<CharT>::mapping;
|
708
|
+
using basic_csv_decode_options<CharT>::max_lines;
|
709
|
+
using basic_csv_decode_options<CharT>::column_types;
|
710
|
+
using basic_csv_decode_options<CharT>::column_defaults;
|
711
|
+
using basic_csv_encode_options<CharT>::float_format;
|
712
|
+
using basic_csv_encode_options<CharT>::precision;
|
713
|
+
using basic_csv_encode_options<CharT>::line_delimiter;
|
714
|
+
using basic_csv_encode_options<CharT>::quote_style;
|
715
|
+
|
716
|
+
static constexpr size_t default_indent = 4;
|
717
|
+
|
718
|
+
// Constructors
|
719
|
+
|
720
|
+
basic_csv_options() = default;
|
721
|
+
basic_csv_options(const basic_csv_options&) = default;
|
722
|
+
basic_csv_options(basic_csv_options&&) = default;
|
723
|
+
basic_csv_options& operator=(const basic_csv_options&) = default;
|
724
|
+
basic_csv_options& operator=(basic_csv_options&&) = default;
|
725
|
+
|
726
|
+
basic_csv_options& float_format(float_chars_format value)
|
727
|
+
{
|
728
|
+
this->float_format_ = value;
|
729
|
+
return *this;
|
730
|
+
}
|
731
|
+
|
732
|
+
basic_csv_options& precision(int8_t value)
|
733
|
+
{
|
734
|
+
this->precision_ = value;
|
735
|
+
return *this;
|
736
|
+
}
|
737
|
+
|
738
|
+
basic_csv_options& header_lines(std::size_t value)
|
739
|
+
{
|
740
|
+
this->header_lines_ = value;
|
741
|
+
return *this;
|
742
|
+
}
|
743
|
+
|
744
|
+
basic_csv_options& assume_header(bool value)
|
745
|
+
{
|
746
|
+
this->assume_header_ = value;
|
747
|
+
return *this;
|
748
|
+
}
|
749
|
+
|
750
|
+
basic_csv_options& ignore_empty_values(bool value)
|
751
|
+
{
|
752
|
+
this->ignore_empty_values_ = value;
|
753
|
+
return *this;
|
754
|
+
}
|
755
|
+
|
756
|
+
basic_csv_options& ignore_empty_lines(bool value)
|
757
|
+
{
|
758
|
+
this->ignore_empty_lines_ = value;
|
759
|
+
return *this;
|
760
|
+
}
|
761
|
+
|
762
|
+
basic_csv_options& trim_leading(bool value)
|
763
|
+
{
|
764
|
+
this->trim_leading_ = value;
|
765
|
+
return *this;
|
766
|
+
}
|
767
|
+
|
768
|
+
basic_csv_options& trim_trailing(bool value)
|
769
|
+
{
|
770
|
+
this->trim_trailing_ = value;
|
771
|
+
return *this;
|
772
|
+
}
|
773
|
+
|
774
|
+
basic_csv_options& trim_leading_inside_quotes(bool value)
|
775
|
+
{
|
776
|
+
this->trim_leading_inside_quotes_ = value;
|
777
|
+
return *this;
|
778
|
+
}
|
779
|
+
|
780
|
+
basic_csv_options& trim_trailing_inside_quotes(bool value)
|
781
|
+
{
|
782
|
+
this->trim_trailing_inside_quotes_ = value;
|
783
|
+
return *this;
|
784
|
+
}
|
785
|
+
|
786
|
+
basic_csv_options& trim(bool value)
|
787
|
+
{
|
788
|
+
this->trim_leading_ = value;
|
789
|
+
this->trim_trailing_ = value;
|
790
|
+
return *this;
|
791
|
+
}
|
792
|
+
|
793
|
+
basic_csv_options& trim_inside_quotes(bool value)
|
794
|
+
{
|
795
|
+
this->trim_leading_inside_quotes_ = value;
|
796
|
+
this->trim_trailing_inside_quotes_ = value;
|
797
|
+
return *this;
|
798
|
+
}
|
799
|
+
|
800
|
+
basic_csv_options& unquoted_empty_value_is_null(bool value)
|
801
|
+
{
|
802
|
+
this->unquoted_empty_value_is_null_ = value;
|
803
|
+
return *this;
|
804
|
+
}
|
805
|
+
|
806
|
+
basic_csv_options& column_names(const string_type& value)
|
807
|
+
{
|
808
|
+
this->column_names_ = value;
|
809
|
+
return *this;
|
810
|
+
}
|
811
|
+
|
812
|
+
basic_csv_options& column_types(const string_type& value)
|
813
|
+
{
|
814
|
+
this->column_types_ = value;
|
815
|
+
return *this;
|
816
|
+
}
|
817
|
+
|
818
|
+
basic_csv_options& column_defaults(const string_type& value)
|
819
|
+
{
|
820
|
+
this->column_defaults_ = value;
|
821
|
+
return *this;
|
822
|
+
}
|
823
|
+
|
824
|
+
basic_csv_options& field_delimiter(char_type value)
|
825
|
+
{
|
826
|
+
this->field_delimiter_ = value;
|
827
|
+
return *this;
|
828
|
+
}
|
829
|
+
|
830
|
+
basic_csv_options& subfield_delimiter(char_type value)
|
831
|
+
{
|
832
|
+
this->subfield_delimiter_ = value;
|
833
|
+
return *this;
|
834
|
+
}
|
835
|
+
|
836
|
+
basic_csv_options& line_delimiter(const string_type& value)
|
837
|
+
{
|
838
|
+
this->line_delimiter_ = value;
|
839
|
+
return *this;
|
840
|
+
}
|
841
|
+
|
842
|
+
basic_csv_options& quote_char(char_type value)
|
843
|
+
{
|
844
|
+
this->quote_char_ = value;
|
845
|
+
return *this;
|
846
|
+
}
|
847
|
+
|
848
|
+
basic_csv_options& infer_types(bool value)
|
849
|
+
{
|
850
|
+
this->infer_types_ = value;
|
851
|
+
return *this;
|
852
|
+
}
|
853
|
+
|
854
|
+
basic_csv_options& lossless_number(bool value)
|
855
|
+
{
|
856
|
+
this->lossless_number_ = value;
|
857
|
+
return *this;
|
858
|
+
}
|
859
|
+
|
860
|
+
basic_csv_options& quote_escape_char(char_type value)
|
861
|
+
{
|
862
|
+
this->quote_escape_char_ = value;
|
863
|
+
return *this;
|
864
|
+
}
|
865
|
+
|
866
|
+
basic_csv_options& comment_starter(char_type value)
|
867
|
+
{
|
868
|
+
this->comment_starter_ = value;
|
869
|
+
return *this;
|
870
|
+
}
|
871
|
+
|
872
|
+
basic_csv_options& quote_style(quote_style_kind value)
|
873
|
+
{
|
874
|
+
this->quote_style_ = value;
|
875
|
+
return *this;
|
876
|
+
}
|
877
|
+
|
878
|
+
//#if !defined(JSONCONS_NO_DEPRECATED)
|
879
|
+
basic_csv_options& mapping(csv_mapping_kind value)
|
880
|
+
{
|
881
|
+
this->mapping_ = value;
|
882
|
+
return *this;
|
883
|
+
}
|
884
|
+
//#endif
|
885
|
+
|
886
|
+
basic_csv_options& mapping_kind(csv_mapping_kind value)
|
887
|
+
{
|
888
|
+
this->mapping_ = value;
|
889
|
+
return *this;
|
890
|
+
}
|
891
|
+
|
892
|
+
basic_csv_options& max_lines(std::size_t value)
|
893
|
+
{
|
894
|
+
this->max_lines_ = value;
|
895
|
+
return *this;
|
896
|
+
}
|
897
|
+
|
898
|
+
basic_csv_options& nan_to_num(const string_type& value)
|
899
|
+
{
|
900
|
+
this->enable_nan_to_num_ = true;
|
901
|
+
this->nan_to_str_.clear();
|
902
|
+
this->nan_to_num_ = value;
|
903
|
+
return *this;
|
904
|
+
}
|
905
|
+
|
906
|
+
basic_csv_options& inf_to_num(const string_type& value)
|
907
|
+
{
|
908
|
+
this->enable_inf_to_num_ = true;
|
909
|
+
this->inf_to_str_.clear();
|
910
|
+
this->inf_to_num_ = value;
|
911
|
+
return *this;
|
912
|
+
}
|
913
|
+
|
914
|
+
basic_csv_options& neginf_to_num(const string_type& value)
|
915
|
+
{
|
916
|
+
this->enable_neginf_to_num_ = true;
|
917
|
+
this->neginf_to_str_.clear();
|
918
|
+
this->neginf_to_num_ = value;
|
919
|
+
return *this;
|
920
|
+
}
|
921
|
+
|
922
|
+
basic_csv_options& nan_to_str(const string_type& value, bool enable_inverse = true)
|
923
|
+
{
|
924
|
+
this->enable_nan_to_str_ = true;
|
925
|
+
this->enable_str_to_nan_ = enable_inverse;
|
926
|
+
this->nan_to_num_.clear();
|
927
|
+
this->nan_to_str_ = value;
|
928
|
+
return *this;
|
929
|
+
}
|
930
|
+
|
931
|
+
basic_csv_options& inf_to_str(const string_type& value, bool enable_inverse = true)
|
932
|
+
{
|
933
|
+
this->enable_inf_to_str_ = true;
|
934
|
+
this->enable_inf_to_str_ = enable_inverse;
|
935
|
+
this->inf_to_num_.clear();
|
936
|
+
this->inf_to_str_ = value;
|
937
|
+
return *this;
|
938
|
+
}
|
939
|
+
|
940
|
+
basic_csv_options& neginf_to_str(const string_type& value, bool enable_inverse = true)
|
941
|
+
{
|
942
|
+
this->enable_neginf_to_str_ = true;
|
943
|
+
this->enable_neginf_to_str_ = enable_inverse;
|
944
|
+
this->neginf_to_num_.clear();
|
945
|
+
this->neginf_to_str_ = value;
|
946
|
+
return *this;
|
947
|
+
}
|
948
|
+
|
949
|
+
#if !defined(JSONCONS_NO_DEPRECATED)
|
950
|
+
|
951
|
+
JSONCONS_DEPRECATED_MSG("Instead, use float_format(float_chars_format)")
|
952
|
+
basic_csv_options& floating_point_format(float_chars_format value)
|
953
|
+
{
|
954
|
+
this->float_format_ = value;
|
955
|
+
return *this;
|
956
|
+
}
|
957
|
+
#endif
|
958
|
+
|
959
|
+
};
|
960
|
+
|
961
|
+
using csv_options = basic_csv_options<char>;
|
962
|
+
using wcsv_options = basic_csv_options<wchar_t>;
|
963
|
+
|
964
|
+
#if !defined(JSONCONS_NO_DEPRECATED)
|
965
|
+
JSONCONS_DEPRECATED_MSG("Instead, use csv_options") typedef csv_options csv_parameters;
|
966
|
+
JSONCONS_DEPRECATED_MSG("Instead, use wcsv_options") typedef wcsv_options wcsv_parameters;
|
967
|
+
JSONCONS_DEPRECATED_MSG("Instead, use csv_options") typedef csv_options csv_serializing_options;
|
968
|
+
JSONCONS_DEPRECATED_MSG("Instead, use wcsv_options") typedef wcsv_options wcsv_serializing_options;
|
969
|
+
#endif
|
970
|
+
|
971
|
+
|
972
|
+
}}
|
973
|
+
#endif
|