NOISSUE sanitize Json

Removes magical parameter madness.
All require* can throw
All ensure* need a default value and never throw
This commit is contained in:
Petr Mrázek
2015-06-03 21:57:22 +02:00
parent dde35a0eb8
commit 24db645167
6 changed files with 129 additions and 117 deletions

View File

@@ -39,15 +39,15 @@ RawLibraryPtr RawLibrary::fromJson(const QJsonObject &libObj, const QString &fil
if (libObj.contains("extract"))
{
out->applyExcludes = true;
auto extractObj = ensureObject(libObj.value("extract"));
for (auto excludeVal : ensureArray(extractObj.value("exclude")))
auto extractObj = requireObject(libObj.value("extract"));
for (auto excludeVal : requireArray(extractObj.value("exclude")))
{
out->extract_excludes.append(ensureString(excludeVal));
out->extract_excludes.append(requireString(excludeVal));
}
}
if (libObj.contains("natives"))
{
QJsonObject nativesObj = ensureObject(libObj.value("natives"));
QJsonObject nativesObj = requireObject(libObj.value("natives"));
for (auto it = nativesObj.begin(); it != nativesObj.end(); ++it)
{
if (!it.value().isString())
@@ -127,7 +127,7 @@ RawLibraryPtr RawLibrary::fromJsonPlus(const QJsonObject &libObj, const QString
}
if (libObj.contains("MMC-depend"))
{
const QString dependString = ensureString(libObj.value("MMC-depend"));
const QString dependString = requireString(libObj.value("MMC-depend"));
if (dependString == "hard")
{
lib->dependType = RawLibrary::Hard;