gui/mainwindow.cpp: use picojson to generate JSON / updated picojson to latest dev version (#5710)
The lastest release of picojson does not support creation of JSONs, so we need to switch to the current dev version.
This commit is contained in:
parent
70745b527a
commit
347b188726
|
@ -32,6 +32,7 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <cstddef>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
@ -39,6 +40,7 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
// for isnan/isinf
|
// for isnan/isinf
|
||||||
#if __cplusplus >= 201103L
|
#if __cplusplus >= 201103L
|
||||||
|
@ -55,11 +57,33 @@ extern "C" {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef PICOJSON_USE_RVALUE_REFERENCE
|
||||||
|
#if (defined(__cpp_rvalue_references) && __cpp_rvalue_references >= 200610) || (defined(_MSC_VER) && _MSC_VER >= 1600)
|
||||||
|
#define PICOJSON_USE_RVALUE_REFERENCE 1
|
||||||
|
#else
|
||||||
|
#define PICOJSON_USE_RVALUE_REFERENCE 0
|
||||||
|
#endif
|
||||||
|
#endif // PICOJSON_USE_RVALUE_REFERENCE
|
||||||
|
|
||||||
|
#ifndef PICOJSON_NOEXCEPT
|
||||||
|
#if PICOJSON_USE_RVALUE_REFERENCE
|
||||||
|
#define PICOJSON_NOEXCEPT noexcept
|
||||||
|
#else
|
||||||
|
#define PICOJSON_NOEXCEPT throw()
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
// experimental support for int64_t (see README.mkdn for detail)
|
// experimental support for int64_t (see README.mkdn for detail)
|
||||||
#ifdef PICOJSON_USE_INT64
|
#ifdef PICOJSON_USE_INT64
|
||||||
#define __STDC_FORMAT_MACROS
|
#define __STDC_FORMAT_MACROS
|
||||||
# include <errno.h>
|
#include <cerrno>
|
||||||
|
#if __cplusplus >= 201103L
|
||||||
|
#include <cinttypes>
|
||||||
|
#else
|
||||||
|
extern "C" {
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// to disable the use of localeconv(3), set PICOJSON_USE_LOCALE to 0
|
// to disable the use of localeconv(3), set PICOJSON_USE_LOCALE to 0
|
||||||
|
@ -73,7 +97,11 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef PICOJSON_ASSERT
|
#ifndef PICOJSON_ASSERT
|
||||||
# define PICOJSON_ASSERT(e) do { if (! (e)) throw std::runtime_error(#e); } while (0)
|
#define PICOJSON_ASSERT(e) \
|
||||||
|
do { \
|
||||||
|
if (!(e)) \
|
||||||
|
throw std::runtime_error(#e); \
|
||||||
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
@ -82,6 +110,7 @@ extern "C" {
|
||||||
#pragma warning(disable : 4244) // conversion from int to char
|
#pragma warning(disable : 4244) // conversion from int to char
|
||||||
#pragma warning(disable : 4127) // conditional expression is constant
|
#pragma warning(disable : 4127) // conditional expression is constant
|
||||||
#pragma warning(disable : 4702) // unreachable code
|
#pragma warning(disable : 4702) // unreachable code
|
||||||
|
#pragma warning(disable : 4706) // assignment within conditional expression
|
||||||
#else
|
#else
|
||||||
#define SNPRINTF snprintf
|
#define SNPRINTF snprintf
|
||||||
#endif
|
#endif
|
||||||
|
@ -96,13 +125,12 @@ namespace picojson {
|
||||||
array_type,
|
array_type,
|
||||||
object_type
|
object_type
|
||||||
#ifdef PICOJSON_USE_INT64
|
#ifdef PICOJSON_USE_INT64
|
||||||
, int64_type
|
,
|
||||||
|
int64_type
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum { INDENT_WIDTH = 2, DEFAULT_MAX_DEPTHS = 100 };
|
||||||
INDENT_WIDTH = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
struct null {};
|
struct null {};
|
||||||
|
|
||||||
|
@ -120,9 +148,11 @@ namespace picojson {
|
||||||
array *array_;
|
array *array_;
|
||||||
object *object_;
|
object *object_;
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int type_;
|
int type_;
|
||||||
_storage u_;
|
_storage u_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
value();
|
value();
|
||||||
value(int type, bool);
|
value(int type, bool);
|
||||||
|
@ -134,41 +164,60 @@ namespace picojson {
|
||||||
explicit value(const std::string &s);
|
explicit value(const std::string &s);
|
||||||
explicit value(const array &a);
|
explicit value(const array &a);
|
||||||
explicit value(const object &o);
|
explicit value(const object &o);
|
||||||
|
#if PICOJSON_USE_RVALUE_REFERENCE
|
||||||
|
explicit value(std::string &&s);
|
||||||
|
explicit value(array &&a);
|
||||||
|
explicit value(object &&o);
|
||||||
|
#endif
|
||||||
explicit value(const char *s);
|
explicit value(const char *s);
|
||||||
value(const char *s, size_t len);
|
value(const char *s, size_t len);
|
||||||
~value();
|
~value();
|
||||||
value(const value &x);
|
value(const value &x);
|
||||||
value &operator=(const value &x);
|
value &operator=(const value &x);
|
||||||
void swap(value& x);
|
#if PICOJSON_USE_RVALUE_REFERENCE
|
||||||
|
value(value &&x) PICOJSON_NOEXCEPT;
|
||||||
|
value &operator=(value &&x) PICOJSON_NOEXCEPT;
|
||||||
|
#endif
|
||||||
|
void swap(value &x) PICOJSON_NOEXCEPT;
|
||||||
template <typename T> bool is() const;
|
template <typename T> bool is() const;
|
||||||
template <typename T> const T &get() const;
|
template <typename T> const T &get() const;
|
||||||
template <typename T> T &get();
|
template <typename T> T &get();
|
||||||
|
template <typename T> void set(const T &);
|
||||||
|
#if PICOJSON_USE_RVALUE_REFERENCE
|
||||||
|
template <typename T> void set(T &&);
|
||||||
|
#endif
|
||||||
bool evaluate_as_boolean() const;
|
bool evaluate_as_boolean() const;
|
||||||
const value& get(size_t idx) const;
|
const value &get(const size_t idx) const;
|
||||||
const value &get(const std::string &key) const;
|
const value &get(const std::string &key) const;
|
||||||
value& get(size_t idx);
|
value &get(const size_t idx);
|
||||||
value &get(const std::string &key);
|
value &get(const std::string &key);
|
||||||
|
|
||||||
bool contains(size_t idx) const;
|
bool contains(const size_t idx) const;
|
||||||
bool contains(const std::string &key) const;
|
bool contains(const std::string &key) const;
|
||||||
std::string to_str() const;
|
std::string to_str() const;
|
||||||
template <typename Iter> void serialize(Iter os, bool prettify = false) const;
|
template <typename Iter> void serialize(Iter os, bool prettify = false) const;
|
||||||
std::string serialize(bool prettify = false) const;
|
std::string serialize(bool prettify = false) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename T> value(const T *); // intentionally defined to block implicit conversion of pointer to bool
|
template <typename T> value(const T *); // intentionally defined to block implicit conversion of pointer to bool
|
||||||
template <typename Iter> static void _indent(Iter os, int indent);
|
template <typename Iter> static void _indent(Iter os, int indent);
|
||||||
template <typename Iter> void _serialize(Iter os, int indent) const;
|
template <typename Iter> void _serialize(Iter os, int indent) const;
|
||||||
std::string _serialize(int indent) const;
|
std::string _serialize(int indent) const;
|
||||||
|
void clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef value::array array;
|
typedef value::array array;
|
||||||
typedef value::object object;
|
typedef value::object object;
|
||||||
|
|
||||||
inline value::value() : type_(null_type) {}
|
inline value::value() : type_(null_type), u_() {
|
||||||
|
}
|
||||||
|
|
||||||
inline value::value(int type, bool) : type_(type) {
|
inline value::value(int type, bool) : type_(type), u_() {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
#define INIT(p, v) case p##type: u_.p = v; break
|
#define INIT(p, v) \
|
||||||
|
case p##type: \
|
||||||
|
u_.p = v; \
|
||||||
|
break
|
||||||
INIT(boolean_, false);
|
INIT(boolean_, false);
|
||||||
INIT(number_, 0.0);
|
INIT(number_, 0.0);
|
||||||
#ifdef PICOJSON_USE_INT64
|
#ifdef PICOJSON_USE_INT64
|
||||||
|
@ -178,25 +227,26 @@ namespace picojson {
|
||||||
INIT(array_, new array());
|
INIT(array_, new array());
|
||||||
INIT(object_, new object());
|
INIT(object_, new object());
|
||||||
#undef INIT
|
#undef INIT
|
||||||
default: break;
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline value::value(bool b) : type_(boolean_type) {
|
inline value::value(bool b) : type_(boolean_type), u_() {
|
||||||
u_.boolean_ = b;
|
u_.boolean_ = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef PICOJSON_USE_INT64
|
#ifdef PICOJSON_USE_INT64
|
||||||
inline value::value(int64_t i) : type_(int64_type) {
|
inline value::value(int64_t i) : type_(int64_type), u_() {
|
||||||
u_.int64_ = i;
|
u_.int64_ = i;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline value::value(double n) : type_(number_type) {
|
inline value::value(double n) : type_(number_type), u_() {
|
||||||
if (
|
if (
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
!_finite(n)
|
!_finite(n)
|
||||||
#elif __cplusplus>=201103L || !(defined(isnan) && defined(isinf))
|
#elif __cplusplus >= 201103L
|
||||||
std::isnan(n) || std::isinf(n)
|
std::isnan(n) || std::isinf(n)
|
||||||
#else
|
#else
|
||||||
isnan(n) || isinf(n)
|
isnan(n) || isinf(n)
|
||||||
|
@ -207,40 +257,65 @@ namespace picojson {
|
||||||
u_.number_ = n;
|
u_.number_ = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline value::value(const std::string& s) : type_(string_type) {
|
inline value::value(const std::string &s) : type_(string_type), u_() {
|
||||||
u_.string_ = new std::string(s);
|
u_.string_ = new std::string(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline value::value(const array& a) : type_(array_type) {
|
inline value::value(const array &a) : type_(array_type), u_() {
|
||||||
u_.array_ = new array(a);
|
u_.array_ = new array(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline value::value(const object& o) : type_(object_type) {
|
inline value::value(const object &o) : type_(object_type), u_() {
|
||||||
u_.object_ = new object(o);
|
u_.object_ = new object(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline value::value(const char* s) : type_(string_type) {
|
#if PICOJSON_USE_RVALUE_REFERENCE
|
||||||
|
inline value::value(std::string &&s) : type_(string_type), u_() {
|
||||||
|
u_.string_ = new std::string(std::move(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline value::value(array &&a) : type_(array_type), u_() {
|
||||||
|
u_.array_ = new array(std::move(a));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline value::value(object &&o) : type_(object_type), u_() {
|
||||||
|
u_.object_ = new object(std::move(o));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
inline value::value(const char *s) : type_(string_type), u_() {
|
||||||
u_.string_ = new std::string(s);
|
u_.string_ = new std::string(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline value::value(const char* s, size_t len) : type_(string_type) {
|
inline value::value(const char *s, size_t len) : type_(string_type), u_() {
|
||||||
u_.string_ = new std::string(s, len);
|
u_.string_ = new std::string(s, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline value::~value() {
|
inline void value::clear() {
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
#define DEINIT(p) case p##type: delete u_.p; break
|
#define DEINIT(p) \
|
||||||
|
case p##type: \
|
||||||
|
delete u_.p; \
|
||||||
|
break
|
||||||
DEINIT(string_);
|
DEINIT(string_);
|
||||||
DEINIT(array_);
|
DEINIT(array_);
|
||||||
DEINIT(object_);
|
DEINIT(object_);
|
||||||
#undef DEINIT
|
#undef DEINIT
|
||||||
default: break;
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline value::value(const value& x) : type_(x.type_) {
|
inline value::~value() {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline value::value(const value &x) : type_(x.type_), u_() {
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
#define INIT(p, v) case p##type: u_.p = v; break
|
#define INIT(p, v) \
|
||||||
|
case p##type: \
|
||||||
|
u_.p = v; \
|
||||||
|
break
|
||||||
INIT(string_, new std::string(*x.u_.string_));
|
INIT(string_, new std::string(*x.u_.string_));
|
||||||
INIT(array_, new array(*x.u_.array_));
|
INIT(array_, new array(*x.u_.array_));
|
||||||
INIT(object_, new object(*x.u_.object_));
|
INIT(object_, new object(*x.u_.object_));
|
||||||
|
@ -259,7 +334,16 @@ namespace picojson {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void value::swap(value& x) {
|
#if PICOJSON_USE_RVALUE_REFERENCE
|
||||||
|
inline value::value(value &&x) PICOJSON_NOEXCEPT : type_(null_type), u_() {
|
||||||
|
swap(x);
|
||||||
|
}
|
||||||
|
inline value &value::operator=(value &&x) PICOJSON_NOEXCEPT {
|
||||||
|
swap(x);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
inline void value::swap(value &x) PICOJSON_NOEXCEPT {
|
||||||
std::swap(type_, x.type_);
|
std::swap(type_, x.type_);
|
||||||
std::swap(u_, x.u_);
|
std::swap(u_, x.u_);
|
||||||
}
|
}
|
||||||
|
@ -287,13 +371,11 @@ namespace picojson {
|
||||||
|
|
||||||
#define GET(ctype, var) \
|
#define GET(ctype, var) \
|
||||||
template <> inline const ctype &value::get<ctype>() const { \
|
template <> inline const ctype &value::get<ctype>() const { \
|
||||||
PICOJSON_ASSERT("type mismatch! call is<type>() before get<type>()" \
|
PICOJSON_ASSERT("type mismatch! call is<type>() before get<type>()" && is<ctype>()); \
|
||||||
&& is<ctype>()); \
|
|
||||||
return var; \
|
return var; \
|
||||||
} \
|
} \
|
||||||
template <> inline ctype &value::get<ctype>() { \
|
template <> inline ctype &value::get<ctype>() { \
|
||||||
PICOJSON_ASSERT("type mismatch! call is<type>() before get<type>()" \
|
PICOJSON_ASSERT("type mismatch! call is<type>() before get<type>()" && is<ctype>()); \
|
||||||
&& is<ctype>()); \
|
|
||||||
return var; \
|
return var; \
|
||||||
}
|
}
|
||||||
GET(bool, u_.boolean_)
|
GET(bool, u_.boolean_)
|
||||||
|
@ -301,13 +383,44 @@ namespace picojson {
|
||||||
GET(array, *u_.array_)
|
GET(array, *u_.array_)
|
||||||
GET(object, *u_.object_)
|
GET(object, *u_.object_)
|
||||||
#ifdef PICOJSON_USE_INT64
|
#ifdef PICOJSON_USE_INT64
|
||||||
GET(double, (type_ == int64_type && (const_cast<value*>(this)->type_ = number_type, const_cast<value*>(this)->u_.number_ = u_.int64_), u_.number_))
|
GET(double,
|
||||||
|
(type_ == int64_type && (const_cast<value *>(this)->type_ = number_type, (const_cast<value *>(this)->u_.number_ = u_.int64_)),
|
||||||
|
u_.number_))
|
||||||
GET(int64_t, u_.int64_)
|
GET(int64_t, u_.int64_)
|
||||||
#else
|
#else
|
||||||
GET(double, u_.number_)
|
GET(double, u_.number_)
|
||||||
#endif
|
#endif
|
||||||
#undef GET
|
#undef GET
|
||||||
|
|
||||||
|
#define SET(ctype, jtype, setter) \
|
||||||
|
template <> inline void value::set<ctype>(const ctype &_val) { \
|
||||||
|
clear(); \
|
||||||
|
type_ = jtype##_type; \
|
||||||
|
setter \
|
||||||
|
}
|
||||||
|
SET(bool, boolean, u_.boolean_ = _val;)
|
||||||
|
SET(std::string, string, u_.string_ = new std::string(_val);)
|
||||||
|
SET(array, array, u_.array_ = new array(_val);)
|
||||||
|
SET(object, object, u_.object_ = new object(_val);)
|
||||||
|
SET(double, number, u_.number_ = _val;)
|
||||||
|
#ifdef PICOJSON_USE_INT64
|
||||||
|
SET(int64_t, int64, u_.int64_ = _val;)
|
||||||
|
#endif
|
||||||
|
#undef SET
|
||||||
|
|
||||||
|
#if PICOJSON_USE_RVALUE_REFERENCE
|
||||||
|
#define MOVESET(ctype, jtype, setter) \
|
||||||
|
template <> inline void value::set<ctype>(ctype && _val) { \
|
||||||
|
clear(); \
|
||||||
|
type_ = jtype##_type; \
|
||||||
|
setter \
|
||||||
|
}
|
||||||
|
MOVESET(std::string, string, u_.string_ = new std::string(std::move(_val));)
|
||||||
|
MOVESET(array, array, u_.array_ = new array(std::move(_val));)
|
||||||
|
MOVESET(object, object, u_.object_ = new object(std::move(_val));)
|
||||||
|
#undef MOVESET
|
||||||
|
#endif
|
||||||
|
|
||||||
inline bool value::evaluate_as_boolean() const {
|
inline bool value::evaluate_as_boolean() const {
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case null_type:
|
case null_type:
|
||||||
|
@ -316,6 +429,10 @@ namespace picojson {
|
||||||
return u_.boolean_;
|
return u_.boolean_;
|
||||||
case number_type:
|
case number_type:
|
||||||
return u_.number_ != 0;
|
return u_.number_ != 0;
|
||||||
|
#ifdef PICOJSON_USE_INT64
|
||||||
|
case int64_type:
|
||||||
|
return u_.int64_ != 0;
|
||||||
|
#endif
|
||||||
case string_type:
|
case string_type:
|
||||||
return !u_.string_->empty();
|
return !u_.string_->empty();
|
||||||
default:
|
default:
|
||||||
|
@ -323,13 +440,13 @@ namespace picojson {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const value& value::get(size_t idx) const {
|
inline const value &value::get(const size_t idx) const {
|
||||||
static value s_null;
|
static value s_null;
|
||||||
PICOJSON_ASSERT(is<array>());
|
PICOJSON_ASSERT(is<array>());
|
||||||
return idx < u_.array_->size() ? (*u_.array_)[idx] : s_null;
|
return idx < u_.array_->size() ? (*u_.array_)[idx] : s_null;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline value& value::get(size_t idx) {
|
inline value &value::get(const size_t idx) {
|
||||||
static value s_null;
|
static value s_null;
|
||||||
PICOJSON_ASSERT(is<array>());
|
PICOJSON_ASSERT(is<array>());
|
||||||
return idx < u_.array_->size() ? (*u_.array_)[idx] : s_null;
|
return idx < u_.array_->size() ? (*u_.array_)[idx] : s_null;
|
||||||
|
@ -349,7 +466,7 @@ namespace picojson {
|
||||||
return i != u_.object_->end() ? i->second : s_null;
|
return i != u_.object_->end() ? i->second : s_null;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool value::contains(size_t idx) const {
|
inline bool value::contains(const size_t idx) const {
|
||||||
PICOJSON_ASSERT(is<array>());
|
PICOJSON_ASSERT(is<array>());
|
||||||
return idx < u_.array_->size();
|
return idx < u_.array_->size();
|
||||||
}
|
}
|
||||||
|
@ -362,8 +479,10 @@ namespace picojson {
|
||||||
|
|
||||||
inline std::string value::to_str() const {
|
inline std::string value::to_str() const {
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case null_type: return "null";
|
case null_type:
|
||||||
case boolean_type: return u_.boolean_ ? "true" : "false";
|
return "null";
|
||||||
|
case boolean_type:
|
||||||
|
return u_.boolean_ ? "true" : "false";
|
||||||
#ifdef PICOJSON_USE_INT64
|
#ifdef PICOJSON_USE_INT64
|
||||||
case int64_type: {
|
case int64_type: {
|
||||||
char buf[sizeof("-9223372036854775808")];
|
char buf[sizeof("-9223372036854775808")];
|
||||||
|
@ -388,10 +507,14 @@ namespace picojson {
|
||||||
#endif
|
#endif
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
case string_type: return *u_.string_;
|
case string_type:
|
||||||
case array_type: return "array";
|
return *u_.string_;
|
||||||
case object_type: return "object";
|
case array_type:
|
||||||
default: PICOJSON_ASSERT(0);
|
return "array";
|
||||||
|
case object_type:
|
||||||
|
return "object";
|
||||||
|
default:
|
||||||
|
PICOJSON_ASSERT(0);
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
__assume(0);
|
__assume(0);
|
||||||
#endif
|
#endif
|
||||||
|
@ -403,11 +526,14 @@ namespace picojson {
|
||||||
std::copy(s.begin(), s.end(), oi);
|
std::copy(s.begin(), s.end(), oi);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Iter> void serialize_str(const std::string& s, Iter oi) {
|
template <typename Iter> struct serialize_str_char {
|
||||||
*oi++ = '"';
|
Iter oi;
|
||||||
for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {
|
void operator()(char c) {
|
||||||
switch (*i) {
|
switch (c) {
|
||||||
#define MAP(val, sym) case val: copy(sym, oi); break
|
#define MAP(val, sym) \
|
||||||
|
case val: \
|
||||||
|
copy(sym, oi); \
|
||||||
|
break
|
||||||
MAP('"', "\\\"");
|
MAP('"', "\\\"");
|
||||||
MAP('\\', "\\\\");
|
MAP('\\', "\\\\");
|
||||||
MAP('/', "\\/");
|
MAP('/', "\\/");
|
||||||
|
@ -418,16 +544,22 @@ namespace picojson {
|
||||||
MAP('\t', "\\t");
|
MAP('\t', "\\t");
|
||||||
#undef MAP
|
#undef MAP
|
||||||
default:
|
default:
|
||||||
if (static_cast<unsigned char>(*i) < 0x20 || *i == 0x7f) {
|
if (static_cast<unsigned char>(c) < 0x20 || c == 0x7f) {
|
||||||
char buf[7];
|
char buf[7];
|
||||||
SNPRINTF(buf, sizeof(buf), "\\u%04x", *i & 0xff);
|
SNPRINTF(buf, sizeof(buf), "\\u%04x", c & 0xff);
|
||||||
copy(buf, buf + 6, oi);
|
copy(buf, buf + 6, oi);
|
||||||
} else {
|
} else {
|
||||||
*oi++ = *i;
|
*oi++ = c;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Iter> void serialize_str(const std::string &s, Iter oi) {
|
||||||
|
*oi++ = '"';
|
||||||
|
serialize_str_char<Iter> process_char = {oi};
|
||||||
|
std::for_each(s.begin(), s.end(), process_char);
|
||||||
*oi++ = '"';
|
*oi++ = '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,9 +588,7 @@ namespace picojson {
|
||||||
if (indent != -1) {
|
if (indent != -1) {
|
||||||
++indent;
|
++indent;
|
||||||
}
|
}
|
||||||
for (array::const_iterator i = u_.array_->begin();
|
for (array::const_iterator i = u_.array_->begin(); i != u_.array_->end(); ++i) {
|
||||||
i != u_.array_->end();
|
|
||||||
++i) {
|
|
||||||
if (i != u_.array_->begin()) {
|
if (i != u_.array_->begin()) {
|
||||||
*oi++ = ',';
|
*oi++ = ',';
|
||||||
}
|
}
|
||||||
|
@ -481,9 +611,7 @@ namespace picojson {
|
||||||
if (indent != -1) {
|
if (indent != -1) {
|
||||||
++indent;
|
++indent;
|
||||||
}
|
}
|
||||||
for (object::const_iterator i = u_.object_->begin();
|
for (object::const_iterator i = u_.object_->begin(); i != u_.object_->end(); ++i) {
|
||||||
i != u_.object_->end();
|
|
||||||
++i) {
|
|
||||||
if (i != u_.object_->begin()) {
|
if (i != u_.object_->begin()) {
|
||||||
*oi++ = ',';
|
*oi++ = ',';
|
||||||
}
|
}
|
||||||
|
@ -524,35 +652,40 @@ namespace picojson {
|
||||||
template <typename Iter> class input {
|
template <typename Iter> class input {
|
||||||
protected:
|
protected:
|
||||||
Iter cur_, end_;
|
Iter cur_, end_;
|
||||||
int last_ch_;
|
bool consumed_;
|
||||||
bool ungot_;
|
|
||||||
int line_;
|
int line_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
input(const Iter& first, const Iter& last) : cur_(first), end_(last), last_ch_(-1), ungot_(false), line_(1) {}
|
input(const Iter &first, const Iter &last) : cur_(first), end_(last), consumed_(false), line_(1) {
|
||||||
|
}
|
||||||
int getc() {
|
int getc() {
|
||||||
if (ungot_) {
|
if (consumed_) {
|
||||||
ungot_ = false;
|
if (*cur_ == '\n') {
|
||||||
return last_ch_;
|
++line_;
|
||||||
|
}
|
||||||
|
++cur_;
|
||||||
}
|
}
|
||||||
if (cur_ == end_) {
|
if (cur_ == end_) {
|
||||||
last_ch_ = -1;
|
consumed_ = false;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (last_ch_ == '\n') {
|
consumed_ = true;
|
||||||
line_++;
|
return *cur_ & 0xff;
|
||||||
}
|
|
||||||
last_ch_ = *cur_ & 0xff;
|
|
||||||
++cur_;
|
|
||||||
return last_ch_;
|
|
||||||
}
|
}
|
||||||
void ungetc() {
|
void ungetc() {
|
||||||
if (last_ch_ != -1) {
|
consumed_ = false;
|
||||||
PICOJSON_ASSERT(! ungot_);
|
|
||||||
ungot_ = true;
|
|
||||||
}
|
}
|
||||||
|
Iter cur() const {
|
||||||
|
if (consumed_) {
|
||||||
|
input<Iter> *self = const_cast<input<Iter> *>(this);
|
||||||
|
self->consumed_ = false;
|
||||||
|
++self->cur_;
|
||||||
|
}
|
||||||
|
return cur_;
|
||||||
|
}
|
||||||
|
int line() const {
|
||||||
|
return line_;
|
||||||
}
|
}
|
||||||
Iter cur() const { return cur_; }
|
|
||||||
int line() const { return line_; }
|
|
||||||
void skip_ws() {
|
void skip_ws() {
|
||||||
while (1) {
|
while (1) {
|
||||||
int ch = getc();
|
int ch = getc();
|
||||||
|
@ -562,18 +695,16 @@ namespace picojson {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool expect(int expect) {
|
bool expect(const int expected) {
|
||||||
skip_ws();
|
skip_ws();
|
||||||
if (getc() != expect) {
|
if (getc() != expected) {
|
||||||
ungetc();
|
ungetc();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool match(const std::string &pattern) {
|
bool match(const std::string &pattern) {
|
||||||
for (std::string::const_iterator pi(pattern.begin());
|
for (std::string::const_iterator pi(pattern.begin()); pi != pattern.end(); ++pi) {
|
||||||
pi != pattern.end();
|
|
||||||
++pi) {
|
|
||||||
if (getc() != *pi) {
|
if (getc() != *pi) {
|
||||||
ungetc();
|
ungetc();
|
||||||
return false;
|
return false;
|
||||||
|
@ -627,20 +758,20 @@ namespace picojson {
|
||||||
uni_ch += 0x10000;
|
uni_ch += 0x10000;
|
||||||
}
|
}
|
||||||
if (uni_ch < 0x80) {
|
if (uni_ch < 0x80) {
|
||||||
out.push_back(uni_ch);
|
out.push_back(static_cast<char>(uni_ch));
|
||||||
} else {
|
} else {
|
||||||
if (uni_ch < 0x800) {
|
if (uni_ch < 0x800) {
|
||||||
out.push_back(0xc0 | (uni_ch >> 6));
|
out.push_back(static_cast<char>(0xc0 | (uni_ch >> 6)));
|
||||||
} else {
|
} else {
|
||||||
if (uni_ch < 0x10000) {
|
if (uni_ch < 0x10000) {
|
||||||
out.push_back(0xe0 | (uni_ch >> 12));
|
out.push_back(static_cast<char>(0xe0 | (uni_ch >> 12)));
|
||||||
} else {
|
} else {
|
||||||
out.push_back(0xf0 | (uni_ch >> 18));
|
out.push_back(static_cast<char>(0xf0 | (uni_ch >> 18)));
|
||||||
out.push_back(0x80 | ((uni_ch >> 12) & 0x3f));
|
out.push_back(static_cast<char>(0x80 | ((uni_ch >> 12) & 0x3f)));
|
||||||
}
|
}
|
||||||
out.push_back(0x80 | ((uni_ch >> 6) & 0x3f));
|
out.push_back(static_cast<char>(0x80 | ((uni_ch >> 6) & 0x3f)));
|
||||||
}
|
}
|
||||||
out.push_back(0x80 | (uni_ch & 0x3f));
|
out.push_back(static_cast<char>(0x80 | (uni_ch & 0x3f)));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -658,7 +789,10 @@ namespace picojson {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
#define MAP(sym, val) case sym: out.push_back(val); break
|
#define MAP(sym, val) \
|
||||||
|
case sym: \
|
||||||
|
out.push_back(val); \
|
||||||
|
break
|
||||||
MAP('"', '\"');
|
MAP('"', '\"');
|
||||||
MAP('\\', '\\');
|
MAP('\\', '\\');
|
||||||
MAP('/', '/');
|
MAP('/', '/');
|
||||||
|
@ -677,7 +811,7 @@ namespace picojson {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
out.push_back(ch);
|
out.push_back(static_cast<char>(ch));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -705,29 +839,26 @@ namespace picojson {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (in.expect('}')) {
|
if (in.expect('}')) {
|
||||||
return true;
|
return ctx.parse_object_stop();
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
std::string key;
|
std::string key;
|
||||||
if (! in.expect('"')
|
if (!in.expect('"') || !_parse_string(key, in) || !in.expect(':')) {
|
||||||
|| ! _parse_string(key, in)
|
|
||||||
|| ! in.expect(':')) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!ctx.parse_object_item(in, key)) {
|
if (!ctx.parse_object_item(in, key)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} while (in.expect(','));
|
} while (in.expect(','));
|
||||||
return in.expect('}');
|
return in.expect('}') && ctx.parse_object_stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Iter> inline std::string _parse_number(input<Iter> &in) {
|
template <typename Iter> inline std::string _parse_number(input<Iter> &in) {
|
||||||
std::string num_str;
|
std::string num_str;
|
||||||
while (1) {
|
while (1) {
|
||||||
int ch = in.getc();
|
int ch = in.getc();
|
||||||
if (('0' <= ch && ch <= '9') || ch == '+' || ch == '-'
|
if (('0' <= ch && ch <= '9') || ch == '+' || ch == '-' || ch == 'e' || ch == 'E') {
|
||||||
|| ch == 'e' || ch == 'E') {
|
num_str.push_back(static_cast<char>(ch));
|
||||||
num_str.push_back(ch);
|
|
||||||
} else if (ch == '.') {
|
} else if (ch == '.') {
|
||||||
#if PICOJSON_USE_LOCALE
|
#if PICOJSON_USE_LOCALE
|
||||||
num_str += localeconv()->decimal_point;
|
num_str += localeconv()->decimal_point;
|
||||||
|
@ -746,7 +877,8 @@ namespace picojson {
|
||||||
in.skip_ws();
|
in.skip_ws();
|
||||||
int ch = in.getc();
|
int ch = in.getc();
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
#define IS(ch, text, op) case ch: \
|
#define IS(ch, text, op) \
|
||||||
|
case ch: \
|
||||||
if (in.match(text) && op) { \
|
if (in.match(text) && op) { \
|
||||||
return true; \
|
return true; \
|
||||||
} else { \
|
} else { \
|
||||||
|
@ -767,7 +899,7 @@ namespace picojson {
|
||||||
double f;
|
double f;
|
||||||
char *endp;
|
char *endp;
|
||||||
in.ungetc();
|
in.ungetc();
|
||||||
std::string num_str = _parse_number(in);
|
std::string num_str(_parse_number(in));
|
||||||
if (num_str.empty()) {
|
if (num_str.empty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -775,10 +907,8 @@ namespace picojson {
|
||||||
{
|
{
|
||||||
errno = 0;
|
errno = 0;
|
||||||
intmax_t ival = strtoimax(num_str.c_str(), &endp, 10);
|
intmax_t ival = strtoimax(num_str.c_str(), &endp, 10);
|
||||||
if (errno == 0
|
if (errno == 0 && std::numeric_limits<int64_t>::min() <= ival && ival <= std::numeric_limits<int64_t>::max() &&
|
||||||
&& std::numeric_limits<int64_t>::min() <= ival
|
endp == num_str.c_str() + num_str.size()) {
|
||||||
&& ival <= std::numeric_limits<int64_t>::max()
|
|
||||||
&& endp == num_str.c_str() + num_str.size()) {
|
|
||||||
ctx.set_int64(ival);
|
ctx.set_int64(ival);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -799,19 +929,35 @@ namespace picojson {
|
||||||
|
|
||||||
class deny_parse_context {
|
class deny_parse_context {
|
||||||
public:
|
public:
|
||||||
bool set_null() { return false; }
|
bool set_null() {
|
||||||
bool set_bool(bool) { return false; }
|
return false;
|
||||||
|
}
|
||||||
|
bool set_bool(bool) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
#ifdef PICOJSON_USE_INT64
|
#ifdef PICOJSON_USE_INT64
|
||||||
bool set_int64(int64_t) { return false; }
|
bool set_int64(int64_t) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
bool set_number(double) { return false; }
|
bool set_number(double) {
|
||||||
template <typename Iter> bool parse_string(input<Iter>&) { return false; }
|
return false;
|
||||||
bool parse_array_start() { return false; }
|
}
|
||||||
|
template <typename Iter> bool parse_string(input<Iter> &) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool parse_array_start() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
template <typename Iter> bool parse_array_item(input<Iter> &, size_t) {
|
template <typename Iter> bool parse_array_item(input<Iter> &, size_t) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool parse_array_stop(size_t) { return false; }
|
bool parse_array_stop(size_t) {
|
||||||
bool parse_object_start() { return false; }
|
return false;
|
||||||
|
}
|
||||||
|
bool parse_object_start() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
template <typename Iter> bool parse_object_item(input<Iter> &, const std::string &) {
|
template <typename Iter> bool parse_object_item(input<Iter> &, const std::string &) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -820,8 +966,11 @@ namespace picojson {
|
||||||
class default_parse_context {
|
class default_parse_context {
|
||||||
protected:
|
protected:
|
||||||
value *out_;
|
value *out_;
|
||||||
|
size_t depths_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
default_parse_context(value* out) : out_(out) {}
|
default_parse_context(value *out, size_t depths = DEFAULT_MAX_DEPTHS) : out_(out), depths_(depths) {
|
||||||
|
}
|
||||||
bool set_null() {
|
bool set_null() {
|
||||||
*out_ = value();
|
*out_ = value();
|
||||||
return true;
|
return true;
|
||||||
|
@ -845,56 +994,101 @@ namespace picojson {
|
||||||
return _parse_string(out_->get<std::string>(), in);
|
return _parse_string(out_->get<std::string>(), in);
|
||||||
}
|
}
|
||||||
bool parse_array_start() {
|
bool parse_array_start() {
|
||||||
|
if (depths_ == 0)
|
||||||
|
return false;
|
||||||
|
--depths_;
|
||||||
*out_ = value(array_type, false);
|
*out_ = value(array_type, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
template <typename Iter> bool parse_array_item(input<Iter> &in, size_t) {
|
template <typename Iter> bool parse_array_item(input<Iter> &in, size_t) {
|
||||||
array &a = out_->get<array>();
|
array &a = out_->get<array>();
|
||||||
a.push_back(value());
|
a.push_back(value());
|
||||||
default_parse_context ctx(&a.back());
|
default_parse_context ctx(&a.back(), depths_);
|
||||||
return _parse(ctx, in);
|
return _parse(ctx, in);
|
||||||
}
|
}
|
||||||
bool parse_array_stop(size_t) { return true; }
|
bool parse_array_stop(size_t) {
|
||||||
|
++depths_;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
bool parse_object_start() {
|
bool parse_object_start() {
|
||||||
|
if (depths_ == 0)
|
||||||
|
return false;
|
||||||
*out_ = value(object_type, false);
|
*out_ = value(object_type, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
template <typename Iter> bool parse_object_item(input<Iter> &in, const std::string &key) {
|
template <typename Iter> bool parse_object_item(input<Iter> &in, const std::string &key) {
|
||||||
object &o = out_->get<object>();
|
object &o = out_->get<object>();
|
||||||
default_parse_context ctx(&o[key]);
|
default_parse_context ctx(&o[key], depths_);
|
||||||
return _parse(ctx, in);
|
return _parse(ctx, in);
|
||||||
}
|
}
|
||||||
|
bool parse_object_stop() {
|
||||||
|
++depths_;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
default_parse_context(const default_parse_context &);
|
default_parse_context(const default_parse_context &);
|
||||||
default_parse_context &operator=(const default_parse_context &);
|
default_parse_context &operator=(const default_parse_context &);
|
||||||
};
|
};
|
||||||
|
|
||||||
class null_parse_context {
|
class null_parse_context {
|
||||||
|
protected:
|
||||||
|
size_t depths_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct dummy_str {
|
struct dummy_str {
|
||||||
void push_back(int) {}
|
void push_back(int) {
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
null_parse_context() {}
|
null_parse_context(size_t depths = DEFAULT_MAX_DEPTHS) : depths_(depths) {
|
||||||
bool set_null() { return true; }
|
}
|
||||||
bool set_bool(bool) { return true; }
|
bool set_null() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool set_bool(bool) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
#ifdef PICOJSON_USE_INT64
|
#ifdef PICOJSON_USE_INT64
|
||||||
bool set_int64(int64_t) { return true; }
|
bool set_int64(int64_t) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
bool set_number(double) { return true; }
|
bool set_number(double) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
template <typename Iter> bool parse_string(input<Iter> &in) {
|
template <typename Iter> bool parse_string(input<Iter> &in) {
|
||||||
dummy_str s;
|
dummy_str s;
|
||||||
return _parse_string(s, in);
|
return _parse_string(s, in);
|
||||||
}
|
}
|
||||||
bool parse_array_start() { return true; }
|
bool parse_array_start() {
|
||||||
|
if (depths_ == 0)
|
||||||
|
return false;
|
||||||
|
--depths_;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
template <typename Iter> bool parse_array_item(input<Iter> &in, size_t) {
|
template <typename Iter> bool parse_array_item(input<Iter> &in, size_t) {
|
||||||
return _parse(*this, in);
|
return _parse(*this, in);
|
||||||
}
|
}
|
||||||
bool parse_array_stop(size_t) { return true; }
|
bool parse_array_stop(size_t) {
|
||||||
bool parse_object_start() { return true; }
|
++depths_;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool parse_object_start() {
|
||||||
|
if (depths_ == 0)
|
||||||
|
return false;
|
||||||
|
--depths_;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
template <typename Iter> bool parse_object_item(input<Iter> &in, const std::string &) {
|
template <typename Iter> bool parse_object_item(input<Iter> &in, const std::string &) {
|
||||||
|
++depths_;
|
||||||
return _parse(*this, in);
|
return _parse(*this, in);
|
||||||
}
|
}
|
||||||
|
bool parse_object_stop() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
null_parse_context(const null_parse_context &);
|
null_parse_context(const null_parse_context &);
|
||||||
null_parse_context &operator=(const null_parse_context &);
|
null_parse_context &operator=(const null_parse_context &);
|
||||||
|
@ -918,7 +1112,7 @@ namespace picojson {
|
||||||
if (ch == -1 || ch == '\n') {
|
if (ch == -1 || ch == '\n') {
|
||||||
break;
|
break;
|
||||||
} else if (ch >= ' ') {
|
} else if (ch >= ' ') {
|
||||||
err->push_back(ch);
|
err->push_back(static_cast<char>(ch));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -938,14 +1132,11 @@ namespace picojson {
|
||||||
|
|
||||||
inline std::string parse(value &out, std::istream &is) {
|
inline std::string parse(value &out, std::istream &is) {
|
||||||
std::string err;
|
std::string err;
|
||||||
parse(out, std::istreambuf_iterator<char>(is.rdbuf()),
|
parse(out, std::istreambuf_iterator<char>(is.rdbuf()), std::istreambuf_iterator<char>(), &err);
|
||||||
std::istreambuf_iterator<char>(), &err);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> struct last_error_t {
|
template <typename T> struct last_error_t { static std::string s; };
|
||||||
static std::string s;
|
|
||||||
};
|
|
||||||
template <typename T> std::string last_error_t<T>::s;
|
template <typename T> std::string last_error_t<T>::s;
|
||||||
|
|
||||||
inline void set_last_error(const std::string &s) {
|
inline void set_last_error(const std::string &s) {
|
||||||
|
@ -980,17 +1171,17 @@ namespace picojson {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !PICOJSON_USE_RVALUE_REFERENCE
|
||||||
namespace std {
|
namespace std {
|
||||||
template<> inline void swap(picojson::value& x, picojson::value& y)
|
template <> inline void swap(picojson::value &x, picojson::value &y) {
|
||||||
{
|
|
||||||
x.swap(y);
|
x.swap(y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
inline std::istream& operator>>(std::istream& is, picojson::value& x)
|
inline std::istream &operator>>(std::istream &is, picojson::value &x) {
|
||||||
{
|
|
||||||
picojson::set_last_error(std::string());
|
picojson::set_last_error(std::string());
|
||||||
std::string err = picojson::parse(x, is);
|
const std::string err(picojson::parse(x, is));
|
||||||
if (!err.empty()) {
|
if (!err.empty()) {
|
||||||
picojson::set_last_error(err);
|
picojson::set_last_error(err);
|
||||||
is.setstate(std::ios::failbit);
|
is.setstate(std::ios::failbit);
|
||||||
|
@ -998,8 +1189,7 @@ inline std::istream& operator>>(std::istream& is, picojson::value& x)
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::ostream& operator<<(std::ostream& os, const picojson::value& x)
|
inline std::ostream &operator<<(std::ostream &os, const picojson::value &x) {
|
||||||
{
|
|
||||||
x.serialize(std::ostream_iterator<char>(os));
|
x.serialize(std::ostream_iterator<char>(os));
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ CheckOptions:
|
||||||
else()
|
else()
|
||||||
target_include_directories(cppcheck-gui SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
|
target_include_directories(cppcheck-gui SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
|
||||||
endif()
|
endif()
|
||||||
|
target_include_directories(cppcheck-gui PRIVATE ${PROJECT_SOURCE_DIR}/externals/picojson/)
|
||||||
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
|
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
|
||||||
target_precompile_headers(cppcheck-gui PRIVATE precompiled.h)
|
target_precompile_headers(cppcheck-gui PRIVATE precompiled.h)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -94,6 +94,8 @@
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <Qt>
|
#include <Qt>
|
||||||
|
|
||||||
|
#include "json.h"
|
||||||
|
|
||||||
static const QString compile_commands_json("compile_commands.json");
|
static const QString compile_commands_json("compile_commands.json");
|
||||||
|
|
||||||
static QString fromNativePath(const QString& p) {
|
static QString fromNativePath(const QString& p) {
|
||||||
|
@ -1005,25 +1007,31 @@ Settings MainWindow::getCppcheckSettings() {
|
||||||
|
|
||||||
addonFilePath.replace(QChar('\\'), QChar('/'));
|
addonFilePath.replace(QChar('\\'), QChar('/'));
|
||||||
|
|
||||||
// TODO: use picojson to generate the JSON
|
picojson::object obj;
|
||||||
QString json;
|
obj["script"] = picojson::value(addonFilePath.toStdString());
|
||||||
json += "{ \"script\":\"" + addonFilePath + "\"";
|
|
||||||
if (!pythonCmd.isEmpty())
|
if (!pythonCmd.isEmpty())
|
||||||
json += ", \"python\":\"" + pythonCmd + "\"";
|
obj["python"] = picojson::value(pythonCmd.toStdString());
|
||||||
|
|
||||||
|
if (!isCppcheckPremium() && addon == "misra") {
|
||||||
const QString misraFile = fromNativePath(mSettings->value(SETTINGS_MISRA_FILE).toString());
|
const QString misraFile = fromNativePath(mSettings->value(SETTINGS_MISRA_FILE).toString());
|
||||||
if (!isCppcheckPremium() && addon == "misra" && !misraFile.isEmpty()) {
|
if (!misraFile.isEmpty()) {
|
||||||
QString arg;
|
QString arg;
|
||||||
if (misraFile.endsWith(".pdf", Qt::CaseInsensitive))
|
if (misraFile.endsWith(".pdf", Qt::CaseInsensitive))
|
||||||
arg = "--misra-pdf=" + misraFile;
|
arg = "--misra-pdf=" + misraFile;
|
||||||
else
|
else
|
||||||
arg = "--rule-texts=" + misraFile;
|
arg = "--rule-texts=" + misraFile;
|
||||||
json += ", \"args\":[\"" + arg + "\"]";
|
obj["args"] = picojson::value(arg.toStdString());
|
||||||
}
|
}
|
||||||
json += " }";
|
}
|
||||||
result.addons.emplace(json.toStdString());
|
picojson::value json;
|
||||||
|
json.set(std::move(obj));
|
||||||
|
std::string json_str = json.serialize();
|
||||||
|
|
||||||
AddonInfo addonInfo;
|
AddonInfo addonInfo;
|
||||||
addonInfo.getAddonInfo(json.toStdString(), result.exename);
|
addonInfo.getAddonInfo(json_str, result.exename);
|
||||||
result.addonInfos.emplace_back(std::move(addonInfo));
|
result.addonInfos.emplace_back(std::move(addonInfo));
|
||||||
|
|
||||||
|
result.addons.emplace(std::move(json_str));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCppcheckPremium()) {
|
if (isCppcheckPremium()) {
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
SUPPRESS_WARNING_PUSH("-Wfloat-equal")
|
SUPPRESS_WARNING_PUSH("-Wfloat-equal")
|
||||||
SUPPRESS_WARNING_CLANG_PUSH("-Wtautological-type-limit-compare")
|
SUPPRESS_WARNING_CLANG_PUSH("-Wtautological-type-limit-compare")
|
||||||
SUPPRESS_WARNING_GCC_PUSH("-Wparentheses")
|
|
||||||
SUPPRESS_WARNING_CLANG_PUSH("-Wextra-semi-stmt")
|
SUPPRESS_WARNING_CLANG_PUSH("-Wextra-semi-stmt")
|
||||||
SUPPRESS_WARNING_CLANG_PUSH("-Wzero-as-null-pointer-constant")
|
SUPPRESS_WARNING_CLANG_PUSH("-Wzero-as-null-pointer-constant")
|
||||||
|
|
||||||
|
@ -32,7 +31,6 @@ SUPPRESS_WARNING_CLANG_PUSH("-Wzero-as-null-pointer-constant")
|
||||||
|
|
||||||
SUPPRESS_WARNING_CLANG_POP
|
SUPPRESS_WARNING_CLANG_POP
|
||||||
SUPPRESS_WARNING_CLANG_POP
|
SUPPRESS_WARNING_CLANG_POP
|
||||||
SUPPRESS_WARNING_GCC_POP
|
|
||||||
SUPPRESS_WARNING_CLANG_POP
|
SUPPRESS_WARNING_CLANG_POP
|
||||||
SUPPRESS_WARNING_POP
|
SUPPRESS_WARNING_POP
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue