added brace wrapping after if and for
This commit is contained in:
@@ -12,13 +12,15 @@ namespace {
|
||||
inline bool ReadValue(const rapidjson::Value &object, const char *key,
|
||||
Type &out)
|
||||
{
|
||||
if (!object.HasMember(key)) {
|
||||
if (!object.HasMember(key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto &value = object[key];
|
||||
|
||||
if (!value.Is<Type>()) {
|
||||
if (!value.Is<Type>())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -31,13 +33,15 @@ namespace {
|
||||
inline bool ReadValue<QString>(const rapidjson::Value &object,
|
||||
const char *key, QString &out)
|
||||
{
|
||||
if (!object.HasMember(key)) {
|
||||
if (!object.HasMember(key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto &value = object[key];
|
||||
|
||||
if (!value.IsString()) {
|
||||
if (!value.IsString())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -51,18 +55,22 @@ namespace {
|
||||
const char *key,
|
||||
std::vector<QString> &out)
|
||||
{
|
||||
if (!object.HasMember(key)) {
|
||||
if (!object.HasMember(key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto &value = object[key];
|
||||
|
||||
if (!value.IsArray()) {
|
||||
if (!value.IsArray())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const rapidjson::Value &innerValue : value.GetArray()) {
|
||||
if (!innerValue.IsString()) {
|
||||
for (const rapidjson::Value &innerValue : value.GetArray())
|
||||
{
|
||||
if (!innerValue.IsString())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -76,141 +84,173 @@ namespace {
|
||||
inline bool ParseSingleCheermoteSet(JSONCheermoteSet &set,
|
||||
const rapidjson::Value &action)
|
||||
{
|
||||
if (!action.IsObject()) {
|
||||
if (!action.IsObject())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "prefix", set.prefix)) {
|
||||
if (!ReadValue(action, "prefix", set.prefix))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "scales", set.scales)) {
|
||||
if (!ReadValue(action, "scales", set.scales))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "backgrounds", set.backgrounds)) {
|
||||
if (!ReadValue(action, "backgrounds", set.backgrounds))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "states", set.states)) {
|
||||
if (!ReadValue(action, "states", set.states))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "type", set.type)) {
|
||||
if (!ReadValue(action, "type", set.type))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "updated_at", set.updatedAt)) {
|
||||
if (!ReadValue(action, "updated_at", set.updatedAt))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(action, "priority", set.priority)) {
|
||||
if (!ReadValue(action, "priority", set.priority))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Tiers
|
||||
if (!action.HasMember("tiers")) {
|
||||
if (!action.HasMember("tiers"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto &tiersValue = action["tiers"];
|
||||
|
||||
if (!tiersValue.IsArray()) {
|
||||
if (!tiersValue.IsArray())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const rapidjson::Value &tierValue : tiersValue.GetArray()) {
|
||||
for (const rapidjson::Value &tierValue : tiersValue.GetArray())
|
||||
{
|
||||
JSONCheermoteSet::CheermoteTier tier;
|
||||
|
||||
if (!tierValue.IsObject()) {
|
||||
if (!tierValue.IsObject())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(tierValue, "min_bits", tier.minBits)) {
|
||||
if (!ReadValue(tierValue, "min_bits", tier.minBits))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(tierValue, "id", tier.id)) {
|
||||
if (!ReadValue(tierValue, "id", tier.id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadValue(tierValue, "color", tier.color)) {
|
||||
if (!ReadValue(tierValue, "color", tier.color))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Images
|
||||
if (!tierValue.HasMember("images")) {
|
||||
if (!tierValue.HasMember("images"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto &imagesValue = tierValue["images"];
|
||||
|
||||
if (!imagesValue.IsObject()) {
|
||||
if (!imagesValue.IsObject())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read images object
|
||||
for (const auto &imageBackgroundValue : imagesValue.GetObject()) {
|
||||
for (const auto &imageBackgroundValue : imagesValue.GetObject())
|
||||
{
|
||||
QString background = imageBackgroundValue.name.GetString();
|
||||
bool backgroundExists = false;
|
||||
for (const auto &bg : set.backgrounds) {
|
||||
if (background == bg) {
|
||||
for (const auto &bg : set.backgrounds)
|
||||
{
|
||||
if (background == bg)
|
||||
{
|
||||
backgroundExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!backgroundExists) {
|
||||
if (!backgroundExists)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const rapidjson::Value &imageBackgroundStates =
|
||||
imageBackgroundValue.value;
|
||||
if (!imageBackgroundStates.IsObject()) {
|
||||
if (!imageBackgroundStates.IsObject())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Read each key which represents a background
|
||||
for (const auto &imageBackgroundState :
|
||||
imageBackgroundStates.GetObject()) {
|
||||
imageBackgroundStates.GetObject())
|
||||
{
|
||||
QString state = imageBackgroundState.name.GetString();
|
||||
bool stateExists = false;
|
||||
for (const auto &_state : set.states) {
|
||||
if (state == _state) {
|
||||
for (const auto &_state : set.states)
|
||||
{
|
||||
if (state == _state)
|
||||
{
|
||||
stateExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!stateExists) {
|
||||
if (!stateExists)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const rapidjson::Value &imageScalesValue =
|
||||
imageBackgroundState.value;
|
||||
if (!imageScalesValue.IsObject()) {
|
||||
if (!imageScalesValue.IsObject())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Read each key which represents a scale
|
||||
for (const auto &imageScaleValue :
|
||||
imageScalesValue.GetObject()) {
|
||||
imageScalesValue.GetObject())
|
||||
{
|
||||
QString scale = imageScaleValue.name.GetString();
|
||||
bool scaleExists = false;
|
||||
for (const auto &_scale : set.scales) {
|
||||
if (scale == _scale) {
|
||||
for (const auto &_scale : set.scales)
|
||||
{
|
||||
if (scale == _scale)
|
||||
{
|
||||
scaleExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!scaleExists) {
|
||||
if (!scaleExists)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const rapidjson::Value &imageScaleURLValue =
|
||||
imageScaleValue.value;
|
||||
if (!imageScaleURLValue.IsString()) {
|
||||
if (!imageScaleURLValue.IsString())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -218,7 +258,8 @@ namespace {
|
||||
|
||||
bool ok = false;
|
||||
qreal scaleNumber = scale.toFloat(&ok);
|
||||
if (!ok) {
|
||||
if (!ok)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -246,25 +287,30 @@ std::vector<JSONCheermoteSet> ParseCheermoteSets(const rapidjson::Document &d)
|
||||
{
|
||||
std::vector<JSONCheermoteSet> sets;
|
||||
|
||||
if (!d.IsObject()) {
|
||||
if (!d.IsObject())
|
||||
{
|
||||
return sets;
|
||||
}
|
||||
|
||||
if (!d.HasMember("actions")) {
|
||||
if (!d.HasMember("actions"))
|
||||
{
|
||||
return sets;
|
||||
}
|
||||
|
||||
const auto &actionsValue = d["actions"];
|
||||
|
||||
if (!actionsValue.IsArray()) {
|
||||
if (!actionsValue.IsArray())
|
||||
{
|
||||
return sets;
|
||||
}
|
||||
|
||||
for (const auto &action : actionsValue.GetArray()) {
|
||||
for (const auto &action : actionsValue.GetArray())
|
||||
{
|
||||
JSONCheermoteSet set;
|
||||
bool res = ParseSingleCheermoteSet(set, action);
|
||||
|
||||
if (res) {
|
||||
if (res)
|
||||
{
|
||||
sets.emplace_back(set);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user