/src/cppcheck/externals/picojson/picojson.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2009-2010 Cybozu Labs, Inc. |
3 | | * Copyright 2011-2014 Kazuho Oku |
4 | | * All rights reserved. |
5 | | * |
6 | | * Redistribution and use in source and binary forms, with or without |
7 | | * modification, are permitted provided that the following conditions are met: |
8 | | * |
9 | | * 1. Redistributions of source code must retain the above copyright notice, |
10 | | * this list of conditions and the following disclaimer. |
11 | | * |
12 | | * 2. Redistributions in binary form must reproduce the above copyright notice, |
13 | | * this list of conditions and the following disclaimer in the documentation |
14 | | * and/or other materials provided with the distribution. |
15 | | * |
16 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
17 | | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
18 | | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
19 | | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
20 | | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 | | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 | | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 | | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | | * POSSIBILITY OF SUCH DAMAGE. |
27 | | */ |
28 | | #ifndef picojson_h |
29 | | #define picojson_h |
30 | | |
31 | | #include <algorithm> |
32 | | #include <cstdio> |
33 | | #include <cstdlib> |
34 | | #include <cstring> |
35 | | #include <iostream> |
36 | | #include <iterator> |
37 | | #include <limits> |
38 | | #include <map> |
39 | | #include <stdexcept> |
40 | | #include <string> |
41 | | #include <vector> |
42 | | |
43 | | // for isnan/isinf |
44 | | #if __cplusplus>=201103L |
45 | | # include <cmath> |
46 | | #else |
47 | | extern "C" { |
48 | | # ifdef _MSC_VER |
49 | | # include <float.h> |
50 | | # elif defined(__INTEL_COMPILER) |
51 | | # include <mathimf.h> |
52 | | # else |
53 | | # include <math.h> |
54 | | # endif |
55 | | } |
56 | | #endif |
57 | | |
58 | | // experimental support for int64_t (see README.mkdn for detail) |
59 | | #ifdef PICOJSON_USE_INT64 |
60 | | # define __STDC_FORMAT_MACROS |
61 | | # include <errno.h> |
62 | | # include <inttypes.h> |
63 | | #endif |
64 | | |
65 | | // to disable the use of localeconv(3), set PICOJSON_USE_LOCALE to 0 |
66 | | #ifndef PICOJSON_USE_LOCALE |
67 | | # define PICOJSON_USE_LOCALE 1 |
68 | | #endif |
69 | | #if PICOJSON_USE_LOCALE |
70 | | extern "C" { |
71 | | # include <locale.h> |
72 | | } |
73 | | #endif |
74 | | |
75 | | #ifndef PICOJSON_ASSERT |
76 | 0 | # define PICOJSON_ASSERT(e) do { if (! (e)) throw std::runtime_error(#e); } while (0) |
77 | | #endif |
78 | | |
79 | | #ifdef _MSC_VER |
80 | | #define SNPRINTF _snprintf_s |
81 | | #pragma warning(push) |
82 | | #pragma warning(disable : 4244) // conversion from int to char |
83 | | #pragma warning(disable : 4127) // conditional expression is constant |
84 | | #pragma warning(disable : 4702) // unreachable code |
85 | | #else |
86 | 0 | #define SNPRINTF snprintf |
87 | | #endif |
88 | | |
89 | | namespace picojson { |
90 | | |
91 | | enum { |
92 | | null_type, |
93 | | boolean_type, |
94 | | number_type, |
95 | | string_type, |
96 | | array_type, |
97 | | object_type |
98 | | #ifdef PICOJSON_USE_INT64 |
99 | | , int64_type |
100 | | #endif |
101 | | }; |
102 | | |
103 | | enum { |
104 | | INDENT_WIDTH = 2 |
105 | | }; |
106 | | |
107 | | struct null {}; |
108 | | |
109 | | class value { |
110 | | public: |
111 | | typedef std::vector<value> array; |
112 | | typedef std::map<std::string, value> object; |
113 | | union _storage { |
114 | | bool boolean_; |
115 | | double number_; |
116 | | #ifdef PICOJSON_USE_INT64 |
117 | | int64_t int64_; |
118 | | #endif |
119 | | std::string* string_; |
120 | | array* array_; |
121 | | object* object_; |
122 | | }; |
123 | | protected: |
124 | | int type_; |
125 | | _storage u_; |
126 | | public: |
127 | | value(); |
128 | | value(int type, bool); |
129 | | explicit value(bool b); |
130 | | #ifdef PICOJSON_USE_INT64 |
131 | | explicit value(int64_t i); |
132 | | #endif |
133 | | explicit value(double n); |
134 | | explicit value(const std::string& s); |
135 | | explicit value(const array& a); |
136 | | explicit value(const object& o); |
137 | | explicit value(const char* s); |
138 | | value(const char* s, size_t len); |
139 | | ~value(); |
140 | | value(const value& x); |
141 | | value& operator=(const value& x); |
142 | | void swap(value& x); |
143 | | template <typename T> bool is() const; |
144 | | template <typename T> const T& get() const; |
145 | | template <typename T> T& get(); |
146 | | bool evaluate_as_boolean() const; |
147 | | const value& get(size_t idx) const; |
148 | | const value& get(const std::string& key) const; |
149 | | value& get(size_t idx); |
150 | | value& get(const std::string& key); |
151 | | |
152 | | bool contains(size_t idx) const; |
153 | | bool contains(const std::string& key) const; |
154 | | std::string to_str() const; |
155 | | template <typename Iter> void serialize(Iter os, bool prettify = false) const; |
156 | | std::string serialize(bool prettify = false) const; |
157 | | private: |
158 | | template <typename T> value(const T*); // intentionally defined to block implicit conversion of pointer to bool |
159 | | template <typename Iter> static void _indent(Iter os, int indent); |
160 | | template <typename Iter> void _serialize(Iter os, int indent) const; |
161 | | std::string _serialize(int indent) const; |
162 | | }; |
163 | | |
164 | | typedef value::array array; |
165 | | typedef value::object object; |
166 | | |
167 | 0 | inline value::value() : type_(null_type) {} |
168 | | |
169 | 0 | inline value::value(int type, bool) : type_(type) { |
170 | 0 | switch (type) { |
171 | 0 | #define INIT(p, v) case p##type: u_.p = v; break |
172 | 0 | INIT(boolean_, false); |
173 | 0 | INIT(number_, 0.0); |
174 | 0 | #ifdef PICOJSON_USE_INT64 |
175 | 0 | INIT(int64_, 0); |
176 | 0 | #endif |
177 | 0 | INIT(string_, new std::string()); |
178 | 0 | INIT(array_, new array()); |
179 | 0 | INIT(object_, new object()); |
180 | 0 | #undef INIT |
181 | 0 | default: break; |
182 | 0 | } |
183 | 0 | } |
184 | | |
185 | 0 | inline value::value(bool b) : type_(boolean_type) { |
186 | 0 | u_.boolean_ = b; |
187 | 0 | } |
188 | | |
189 | | #ifdef PICOJSON_USE_INT64 |
190 | 0 | inline value::value(int64_t i) : type_(int64_type) { |
191 | 0 | u_.int64_ = i; |
192 | 0 | } |
193 | | #endif |
194 | | |
195 | 0 | inline value::value(double n) : type_(number_type) { |
196 | 0 | if ( |
197 | | #ifdef _MSC_VER |
198 | | ! _finite(n) |
199 | | #elif __cplusplus>=201103L || !(defined(isnan) && defined(isinf)) |
200 | 0 | std::isnan(n) || std::isinf(n) |
201 | | #else |
202 | | isnan(n) || isinf(n) |
203 | | #endif |
204 | 0 | ) { |
205 | 0 | throw std::overflow_error(""); |
206 | 0 | } |
207 | 0 | u_.number_ = n; |
208 | 0 | } |
209 | | |
210 | | inline value::value(const std::string& s) : type_(string_type) { |
211 | | u_.string_ = new std::string(s); |
212 | | } |
213 | | |
214 | | inline value::value(const array& a) : type_(array_type) { |
215 | | u_.array_ = new array(a); |
216 | | } |
217 | | |
218 | | inline value::value(const object& o) : type_(object_type) { |
219 | | u_.object_ = new object(o); |
220 | | } |
221 | | |
222 | | inline value::value(const char* s) : type_(string_type) { |
223 | | u_.string_ = new std::string(s); |
224 | | } |
225 | | |
226 | | inline value::value(const char* s, size_t len) : type_(string_type) { |
227 | | u_.string_ = new std::string(s, len); |
228 | | } |
229 | | |
230 | 0 | inline value::~value() { |
231 | 0 | switch (type_) { |
232 | 0 | #define DEINIT(p) case p##type: delete u_.p; break |
233 | 0 | DEINIT(string_); |
234 | 0 | DEINIT(array_); |
235 | 0 | DEINIT(object_); |
236 | 0 | #undef DEINIT |
237 | 0 | default: break; |
238 | 0 | } |
239 | 0 | } |
240 | | |
241 | 0 | inline value::value(const value& x) : type_(x.type_) { |
242 | 0 | switch (type_) { |
243 | 0 | #define INIT(p, v) case p##type: u_.p = v; break |
244 | 0 | INIT(string_, new std::string(*x.u_.string_)); |
245 | 0 | INIT(array_, new array(*x.u_.array_)); |
246 | 0 | INIT(object_, new object(*x.u_.object_)); |
247 | 0 | #undef INIT |
248 | 0 | default: |
249 | 0 | u_ = x.u_; |
250 | 0 | break; |
251 | 0 | } |
252 | 0 | } |
253 | | |
254 | 0 | inline value& value::operator=(const value& x) { |
255 | 0 | if (this != &x) { |
256 | 0 | value t(x); |
257 | 0 | swap(t); |
258 | 0 | } |
259 | 0 | return *this; |
260 | 0 | } |
261 | | |
262 | 0 | inline void value::swap(value& x) { |
263 | 0 | std::swap(type_, x.type_); |
264 | 0 | std::swap(u_, x.u_); |
265 | 0 | } |
266 | | |
267 | | #define IS(ctype, jtype) \ |
268 | 0 | template <> inline bool value::is<ctype>() const { \ |
269 | 0 | return type_ == jtype##_type; \ |
270 | 0 | } Unexecuted instantiation: bool picojson::value::is<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >() const Unexecuted instantiation: bool picojson::value::is<std::__1::vector<picojson::value, std::__1::allocator<picojson::value> > >() const Unexecuted instantiation: bool picojson::value::is<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, picojson::value, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, picojson::value> > > >() const Unexecuted instantiation: bool picojson::value::is<bool>() const Unexecuted instantiation: bool picojson::value::is<picojson::null>() const Unexecuted instantiation: bool picojson::value::is<long>() const |
271 | | IS(null, null) |
272 | | IS(bool, boolean) |
273 | | #ifdef PICOJSON_USE_INT64 |
274 | | IS(int64_t, int64) |
275 | | #endif |
276 | | IS(std::string, string) |
277 | | IS(array, array) |
278 | | IS(object, object) |
279 | | #undef IS |
280 | 0 | template <> inline bool value::is<double>() const { |
281 | 0 | return type_ == number_type |
282 | 0 | #ifdef PICOJSON_USE_INT64 |
283 | 0 | || type_ == int64_type |
284 | 0 | #endif |
285 | 0 | ; |
286 | 0 | } |
287 | | |
288 | | #define GET(ctype, var) \ |
289 | 0 | template <> inline const ctype& value::get<ctype>() const { \ |
290 | 0 | PICOJSON_ASSERT("type mismatch! call is<type>() before get<type>()" \ |
291 | 0 | && is<ctype>()); \ |
292 | 0 | return var; \ |
293 | 0 | } \ Unexecuted instantiation: std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, picojson::value, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, picojson::value> > > const& picojson::value::get<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, picojson::value, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, picojson::value> > > >() const Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const& picojson::value::get<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >() const Unexecuted instantiation: bool const& picojson::value::get<bool>() const Unexecuted instantiation: std::__1::vector<picojson::value, std::__1::allocator<picojson::value> > const& picojson::value::get<std::__1::vector<picojson::value, std::__1::allocator<picojson::value> > >() const Unexecuted instantiation: double const& picojson::value::get<double>() const Unexecuted instantiation: long const& picojson::value::get<long>() const |
294 | 0 | template <> inline ctype& value::get<ctype>() { \ |
295 | 0 | PICOJSON_ASSERT("type mismatch! call is<type>() before get<type>()" \ |
296 | 0 | && is<ctype>()); \ |
297 | 0 | return var; \ |
298 | 0 | } Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >& picojson::value::get<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >() Unexecuted instantiation: std::__1::vector<picojson::value, std::__1::allocator<picojson::value> >& picojson::value::get<std::__1::vector<picojson::value, std::__1::allocator<picojson::value> > >() Unexecuted instantiation: std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, picojson::value, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, picojson::value> > >& picojson::value::get<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, picojson::value, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, picojson::value> > > >() Unexecuted instantiation: bool& picojson::value::get<bool>() Unexecuted instantiation: double& picojson::value::get<double>() Unexecuted instantiation: long& picojson::value::get<long>() |
299 | | GET(bool, u_.boolean_) |
300 | | GET(std::string, *u_.string_) |
301 | | GET(array, *u_.array_) |
302 | | GET(object, *u_.object_) |
303 | | #ifdef PICOJSON_USE_INT64 |
304 | | GET(double, (type_ == int64_type && (const_cast<value*>(this)->type_ = number_type, const_cast<value*>(this)->u_.number_ = u_.int64_), u_.number_)) |
305 | | GET(int64_t, u_.int64_) |
306 | | #else |
307 | | GET(double, u_.number_) |
308 | | #endif |
309 | | #undef GET |
310 | | |
311 | 0 | inline bool value::evaluate_as_boolean() const { |
312 | 0 | switch (type_) { |
313 | 0 | case null_type: |
314 | 0 | return false; |
315 | 0 | case boolean_type: |
316 | 0 | return u_.boolean_; |
317 | 0 | case number_type: |
318 | 0 | return u_.number_ != 0; |
319 | 0 | case string_type: |
320 | 0 | return ! u_.string_->empty(); |
321 | 0 | default: |
322 | 0 | return true; |
323 | 0 | } |
324 | 0 | } |
325 | | |
326 | 0 | inline const value& value::get(size_t idx) const { |
327 | 0 | static value s_null; |
328 | 0 | PICOJSON_ASSERT(is<array>()); |
329 | 0 | return idx < u_.array_->size() ? (*u_.array_)[idx] : s_null; |
330 | 0 | } |
331 | | |
332 | 0 | inline value& value::get(size_t idx) { |
333 | 0 | static value s_null; |
334 | 0 | PICOJSON_ASSERT(is<array>()); |
335 | 0 | return idx < u_.array_->size() ? (*u_.array_)[idx] : s_null; |
336 | 0 | } |
337 | | |
338 | 0 | inline const value& value::get(const std::string& key) const { |
339 | 0 | static value s_null; |
340 | 0 | PICOJSON_ASSERT(is<object>()); |
341 | 0 | object::const_iterator i = u_.object_->find(key); |
342 | 0 | return i != u_.object_->end() ? i->second : s_null; |
343 | 0 | } |
344 | | |
345 | 0 | inline value& value::get(const std::string& key) { |
346 | 0 | static value s_null; |
347 | 0 | PICOJSON_ASSERT(is<object>()); |
348 | 0 | object::iterator i = u_.object_->find(key); |
349 | 0 | return i != u_.object_->end() ? i->second : s_null; |
350 | 0 | } |
351 | | |
352 | 0 | inline bool value::contains(size_t idx) const { |
353 | 0 | PICOJSON_ASSERT(is<array>()); |
354 | 0 | return idx < u_.array_->size(); |
355 | 0 | } |
356 | | |
357 | 0 | inline bool value::contains(const std::string& key) const { |
358 | 0 | PICOJSON_ASSERT(is<object>()); |
359 | 0 | object::const_iterator i = u_.object_->find(key); |
360 | 0 | return i != u_.object_->end(); |
361 | 0 | } |
362 | | |
363 | 0 | inline std::string value::to_str() const { |
364 | 0 | switch (type_) { |
365 | 0 | case null_type: return "null"; |
366 | 0 | case boolean_type: return u_.boolean_ ? "true" : "false"; |
367 | 0 | #ifdef PICOJSON_USE_INT64 |
368 | 0 | case int64_type: { |
369 | 0 | char buf[sizeof("-9223372036854775808")]; |
370 | 0 | SNPRINTF(buf, sizeof(buf), "%" PRId64, u_.int64_); |
371 | 0 | return buf; |
372 | 0 | } |
373 | 0 | #endif |
374 | 0 | case number_type: { |
375 | 0 | char buf[256]; |
376 | 0 | double tmp; |
377 | 0 | SNPRINTF(buf, sizeof(buf), fabs(u_.number_) < (1ULL << 53) && modf(u_.number_, &tmp) == 0 ? "%.f" : "%.17g", u_.number_); |
378 | 0 | #if PICOJSON_USE_LOCALE |
379 | 0 | char *decimal_point = localeconv()->decimal_point; |
380 | 0 | if (strcmp(decimal_point, ".") != 0) { |
381 | 0 | size_t decimal_point_len = strlen(decimal_point); |
382 | 0 | for (char *p = buf; *p != '\0'; ++p) { |
383 | 0 | if (strncmp(p, decimal_point, decimal_point_len) == 0) { |
384 | 0 | return std::string(buf, p) + "." + (p + decimal_point_len); |
385 | 0 | } |
386 | 0 | } |
387 | 0 | } |
388 | 0 | #endif |
389 | 0 | return buf; |
390 | 0 | } |
391 | 0 | case string_type: return *u_.string_; |
392 | 0 | case array_type: return "array"; |
393 | 0 | case object_type: return "object"; |
394 | 0 | default: PICOJSON_ASSERT(0); |
395 | 0 | #ifdef _MSC_VER |
396 | 0 | __assume(0); |
397 | 0 | #endif |
398 | 0 | } |
399 | 0 | return std::string(); |
400 | 0 | } |
401 | | |
402 | 0 | template <typename Iter> void copy(const std::string& s, Iter oi) { |
403 | 0 | std::copy(s.begin(), s.end(), oi); |
404 | 0 | } Unexecuted instantiation: void picojson::copy<std::__1::back_insert_iterator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::back_insert_iterator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >) Unexecuted instantiation: void picojson::copy<std::__1::ostream_iterator<char, char, std::__1::char_traits<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::ostream_iterator<char, char, std::__1::char_traits<char> >) |
405 | | |
406 | 0 | template <typename Iter> void serialize_str(const std::string& s, Iter oi) { |
407 | 0 | *oi++ = '"'; |
408 | 0 | for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) { |
409 | 0 | switch (*i) { |
410 | 0 | #define MAP(val, sym) case val: copy(sym, oi); break |
411 | 0 | MAP('"', "\\\""); |
412 | 0 | MAP('\\', "\\\\"); |
413 | 0 | MAP('/', "\\/"); |
414 | 0 | MAP('\b', "\\b"); |
415 | 0 | MAP('\f', "\\f"); |
416 | 0 | MAP('\n', "\\n"); |
417 | 0 | MAP('\r', "\\r"); |
418 | 0 | MAP('\t', "\\t"); |
419 | 0 | #undef MAP |
420 | 0 | default: |
421 | 0 | if (static_cast<unsigned char>(*i) < 0x20 || *i == 0x7f) { |
422 | 0 | char buf[7]; |
423 | 0 | SNPRINTF(buf, sizeof(buf), "\\u%04x", *i & 0xff); |
424 | 0 | copy(buf, buf + 6, oi); |
425 | 0 | } else { |
426 | 0 | *oi++ = *i; |
427 | 0 | } |
428 | 0 | break; |
429 | 0 | } |
430 | 0 | } |
431 | 0 | *oi++ = '"'; |
432 | 0 | } Unexecuted instantiation: void picojson::serialize_str<std::__1::back_insert_iterator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::back_insert_iterator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >) Unexecuted instantiation: void picojson::serialize_str<std::__1::ostream_iterator<char, char, std::__1::char_traits<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::ostream_iterator<char, char, std::__1::char_traits<char> >) |
433 | | |
434 | 0 | template <typename Iter> void value::serialize(Iter oi, bool prettify) const { |
435 | 0 | return _serialize(oi, prettify ? 0 : -1); |
436 | 0 | } |
437 | | |
438 | 0 | inline std::string value::serialize(bool prettify) const { |
439 | 0 | return _serialize(prettify ? 0 : -1); |
440 | 0 | } |
441 | | |
442 | 0 | template <typename Iter> void value::_indent(Iter oi, int indent) { |
443 | 0 | *oi++ = '\n'; |
444 | 0 | for (int i = 0; i < indent * INDENT_WIDTH; ++i) { |
445 | 0 | *oi++ = ' '; |
446 | 0 | } |
447 | 0 | } Unexecuted instantiation: void picojson::value::_indent<std::__1::back_insert_iterator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(std::__1::back_insert_iterator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, int) Unexecuted instantiation: void picojson::value::_indent<std::__1::ostream_iterator<char, char, std::__1::char_traits<char> > >(std::__1::ostream_iterator<char, char, std::__1::char_traits<char> >, int) |
448 | | |
449 | 0 | template <typename Iter> void value::_serialize(Iter oi, int indent) const { |
450 | 0 | switch (type_) { |
451 | 0 | case string_type: |
452 | 0 | serialize_str(*u_.string_, oi); |
453 | 0 | break; |
454 | 0 | case array_type: { |
455 | 0 | *oi++ = '['; |
456 | 0 | if (indent != -1) { |
457 | 0 | ++indent; |
458 | 0 | } |
459 | 0 | for (array::const_iterator i = u_.array_->begin(); |
460 | 0 | i != u_.array_->end(); |
461 | 0 | ++i) { |
462 | 0 | if (i != u_.array_->begin()) { |
463 | 0 | *oi++ = ','; |
464 | 0 | } |
465 | 0 | if (indent != -1) { |
466 | 0 | _indent(oi, indent); |
467 | 0 | } |
468 | 0 | i->_serialize(oi, indent); |
469 | 0 | } |
470 | 0 | if (indent != -1) { |
471 | 0 | --indent; |
472 | 0 | if (! u_.array_->empty()) { |
473 | 0 | _indent(oi, indent); |
474 | 0 | } |
475 | 0 | } |
476 | 0 | *oi++ = ']'; |
477 | 0 | break; |
478 | 0 | } |
479 | 0 | case object_type: { |
480 | 0 | *oi++ = '{'; |
481 | 0 | if (indent != -1) { |
482 | 0 | ++indent; |
483 | 0 | } |
484 | 0 | for (object::const_iterator i = u_.object_->begin(); |
485 | 0 | i != u_.object_->end(); |
486 | 0 | ++i) { |
487 | 0 | if (i != u_.object_->begin()) { |
488 | 0 | *oi++ = ','; |
489 | 0 | } |
490 | 0 | if (indent != -1) { |
491 | 0 | _indent(oi, indent); |
492 | 0 | } |
493 | 0 | serialize_str(i->first, oi); |
494 | 0 | *oi++ = ':'; |
495 | 0 | if (indent != -1) { |
496 | 0 | *oi++ = ' '; |
497 | 0 | } |
498 | 0 | i->second._serialize(oi, indent); |
499 | 0 | } |
500 | 0 | if (indent != -1) { |
501 | 0 | --indent; |
502 | 0 | if (! u_.object_->empty()) { |
503 | 0 | _indent(oi, indent); |
504 | 0 | } |
505 | 0 | } |
506 | 0 | *oi++ = '}'; |
507 | 0 | break; |
508 | 0 | } |
509 | 0 | default: |
510 | 0 | copy(to_str(), oi); |
511 | 0 | break; |
512 | 0 | } |
513 | 0 | if (indent == 0) { |
514 | 0 | *oi++ = '\n'; |
515 | 0 | } |
516 | 0 | } Unexecuted instantiation: void picojson::value::_serialize<std::__1::back_insert_iterator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(std::__1::back_insert_iterator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, int) const Unexecuted instantiation: void picojson::value::_serialize<std::__1::ostream_iterator<char, char, std::__1::char_traits<char> > >(std::__1::ostream_iterator<char, char, std::__1::char_traits<char> >, int) const |
517 | | |
518 | 0 | inline std::string value::_serialize(int indent) const { |
519 | 0 | std::string s; |
520 | 0 | _serialize(std::back_inserter(s), indent); |
521 | 0 | return s; |
522 | 0 | } |
523 | | |
524 | | template <typename Iter> class input { |
525 | | protected: |
526 | | Iter cur_, end_; |
527 | | int last_ch_; |
528 | | bool ungot_; |
529 | | int line_; |
530 | | public: |
531 | 0 | input(const Iter& first, const Iter& last) : cur_(first), end_(last), last_ch_(-1), ungot_(false), line_(1) {} Unexecuted instantiation: picojson::input<std::__1::__wrap_iter<char const*> >::input(std::__1::__wrap_iter<char const*> const&, std::__1::__wrap_iter<char const*> const&) Unexecuted instantiation: picojson::input<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >::input(std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > const&, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > const&) |
532 | 0 | int getc() { |
533 | 0 | if (ungot_) { |
534 | 0 | ungot_ = false; |
535 | 0 | return last_ch_; |
536 | 0 | } |
537 | 0 | if (cur_ == end_) { |
538 | 0 | last_ch_ = -1; |
539 | 0 | return -1; |
540 | 0 | } |
541 | 0 | if (last_ch_ == '\n') { |
542 | 0 | line_++; |
543 | 0 | } |
544 | 0 | last_ch_ = *cur_ & 0xff; |
545 | 0 | ++cur_; |
546 | 0 | return last_ch_; |
547 | 0 | } Unexecuted instantiation: picojson::input<std::__1::__wrap_iter<char const*> >::getc() Unexecuted instantiation: picojson::input<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >::getc() |
548 | 0 | void ungetc() { |
549 | 0 | if (last_ch_ != -1) { |
550 | 0 | PICOJSON_ASSERT(! ungot_); |
551 | 0 | ungot_ = true; |
552 | 0 | } |
553 | 0 | } Unexecuted instantiation: picojson::input<std::__1::__wrap_iter<char const*> >::ungetc() Unexecuted instantiation: picojson::input<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >::ungetc() |
554 | 0 | Iter cur() const { return cur_; } Unexecuted instantiation: picojson::input<std::__1::__wrap_iter<char const*> >::cur() const Unexecuted instantiation: picojson::input<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >::cur() const |
555 | 0 | int line() const { return line_; } Unexecuted instantiation: picojson::input<std::__1::__wrap_iter<char const*> >::line() const Unexecuted instantiation: picojson::input<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >::line() const |
556 | 0 | void skip_ws() { |
557 | 0 | while (1) { |
558 | 0 | int ch = getc(); |
559 | 0 | if (! (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r')) { |
560 | 0 | ungetc(); |
561 | 0 | break; |
562 | 0 | } |
563 | 0 | } |
564 | 0 | } Unexecuted instantiation: picojson::input<std::__1::__wrap_iter<char const*> >::skip_ws() Unexecuted instantiation: picojson::input<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >::skip_ws() |
565 | 0 | bool expect(int expect) { |
566 | 0 | skip_ws(); |
567 | 0 | if (getc() != expect) { |
568 | 0 | ungetc(); |
569 | 0 | return false; |
570 | 0 | } |
571 | 0 | return true; |
572 | 0 | } Unexecuted instantiation: picojson::input<std::__1::__wrap_iter<char const*> >::expect(int) Unexecuted instantiation: picojson::input<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >::expect(int) |
573 | 0 | bool match(const std::string& pattern) { |
574 | 0 | for (std::string::const_iterator pi(pattern.begin()); |
575 | 0 | pi != pattern.end(); |
576 | 0 | ++pi) { |
577 | 0 | if (getc() != *pi) { |
578 | 0 | ungetc(); |
579 | 0 | return false; |
580 | 0 | } |
581 | 0 | } |
582 | 0 | return true; |
583 | 0 | } Unexecuted instantiation: picojson::input<std::__1::__wrap_iter<char const*> >::match(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Unexecuted instantiation: picojson::input<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >::match(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) |
584 | | }; |
585 | | |
586 | 0 | template<typename Iter> inline int _parse_quadhex(input<Iter> &in) { |
587 | 0 | int uni_ch = 0, hex; |
588 | 0 | for (int i = 0; i < 4; i++) { |
589 | 0 | if ((hex = in.getc()) == -1) { |
590 | 0 | return -1; |
591 | 0 | } |
592 | 0 | if ('0' <= hex && hex <= '9') { |
593 | 0 | hex -= '0'; |
594 | 0 | } else if ('A' <= hex && hex <= 'F') { |
595 | 0 | hex -= 'A' - 0xa; |
596 | 0 | } else if ('a' <= hex && hex <= 'f') { |
597 | 0 | hex -= 'a' - 0xa; |
598 | 0 | } else { |
599 | 0 | in.ungetc(); |
600 | 0 | return -1; |
601 | 0 | } |
602 | 0 | uni_ch = uni_ch * 16 + hex; |
603 | 0 | } |
604 | 0 | return uni_ch; |
605 | 0 | } Unexecuted instantiation: int picojson::_parse_quadhex<std::__1::__wrap_iter<char const*> >(picojson::input<std::__1::__wrap_iter<char const*> >&) Unexecuted instantiation: int picojson::_parse_quadhex<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >(picojson::input<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >&) |
606 | | |
607 | 0 | template<typename String, typename Iter> inline bool _parse_codepoint(String& out, input<Iter>& in) { |
608 | 0 | int uni_ch; |
609 | 0 | if ((uni_ch = _parse_quadhex(in)) == -1) { |
610 | 0 | return false; |
611 | 0 | } |
612 | 0 | if (0xd800 <= uni_ch && uni_ch <= 0xdfff) { |
613 | 0 | if (0xdc00 <= uni_ch) { |
614 | | // a second 16-bit of a surrogate pair appeared |
615 | 0 | return false; |
616 | 0 | } |
617 | | // first 16-bit of surrogate pair, get the next one |
618 | 0 | if (in.getc() != '\\' || in.getc() != 'u') { |
619 | 0 | in.ungetc(); |
620 | 0 | return false; |
621 | 0 | } |
622 | 0 | int second = _parse_quadhex(in); |
623 | 0 | if (! (0xdc00 <= second && second <= 0xdfff)) { |
624 | 0 | return false; |
625 | 0 | } |
626 | 0 | uni_ch = ((uni_ch - 0xd800) << 10) | ((second - 0xdc00) & 0x3ff); |
627 | 0 | uni_ch += 0x10000; |
628 | 0 | } |
629 | 0 | if (uni_ch < 0x80) { |
630 | 0 | out.push_back(uni_ch); |
631 | 0 | } else { |
632 | 0 | if (uni_ch < 0x800) { |
633 | 0 | out.push_back(0xc0 | (uni_ch >> 6)); |
634 | 0 | } else { |
635 | 0 | if (uni_ch < 0x10000) { |
636 | 0 | out.push_back(0xe0 | (uni_ch >> 12)); |
637 | 0 | } else { |
638 | 0 | out.push_back(0xf0 | (uni_ch >> 18)); |
639 | 0 | out.push_back(0x80 | ((uni_ch >> 12) & 0x3f)); |
640 | 0 | } |
641 | 0 | out.push_back(0x80 | ((uni_ch >> 6) & 0x3f)); |
642 | 0 | } |
643 | 0 | out.push_back(0x80 | (uni_ch & 0x3f)); |
644 | 0 | } |
645 | 0 | return true; |
646 | 0 | } Unexecuted instantiation: bool picojson::_parse_codepoint<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__wrap_iter<char const*> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, picojson::input<std::__1::__wrap_iter<char const*> >&) Unexecuted instantiation: bool picojson::_parse_codepoint<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, picojson::input<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >&) |
647 | | |
648 | 0 | template<typename String, typename Iter> inline bool _parse_string(String& out, input<Iter>& in) { |
649 | 0 | while (1) { |
650 | 0 | int ch = in.getc(); |
651 | 0 | if (ch < ' ') { |
652 | 0 | in.ungetc(); |
653 | 0 | return false; |
654 | 0 | } else if (ch == '"') { |
655 | 0 | return true; |
656 | 0 | } else if (ch == '\\') { |
657 | 0 | if ((ch = in.getc()) == -1) { |
658 | 0 | return false; |
659 | 0 | } |
660 | 0 | switch (ch) { |
661 | 0 | #define MAP(sym, val) case sym: out.push_back(val); break |
662 | 0 | MAP('"', '\"'); |
663 | 0 | MAP('\\', '\\'); |
664 | 0 | MAP('/', '/'); |
665 | 0 | MAP('b', '\b'); |
666 | 0 | MAP('f', '\f'); |
667 | 0 | MAP('n', '\n'); |
668 | 0 | MAP('r', '\r'); |
669 | 0 | MAP('t', '\t'); |
670 | 0 | #undef MAP |
671 | 0 | case 'u': |
672 | 0 | if (! _parse_codepoint(out, in)) { |
673 | 0 | return false; |
674 | 0 | } |
675 | 0 | break; |
676 | 0 | default: |
677 | 0 | return false; |
678 | 0 | } |
679 | 0 | } else { |
680 | 0 | out.push_back(ch); |
681 | 0 | } |
682 | 0 | } |
683 | 0 | return false; |
684 | 0 | } Unexecuted instantiation: bool picojson::_parse_string<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__wrap_iter<char const*> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, picojson::input<std::__1::__wrap_iter<char const*> >&) Unexecuted instantiation: bool picojson::_parse_string<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, picojson::input<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >&) |
685 | | |
686 | 0 | template <typename Context, typename Iter> inline bool _parse_array(Context& ctx, input<Iter>& in) { |
687 | 0 | if (! ctx.parse_array_start()) { |
688 | 0 | return false; |
689 | 0 | } |
690 | 0 | size_t idx = 0; |
691 | 0 | if (in.expect(']')) { |
692 | 0 | return ctx.parse_array_stop(idx); |
693 | 0 | } |
694 | 0 | do { |
695 | 0 | if (! ctx.parse_array_item(in, idx)) { |
696 | 0 | return false; |
697 | 0 | } |
698 | 0 | idx++; |
699 | 0 | } while (in.expect(',')); |
700 | 0 | return in.expect(']') && ctx.parse_array_stop(idx); |
701 | 0 | } Unexecuted instantiation: bool picojson::_parse_array<picojson::default_parse_context, std::__1::__wrap_iter<char const*> >(picojson::default_parse_context&, picojson::input<std::__1::__wrap_iter<char const*> >&) Unexecuted instantiation: bool picojson::_parse_array<picojson::default_parse_context, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >(picojson::default_parse_context&, picojson::input<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >&) |
702 | | |
703 | 0 | template <typename Context, typename Iter> inline bool _parse_object(Context& ctx, input<Iter>& in) { |
704 | 0 | if (! ctx.parse_object_start()) { |
705 | 0 | return false; |
706 | 0 | } |
707 | 0 | if (in.expect('}')) { |
708 | 0 | return true; |
709 | 0 | } |
710 | 0 | do { |
711 | 0 | std::string key; |
712 | 0 | if (! in.expect('"') |
713 | 0 | || ! _parse_string(key, in) |
714 | 0 | || ! in.expect(':')) { |
715 | 0 | return false; |
716 | 0 | } |
717 | 0 | if (! ctx.parse_object_item(in, key)) { |
718 | 0 | return false; |
719 | 0 | } |
720 | 0 | } while (in.expect(',')); |
721 | 0 | return in.expect('}'); |
722 | 0 | } Unexecuted instantiation: bool picojson::_parse_object<picojson::default_parse_context, std::__1::__wrap_iter<char const*> >(picojson::default_parse_context&, picojson::input<std::__1::__wrap_iter<char const*> >&) Unexecuted instantiation: bool picojson::_parse_object<picojson::default_parse_context, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >(picojson::default_parse_context&, picojson::input<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >&) |
723 | | |
724 | 0 | template <typename Iter> inline std::string _parse_number(input<Iter>& in) { |
725 | 0 | std::string num_str; |
726 | 0 | while (1) { |
727 | 0 | int ch = in.getc(); |
728 | 0 | if (('0' <= ch && ch <= '9') || ch == '+' || ch == '-' |
729 | 0 | || ch == 'e' || ch == 'E') { |
730 | 0 | num_str.push_back(ch); |
731 | 0 | } else if (ch == '.') { |
732 | 0 | #if PICOJSON_USE_LOCALE |
733 | 0 | num_str += localeconv()->decimal_point; |
734 | | #else |
735 | | num_str.push_back('.'); |
736 | | #endif |
737 | 0 | } else { |
738 | 0 | in.ungetc(); |
739 | 0 | break; |
740 | 0 | } |
741 | 0 | } |
742 | 0 | return num_str; |
743 | 0 | } Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > picojson::_parse_number<std::__1::__wrap_iter<char const*> >(picojson::input<std::__1::__wrap_iter<char const*> >&) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > picojson::_parse_number<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >(picojson::input<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >&) |
744 | | |
745 | 0 | template <typename Context, typename Iter> inline bool _parse(Context& ctx, input<Iter>& in) { |
746 | 0 | in.skip_ws(); |
747 | 0 | int ch = in.getc(); |
748 | 0 | switch (ch) { |
749 | 0 | #define IS(ch, text, op) case ch: \ |
750 | 0 | if (in.match(text) && op) { \ |
751 | 0 | return true; \ |
752 | 0 | } else { \ |
753 | 0 | return false; \ |
754 | 0 | } |
755 | 0 | IS('n', "ull", ctx.set_null()); |
756 | 0 | IS('f', "alse", ctx.set_bool(false)); |
757 | 0 | IS('t', "rue", ctx.set_bool(true)); |
758 | 0 | #undef IS |
759 | 0 | case '"': |
760 | 0 | return ctx.parse_string(in); |
761 | 0 | case '[': |
762 | 0 | return _parse_array(ctx, in); |
763 | 0 | case '{': |
764 | 0 | return _parse_object(ctx, in); |
765 | 0 | default: |
766 | 0 | if (('0' <= ch && ch <= '9') || ch == '-') { |
767 | 0 | double f; |
768 | 0 | char *endp; |
769 | 0 | in.ungetc(); |
770 | 0 | std::string num_str = _parse_number(in); |
771 | 0 | if (num_str.empty()) { |
772 | 0 | return false; |
773 | 0 | } |
774 | 0 | #ifdef PICOJSON_USE_INT64 |
775 | 0 | { |
776 | 0 | errno = 0; |
777 | 0 | intmax_t ival = strtoimax(num_str.c_str(), &endp, 10); |
778 | 0 | if (errno == 0 |
779 | 0 | && std::numeric_limits<int64_t>::min() <= ival |
780 | 0 | && ival <= std::numeric_limits<int64_t>::max() |
781 | 0 | && endp == num_str.c_str() + num_str.size()) { |
782 | 0 | ctx.set_int64(ival); |
783 | 0 | return true; |
784 | 0 | } |
785 | 0 | } |
786 | 0 | #endif |
787 | 0 | f = strtod(num_str.c_str(), &endp); |
788 | 0 | if (endp == num_str.c_str() + num_str.size()) { |
789 | 0 | ctx.set_number(f); |
790 | 0 | return true; |
791 | 0 | } |
792 | 0 | return false; |
793 | 0 | } |
794 | 0 | break; |
795 | 0 | } |
796 | 0 | in.ungetc(); |
797 | 0 | return false; |
798 | 0 | } Unexecuted instantiation: bool picojson::_parse<picojson::default_parse_context, std::__1::__wrap_iter<char const*> >(picojson::default_parse_context&, picojson::input<std::__1::__wrap_iter<char const*> >&) Unexecuted instantiation: bool picojson::_parse<picojson::default_parse_context, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >(picojson::default_parse_context&, picojson::input<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >&) |
799 | | |
800 | | class deny_parse_context { |
801 | | public: |
802 | 0 | bool set_null() { return false; } |
803 | 0 | bool set_bool(bool) { return false; } |
804 | | #ifdef PICOJSON_USE_INT64 |
805 | 0 | bool set_int64(int64_t) { return false; } |
806 | | #endif |
807 | 0 | bool set_number(double) { return false; } |
808 | | template <typename Iter> bool parse_string(input<Iter>&) { return false; } |
809 | 0 | bool parse_array_start() { return false; } |
810 | | template <typename Iter> bool parse_array_item(input<Iter>&, size_t) { |
811 | | return false; |
812 | | } |
813 | 0 | bool parse_array_stop(size_t) { return false; } |
814 | 0 | bool parse_object_start() { return false; } |
815 | | template <typename Iter> bool parse_object_item(input<Iter>&, const std::string&) { |
816 | | return false; |
817 | | } |
818 | | }; |
819 | | |
820 | | class default_parse_context { |
821 | | protected: |
822 | | value* out_; |
823 | | public: |
824 | 0 | default_parse_context(value* out) : out_(out) {} |
825 | 0 | bool set_null() { |
826 | 0 | *out_ = value(); |
827 | 0 | return true; |
828 | 0 | } |
829 | 0 | bool set_bool(bool b) { |
830 | 0 | *out_ = value(b); |
831 | 0 | return true; |
832 | 0 | } |
833 | | #ifdef PICOJSON_USE_INT64 |
834 | 0 | bool set_int64(int64_t i) { |
835 | 0 | *out_ = value(i); |
836 | 0 | return true; |
837 | 0 | } |
838 | | #endif |
839 | 0 | bool set_number(double f) { |
840 | 0 | *out_ = value(f); |
841 | 0 | return true; |
842 | 0 | } |
843 | 0 | template<typename Iter> bool parse_string(input<Iter>& in) { |
844 | 0 | *out_ = value(string_type, false); |
845 | 0 | return _parse_string(out_->get<std::string>(), in); |
846 | 0 | } Unexecuted instantiation: bool picojson::default_parse_context::parse_string<std::__1::__wrap_iter<char const*> >(picojson::input<std::__1::__wrap_iter<char const*> >&) Unexecuted instantiation: bool picojson::default_parse_context::parse_string<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >(picojson::input<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >&) |
847 | 0 | bool parse_array_start() { |
848 | 0 | *out_ = value(array_type, false); |
849 | 0 | return true; |
850 | 0 | } |
851 | 0 | template <typename Iter> bool parse_array_item(input<Iter>& in, size_t) { |
852 | 0 | array& a = out_->get<array>(); |
853 | 0 | a.push_back(value()); |
854 | 0 | default_parse_context ctx(&a.back()); |
855 | 0 | return _parse(ctx, in); |
856 | 0 | } Unexecuted instantiation: bool picojson::default_parse_context::parse_array_item<std::__1::__wrap_iter<char const*> >(picojson::input<std::__1::__wrap_iter<char const*> >&, unsigned long) Unexecuted instantiation: bool picojson::default_parse_context::parse_array_item<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >(picojson::input<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >&, unsigned long) |
857 | 0 | bool parse_array_stop(size_t) { return true; } |
858 | 0 | bool parse_object_start() { |
859 | 0 | *out_ = value(object_type, false); |
860 | 0 | return true; |
861 | 0 | } |
862 | 0 | template <typename Iter> bool parse_object_item(input<Iter>& in, const std::string& key) { |
863 | 0 | object& o = out_->get<object>(); |
864 | 0 | default_parse_context ctx(&o[key]); |
865 | 0 | return _parse(ctx, in); |
866 | 0 | } Unexecuted instantiation: bool picojson::default_parse_context::parse_object_item<std::__1::__wrap_iter<char const*> >(picojson::input<std::__1::__wrap_iter<char const*> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Unexecuted instantiation: bool picojson::default_parse_context::parse_object_item<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >(picojson::input<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) |
867 | | private: |
868 | | default_parse_context(const default_parse_context&); |
869 | | default_parse_context& operator=(const default_parse_context&); |
870 | | }; |
871 | | |
872 | | class null_parse_context { |
873 | | public: |
874 | | struct dummy_str { |
875 | 0 | void push_back(int) {} |
876 | | }; |
877 | | public: |
878 | 0 | null_parse_context() {} |
879 | 0 | bool set_null() { return true; } |
880 | 0 | bool set_bool(bool) { return true; } |
881 | | #ifdef PICOJSON_USE_INT64 |
882 | 0 | bool set_int64(int64_t) { return true; } |
883 | | #endif |
884 | 0 | bool set_number(double) { return true; } |
885 | | template <typename Iter> bool parse_string(input<Iter>& in) { |
886 | | dummy_str s; |
887 | | return _parse_string(s, in); |
888 | | } |
889 | 0 | bool parse_array_start() { return true; } |
890 | | template <typename Iter> bool parse_array_item(input<Iter>& in, size_t) { |
891 | | return _parse(*this, in); |
892 | | } |
893 | 0 | bool parse_array_stop(size_t) { return true; } |
894 | 0 | bool parse_object_start() { return true; } |
895 | | template <typename Iter> bool parse_object_item(input<Iter>& in, const std::string&) { |
896 | | return _parse(*this, in); |
897 | | } |
898 | | private: |
899 | | null_parse_context(const null_parse_context&); |
900 | | null_parse_context& operator=(const null_parse_context&); |
901 | | }; |
902 | | |
903 | | // obsolete, use the version below |
904 | | template <typename Iter> inline std::string parse(value& out, Iter& pos, const Iter& last) { |
905 | | std::string err; |
906 | | pos = parse(out, pos, last, &err); |
907 | | return err; |
908 | | } |
909 | | |
910 | 0 | template <typename Context, typename Iter> inline Iter _parse(Context& ctx, const Iter& first, const Iter& last, std::string* err) { |
911 | 0 | input<Iter> in(first, last); |
912 | 0 | if (! _parse(ctx, in) && err != NULL) { |
913 | 0 | char buf[64]; |
914 | 0 | SNPRINTF(buf, sizeof(buf), "syntax error at line %d near: ", in.line()); |
915 | 0 | *err = buf; |
916 | 0 | while (1) { |
917 | 0 | int ch = in.getc(); |
918 | 0 | if (ch == -1 || ch == '\n') { |
919 | 0 | break; |
920 | 0 | } else if (ch >= ' ') { |
921 | 0 | err->push_back(ch); |
922 | 0 | } |
923 | 0 | } |
924 | 0 | } |
925 | 0 | return in.cur(); |
926 | 0 | } Unexecuted instantiation: std::__1::__wrap_iter<char const*> picojson::_parse<picojson::default_parse_context, std::__1::__wrap_iter<char const*> >(picojson::default_parse_context&, std::__1::__wrap_iter<char const*> const&, std::__1::__wrap_iter<char const*> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > picojson::_parse<picojson::default_parse_context, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >(picojson::default_parse_context&, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > const&, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) |
927 | | |
928 | 0 | template <typename Iter> inline Iter parse(value& out, const Iter& first, const Iter& last, std::string* err) { |
929 | 0 | default_parse_context ctx(&out); |
930 | 0 | return _parse(ctx, first, last, err); |
931 | 0 | } Unexecuted instantiation: std::__1::__wrap_iter<char const*> picojson::parse<std::__1::__wrap_iter<char const*> >(picojson::value&, std::__1::__wrap_iter<char const*> const&, std::__1::__wrap_iter<char const*> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > picojson::parse<std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >(picojson::value&, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > const&, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) |
932 | | |
933 | 0 | inline std::string parse(value& out, const std::string& s) { |
934 | 0 | std::string err; |
935 | 0 | parse(out, s.begin(), s.end(), &err); |
936 | 0 | return err; |
937 | 0 | } |
938 | | |
939 | 0 | inline std::string parse(value& out, std::istream& is) { |
940 | 0 | std::string err; |
941 | 0 | parse(out, std::istreambuf_iterator<char>(is.rdbuf()), |
942 | 0 | std::istreambuf_iterator<char>(), &err); |
943 | 0 | return err; |
944 | 0 | } |
945 | | |
946 | | template <typename T> struct last_error_t { |
947 | | static std::string s; |
948 | | }; |
949 | | template <typename T> std::string last_error_t<T>::s; |
950 | | |
951 | 0 | inline void set_last_error(const std::string& s) { |
952 | 0 | last_error_t<bool>::s = s; |
953 | 0 | } |
954 | | |
955 | 0 | inline const std::string& get_last_error() { |
956 | 0 | return last_error_t<bool>::s; |
957 | 0 | } |
958 | | |
959 | 0 | inline bool operator==(const value& x, const value& y) { |
960 | 0 | if (x.is<null>()) |
961 | 0 | return y.is<null>(); |
962 | 0 | #define PICOJSON_CMP(type) \ |
963 | 0 | if (x.is<type>()) \ |
964 | 0 | return y.is<type>() && x.get<type>() == y.get<type>() |
965 | 0 | PICOJSON_CMP(bool); |
966 | 0 | PICOJSON_CMP(double); |
967 | 0 | PICOJSON_CMP(std::string); |
968 | 0 | PICOJSON_CMP(array); |
969 | 0 | PICOJSON_CMP(object); |
970 | 0 | #undef PICOJSON_CMP |
971 | 0 | PICOJSON_ASSERT(0); |
972 | 0 | #ifdef _MSC_VER |
973 | 0 | __assume(0); |
974 | 0 | #endif |
975 | 0 | return false; |
976 | 0 | } |
977 | | |
978 | 0 | inline bool operator!=(const value& x, const value& y) { |
979 | 0 | return ! (x == y); |
980 | 0 | } |
981 | | } |
982 | | |
983 | | namespace std { |
984 | | template<> inline void swap(picojson::value& x, picojson::value& y) |
985 | 0 | { |
986 | 0 | x.swap(y); |
987 | 0 | } |
988 | | } |
989 | | |
990 | | inline std::istream& operator>>(std::istream& is, picojson::value& x) |
991 | 0 | { |
992 | 0 | picojson::set_last_error(std::string()); |
993 | 0 | std::string err = picojson::parse(x, is); |
994 | 0 | if (! err.empty()) { |
995 | 0 | picojson::set_last_error(err); |
996 | 0 | is.setstate(std::ios::failbit); |
997 | 0 | } |
998 | 0 | return is; |
999 | 0 | } |
1000 | | |
1001 | | inline std::ostream& operator<<(std::ostream& os, const picojson::value& x) |
1002 | 0 | { |
1003 | 0 | x.serialize(std::ostream_iterator<char>(os)); |
1004 | 0 | return os; |
1005 | 0 | } |
1006 | | #ifdef _MSC_VER |
1007 | | #pragma warning(pop) |
1008 | | #endif |
1009 | | |
1010 | | #endif |