2018-06-26 14:09:39 +02:00
|
|
|
#include "util/RapidjsonHelpers.hpp"
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2018-05-13 17:51:01 +02:00
|
|
|
#include <rapidjson/prettywriter.h>
|
|
|
|
|
2018-04-15 15:09:31 +02:00
|
|
|
namespace chatterino {
|
|
|
|
namespace rj {
|
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
void addMember(rapidjson::Value &obj, const char *key,
|
|
|
|
rapidjson::Value &&value,
|
|
|
|
rapidjson::Document::AllocatorType &a)
|
|
|
|
{
|
|
|
|
obj.AddMember(rapidjson::Value(key, a).Move(), value, a);
|
|
|
|
}
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
void addMember(rapidjson::Value &obj, const char *key,
|
|
|
|
rapidjson::Value &value,
|
|
|
|
rapidjson::Document::AllocatorType &a)
|
|
|
|
{
|
|
|
|
obj.AddMember(rapidjson::Value(key, a).Move(), value.Move(), a);
|
|
|
|
}
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2021-07-18 14:37:53 +02:00
|
|
|
QString stringify(const rapidjson::Value &value)
|
2018-08-15 22:46:20 +02:00
|
|
|
{
|
|
|
|
rapidjson::StringBuffer buffer;
|
|
|
|
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
|
|
|
value.Accept(writer);
|
2018-05-13 17:51:01 +02:00
|
|
|
|
2021-07-18 14:37:53 +02:00
|
|
|
return buffer.GetString();
|
2018-08-15 22:46:20 +02:00
|
|
|
}
|
2018-05-13 17:51:01 +02:00
|
|
|
|
2020-08-08 15:37:22 +02:00
|
|
|
bool getSafeObject(rapidjson::Value &obj, const char *key,
|
|
|
|
rapidjson::Value &out)
|
|
|
|
{
|
|
|
|
if (!checkJsonValue(obj, key))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
out = obj[key].Move();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool checkJsonValue(const rapidjson::Value &obj, const char *key)
|
|
|
|
{
|
|
|
|
return obj.IsObject() && !obj.IsNull() && obj.HasMember(key);
|
|
|
|
}
|
|
|
|
|
2018-04-15 15:09:31 +02:00
|
|
|
} // namespace rj
|
|
|
|
} // namespace chatterino
|