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:
Oliver Stöneberg 2023-12-05 19:02:18 +01:00 committed by GitHub
parent 70745b527a
commit 347b188726
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1088 additions and 891 deletions

View File

@ -32,6 +32,7 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstddef>
#include <iostream>
#include <iterator>
#include <limits>
@ -39,6 +40,7 @@
#include <stdexcept>
#include <string>
#include <vector>
#include <utility>
// for isnan/isinf
#if __cplusplus >= 201103L
@ -55,11 +57,33 @@ extern "C" {
}
#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)
#ifdef PICOJSON_USE_INT64
#define __STDC_FORMAT_MACROS
# include <errno.h>
#include <cerrno>
#if __cplusplus >= 201103L
#include <cinttypes>
#else
extern "C" {
#include <inttypes.h>
}
#endif
#endif
// to disable the use of localeconv(3), set PICOJSON_USE_LOCALE to 0
@ -73,7 +97,11 @@ extern "C" {
#endif
#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
#ifdef _MSC_VER
@ -82,6 +110,7 @@ extern "C" {
#pragma warning(disable : 4244) // conversion from int to char
#pragma warning(disable : 4127) // conditional expression is constant
#pragma warning(disable : 4702) // unreachable code
#pragma warning(disable : 4706) // assignment within conditional expression
#else
#define SNPRINTF snprintf
#endif
@ -96,13 +125,12 @@ namespace picojson {
array_type,
object_type
#ifdef PICOJSON_USE_INT64
, int64_type
,
int64_type
#endif
};
enum {
INDENT_WIDTH = 2
};
enum { INDENT_WIDTH = 2, DEFAULT_MAX_DEPTHS = 100 };
struct null {};
@ -120,9 +148,11 @@ namespace picojson {
array *array_;
object *object_;
};
protected:
int type_;
_storage u_;
public:
value();
value(int type, bool);
@ -134,41 +164,60 @@ namespace picojson {
explicit value(const std::string &s);
explicit value(const array &a);
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);
value(const char *s, size_t len);
~value();
value(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> const T &get() const;
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;
const value& get(size_t idx) const;
const value &get(const size_t idx) 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);
bool contains(size_t idx) const;
bool contains(const size_t idx) const;
bool contains(const std::string &key) const;
std::string to_str() const;
template <typename Iter> void serialize(Iter os, bool prettify = false) const;
std::string serialize(bool prettify = false) const;
private:
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> void _serialize(Iter os, int indent) const;
std::string _serialize(int indent) const;
void clear();
};
typedef value::array array;
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) {
#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(number_, 0.0);
#ifdef PICOJSON_USE_INT64
@ -178,25 +227,26 @@ namespace picojson {
INIT(array_, new array());
INIT(object_, new object());
#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;
}
#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;
}
#endif
inline value::value(double n) : type_(number_type) {
inline value::value(double n) : type_(number_type), u_() {
if (
#ifdef _MSC_VER
!_finite(n)
#elif __cplusplus>=201103L || !(defined(isnan) && defined(isinf))
#elif __cplusplus >= 201103L
std::isnan(n) || std::isinf(n)
#else
isnan(n) || isinf(n)
@ -207,40 +257,65 @@ namespace picojson {
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);
}
inline value::value(const array& a) : type_(array_type) {
inline value::value(const array &a) : type_(array_type), u_() {
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);
}
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);
}
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);
}
inline value::~value() {
inline void value::clear() {
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(array_);
DEINIT(object_);
#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_) {
#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(array_, new array(*x.u_.array_));
INIT(object_, new object(*x.u_.object_));
@ -259,7 +334,16 @@ namespace picojson {
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(u_, x.u_);
}
@ -287,13 +371,11 @@ namespace picojson {
#define GET(ctype, var) \
template <> inline const ctype &value::get<ctype>() const { \
PICOJSON_ASSERT("type mismatch! call is<type>() before get<type>()" \
&& is<ctype>()); \
PICOJSON_ASSERT("type mismatch! call is<type>() before get<type>()" && is<ctype>()); \
return var; \
} \
template <> inline ctype &value::get<ctype>() { \
PICOJSON_ASSERT("type mismatch! call is<type>() before get<type>()" \
&& is<ctype>()); \
PICOJSON_ASSERT("type mismatch! call is<type>() before get<type>()" && is<ctype>()); \
return var; \
}
GET(bool, u_.boolean_)
@ -301,13 +383,44 @@ namespace picojson {
GET(array, *u_.array_)
GET(object, *u_.object_)
#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_)
#else
GET(double, u_.number_)
#endif
#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 {
switch (type_) {
case null_type:
@ -316,6 +429,10 @@ namespace picojson {
return u_.boolean_;
case number_type:
return u_.number_ != 0;
#ifdef PICOJSON_USE_INT64
case int64_type:
return u_.int64_ != 0;
#endif
case string_type:
return !u_.string_->empty();
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;
PICOJSON_ASSERT(is<array>());
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;
PICOJSON_ASSERT(is<array>());
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;
}
inline bool value::contains(size_t idx) const {
inline bool value::contains(const size_t idx) const {
PICOJSON_ASSERT(is<array>());
return idx < u_.array_->size();
}
@ -362,8 +479,10 @@ namespace picojson {
inline std::string value::to_str() const {
switch (type_) {
case null_type: return "null";
case boolean_type: return u_.boolean_ ? "true" : "false";
case null_type:
return "null";
case boolean_type:
return u_.boolean_ ? "true" : "false";
#ifdef PICOJSON_USE_INT64
case int64_type: {
char buf[sizeof("-9223372036854775808")];
@ -388,10 +507,14 @@ namespace picojson {
#endif
return buf;
}
case string_type: return *u_.string_;
case array_type: return "array";
case object_type: return "object";
default: PICOJSON_ASSERT(0);
case string_type:
return *u_.string_;
case array_type:
return "array";
case object_type:
return "object";
default:
PICOJSON_ASSERT(0);
#ifdef _MSC_VER
__assume(0);
#endif
@ -403,11 +526,14 @@ namespace picojson {
std::copy(s.begin(), s.end(), oi);
}
template <typename Iter> void serialize_str(const std::string& s, Iter oi) {
*oi++ = '"';
for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {
switch (*i) {
#define MAP(val, sym) case val: copy(sym, oi); break
template <typename Iter> struct serialize_str_char {
Iter oi;
void operator()(char c) {
switch (c) {
#define MAP(val, sym) \
case val: \
copy(sym, oi); \
break
MAP('"', "\\\"");
MAP('\\', "\\\\");
MAP('/', "\\/");
@ -418,16 +544,22 @@ namespace picojson {
MAP('\t', "\\t");
#undef MAP
default:
if (static_cast<unsigned char>(*i) < 0x20 || *i == 0x7f) {
if (static_cast<unsigned char>(c) < 0x20 || c == 0x7f) {
char buf[7];
SNPRINTF(buf, sizeof(buf), "\\u%04x", *i & 0xff);
SNPRINTF(buf, sizeof(buf), "\\u%04x", c & 0xff);
copy(buf, buf + 6, oi);
} else {
*oi++ = *i;
*oi++ = c;
}
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++ = '"';
}
@ -456,9 +588,7 @@ namespace picojson {
if (indent != -1) {
++indent;
}
for (array::const_iterator i = u_.array_->begin();
i != u_.array_->end();
++i) {
for (array::const_iterator i = u_.array_->begin(); i != u_.array_->end(); ++i) {
if (i != u_.array_->begin()) {
*oi++ = ',';
}
@ -481,9 +611,7 @@ namespace picojson {
if (indent != -1) {
++indent;
}
for (object::const_iterator i = u_.object_->begin();
i != u_.object_->end();
++i) {
for (object::const_iterator i = u_.object_->begin(); i != u_.object_->end(); ++i) {
if (i != u_.object_->begin()) {
*oi++ = ',';
}
@ -524,35 +652,40 @@ namespace picojson {
template <typename Iter> class input {
protected:
Iter cur_, end_;
int last_ch_;
bool ungot_;
bool consumed_;
int line_;
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() {
if (ungot_) {
ungot_ = false;
return last_ch_;
if (consumed_) {
if (*cur_ == '\n') {
++line_;
}
++cur_;
}
if (cur_ == end_) {
last_ch_ = -1;
consumed_ = false;
return -1;
}
if (last_ch_ == '\n') {
line_++;
}
last_ch_ = *cur_ & 0xff;
++cur_;
return last_ch_;
consumed_ = true;
return *cur_ & 0xff;
}
void ungetc() {
if (last_ch_ != -1) {
PICOJSON_ASSERT(! ungot_);
ungot_ = true;
consumed_ = false;
}
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() {
while (1) {
int ch = getc();
@ -562,18 +695,16 @@ namespace picojson {
}
}
}
bool expect(int expect) {
bool expect(const int expected) {
skip_ws();
if (getc() != expect) {
if (getc() != expected) {
ungetc();
return false;
}
return true;
}
bool match(const std::string &pattern) {
for (std::string::const_iterator pi(pattern.begin());
pi != pattern.end();
++pi) {
for (std::string::const_iterator pi(pattern.begin()); pi != pattern.end(); ++pi) {
if (getc() != *pi) {
ungetc();
return false;
@ -627,20 +758,20 @@ namespace picojson {
uni_ch += 0x10000;
}
if (uni_ch < 0x80) {
out.push_back(uni_ch);
out.push_back(static_cast<char>(uni_ch));
} else {
if (uni_ch < 0x800) {
out.push_back(0xc0 | (uni_ch >> 6));
out.push_back(static_cast<char>(0xc0 | (uni_ch >> 6)));
} else {
if (uni_ch < 0x10000) {
out.push_back(0xe0 | (uni_ch >> 12));
out.push_back(static_cast<char>(0xe0 | (uni_ch >> 12)));
} else {
out.push_back(0xf0 | (uni_ch >> 18));
out.push_back(0x80 | ((uni_ch >> 12) & 0x3f));
out.push_back(static_cast<char>(0xf0 | (uni_ch >> 18)));
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;
}
@ -658,7 +789,10 @@ namespace picojson {
return false;
}
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('/', '/');
@ -677,7 +811,7 @@ namespace picojson {
return false;
}
} else {
out.push_back(ch);
out.push_back(static_cast<char>(ch));
}
}
return false;
@ -705,29 +839,26 @@ namespace picojson {
return false;
}
if (in.expect('}')) {
return true;
return ctx.parse_object_stop();
}
do {
std::string key;
if (! in.expect('"')
|| ! _parse_string(key, in)
|| ! in.expect(':')) {
if (!in.expect('"') || !_parse_string(key, in) || !in.expect(':')) {
return false;
}
if (!ctx.parse_object_item(in, key)) {
return false;
}
} while (in.expect(','));
return in.expect('}');
return in.expect('}') && ctx.parse_object_stop();
}
template <typename Iter> inline std::string _parse_number(input<Iter> &in) {
std::string num_str;
while (1) {
int ch = in.getc();
if (('0' <= ch && ch <= '9') || ch == '+' || ch == '-'
|| ch == 'e' || ch == 'E') {
num_str.push_back(ch);
if (('0' <= ch && ch <= '9') || ch == '+' || ch == '-' || ch == 'e' || ch == 'E') {
num_str.push_back(static_cast<char>(ch));
} else if (ch == '.') {
#if PICOJSON_USE_LOCALE
num_str += localeconv()->decimal_point;
@ -746,7 +877,8 @@ namespace picojson {
in.skip_ws();
int ch = in.getc();
switch (ch) {
#define IS(ch, text, op) case ch: \
#define IS(ch, text, op) \
case ch: \
if (in.match(text) && op) { \
return true; \
} else { \
@ -767,7 +899,7 @@ namespace picojson {
double f;
char *endp;
in.ungetc();
std::string num_str = _parse_number(in);
std::string num_str(_parse_number(in));
if (num_str.empty()) {
return false;
}
@ -775,10 +907,8 @@ namespace picojson {
{
errno = 0;
intmax_t ival = strtoimax(num_str.c_str(), &endp, 10);
if (errno == 0
&& std::numeric_limits<int64_t>::min() <= ival
&& ival <= std::numeric_limits<int64_t>::max()
&& endp == num_str.c_str() + num_str.size()) {
if (errno == 0 && std::numeric_limits<int64_t>::min() <= ival && ival <= std::numeric_limits<int64_t>::max() &&
endp == num_str.c_str() + num_str.size()) {
ctx.set_int64(ival);
return true;
}
@ -799,19 +929,35 @@ namespace picojson {
class deny_parse_context {
public:
bool set_null() { return false; }
bool set_bool(bool) { return false; }
bool set_null() {
return false;
}
bool set_bool(bool) {
return false;
}
#ifdef PICOJSON_USE_INT64
bool set_int64(int64_t) { return false; }
bool set_int64(int64_t) {
return false;
}
#endif
bool set_number(double) { return false; }
template <typename Iter> bool parse_string(input<Iter>&) { return false; }
bool parse_array_start() { return false; }
bool set_number(double) {
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) {
return false;
}
bool parse_array_stop(size_t) { return false; }
bool parse_object_start() { return false; }
bool parse_array_stop(size_t) {
return false;
}
bool parse_object_start() {
return false;
}
template <typename Iter> bool parse_object_item(input<Iter> &, const std::string &) {
return false;
}
@ -820,8 +966,11 @@ namespace picojson {
class default_parse_context {
protected:
value *out_;
size_t depths_;
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() {
*out_ = value();
return true;
@ -845,56 +994,101 @@ namespace picojson {
return _parse_string(out_->get<std::string>(), in);
}
bool parse_array_start() {
if (depths_ == 0)
return false;
--depths_;
*out_ = value(array_type, false);
return true;
}
template <typename Iter> bool parse_array_item(input<Iter> &in, size_t) {
array &a = out_->get<array>();
a.push_back(value());
default_parse_context ctx(&a.back());
default_parse_context ctx(&a.back(), depths_);
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() {
if (depths_ == 0)
return false;
*out_ = value(object_type, false);
return true;
}
template <typename Iter> bool parse_object_item(input<Iter> &in, const std::string &key) {
object &o = out_->get<object>();
default_parse_context ctx(&o[key]);
default_parse_context ctx(&o[key], depths_);
return _parse(ctx, in);
}
bool parse_object_stop() {
++depths_;
return true;
}
private:
default_parse_context(const default_parse_context &);
default_parse_context &operator=(const default_parse_context &);
};
class null_parse_context {
protected:
size_t depths_;
public:
struct dummy_str {
void push_back(int) {}
void push_back(int) {
}
};
public:
null_parse_context() {}
bool set_null() { return true; }
bool set_bool(bool) { return true; }
null_parse_context(size_t depths = DEFAULT_MAX_DEPTHS) : depths_(depths) {
}
bool set_null() {
return true;
}
bool set_bool(bool) {
return true;
}
#ifdef PICOJSON_USE_INT64
bool set_int64(int64_t) { return true; }
bool set_int64(int64_t) {
return true;
}
#endif
bool set_number(double) { return true; }
bool set_number(double) {
return true;
}
template <typename Iter> bool parse_string(input<Iter> &in) {
dummy_str s;
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) {
return _parse(*this, in);
}
bool parse_array_stop(size_t) { return true; }
bool parse_object_start() { return true; }
bool parse_array_stop(size_t) {
++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 &) {
++depths_;
return _parse(*this, in);
}
bool parse_object_stop() {
return true;
}
private:
null_parse_context(const null_parse_context &);
null_parse_context &operator=(const null_parse_context &);
@ -918,7 +1112,7 @@ namespace picojson {
if (ch == -1 || ch == '\n') {
break;
} 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) {
std::string err;
parse(out, std::istreambuf_iterator<char>(is.rdbuf()),
std::istreambuf_iterator<char>(), &err);
parse(out, std::istreambuf_iterator<char>(is.rdbuf()), std::istreambuf_iterator<char>(), &err);
return err;
}
template <typename T> struct last_error_t {
static std::string s;
};
template <typename T> struct last_error_t { static std::string s; };
template <typename T> std::string last_error_t<T>::s;
inline void set_last_error(const std::string &s) {
@ -980,17 +1171,17 @@ namespace picojson {
}
}
#if !PICOJSON_USE_RVALUE_REFERENCE
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);
}
}
#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());
std::string err = picojson::parse(x, is);
const std::string err(picojson::parse(x, is));
if (!err.empty()) {
picojson::set_last_error(err);
is.setstate(std::ios::failbit);
@ -998,8 +1189,7 @@ inline std::istream& operator>>(std::istream& is, picojson::value& x)
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));
return os;
}

View File

@ -42,6 +42,7 @@ CheckOptions:
else()
target_include_directories(cppcheck-gui SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
endif()
target_include_directories(cppcheck-gui PRIVATE ${PROJECT_SOURCE_DIR}/externals/picojson/)
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
target_precompile_headers(cppcheck-gui PRIVATE precompiled.h)
endif()

View File

@ -94,6 +94,8 @@
#include <QVariant>
#include <Qt>
#include "json.h"
static const QString compile_commands_json("compile_commands.json");
static QString fromNativePath(const QString& p) {
@ -1005,25 +1007,31 @@ Settings MainWindow::getCppcheckSettings() {
addonFilePath.replace(QChar('\\'), QChar('/'));
// TODO: use picojson to generate the JSON
QString json;
json += "{ \"script\":\"" + addonFilePath + "\"";
picojson::object obj;
obj["script"] = picojson::value(addonFilePath.toStdString());
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());
if (!isCppcheckPremium() && addon == "misra" && !misraFile.isEmpty()) {
if (!misraFile.isEmpty()) {
QString arg;
if (misraFile.endsWith(".pdf", Qt::CaseInsensitive))
arg = "--misra-pdf=" + misraFile;
else
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.getAddonInfo(json.toStdString(), result.exename);
addonInfo.getAddonInfo(json_str, result.exename);
result.addonInfos.emplace_back(std::move(addonInfo));
result.addons.emplace(std::move(json_str));
}
if (isCppcheckPremium()) {

View File

@ -23,7 +23,6 @@
SUPPRESS_WARNING_PUSH("-Wfloat-equal")
SUPPRESS_WARNING_CLANG_PUSH("-Wtautological-type-limit-compare")
SUPPRESS_WARNING_GCC_PUSH("-Wparentheses")
SUPPRESS_WARNING_CLANG_PUSH("-Wextra-semi-stmt")
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_GCC_POP
SUPPRESS_WARNING_CLANG_POP
SUPPRESS_WARNING_POP