summaryrefslogtreecommitdiff
path: root/zen/json.h
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2020-02-15 11:50:31 -0500
committerB Stack <bgstack15@gmail.com>2020-02-15 11:50:31 -0500
commit791b90b9898cc41869538f1dfc303588436682b7 (patch)
tree02cc7f817d95ce3f21207cbaba130e3d537fc1eb /zen/json.h
parentMerge branch '10.19' into 'master' (diff)
downloadFreeFileSync-791b90b9898cc41869538f1dfc303588436682b7.tar.gz
FreeFileSync-791b90b9898cc41869538f1dfc303588436682b7.tar.bz2
FreeFileSync-791b90b9898cc41869538f1dfc303588436682b7.zip
add upstream 10.20
It is worth noting that the send email feature is not present in the GPL release.
Diffstat (limited to 'zen/json.h')
-rw-r--r--zen/json.h32
1 files changed, 17 insertions, 15 deletions
diff --git a/zen/json.h b/zen/json.h
index e6464286..725874f7 100644
--- a/zen/json.h
+++ b/zen/json.h
@@ -27,16 +27,18 @@ struct JsonValue
};
explicit JsonValue() {}
- explicit JsonValue(Type t) : type(t) {}
- explicit JsonValue(bool b) : type(Type::boolean), primVal(b ? "true" : "false") {}
- explicit JsonValue(int64_t num) : type(Type::number), primVal(numberTo<std::string>(num)) {}
- explicit JsonValue(double num) : type(Type::number), primVal(numberTo<std::string>(num)) {}
- explicit JsonValue(const std::string& str) : type(Type::string), primVal(str) {}
+ explicit JsonValue(Type t) : type(t) {}
+ explicit JsonValue(bool b) : type(Type::boolean), primVal(b ? "true" : "false") {}
+ explicit JsonValue(int num) : type(Type::number), primVal(numberTo<std::string>(num)) {}
+ explicit JsonValue(int64_t num) : type(Type::number), primVal(numberTo<std::string>(num)) {}
+ explicit JsonValue(double num) : type(Type::number), primVal(numberTo<std::string>(num)) {}
+ explicit JsonValue(std::string str) : type(Type::string), primVal(std::move(str)) {} //unifying assignment
+ explicit JsonValue(const void*) = delete; //catch usage errors e.g. const char* -> JsonValue(bool)
Type type = Type::null;
- std::string primVal; //for primitive types
- std::map<std::string, std::unique_ptr<JsonValue>> objectVal; //"[...] most implementations of JSON libraries do not accept duplicate keys [...]" => fine!
- std::vector<std::unique_ptr<JsonValue>> arrayVal;
+ std::string primVal; //for primitive types
+ std::map<std::string, JsonValue> objectVal; //"[...] most implementations of JSON libraries do not accept duplicate keys [...]" => fine!
+ std::vector<JsonValue> arrayVal;
};
@@ -66,7 +68,7 @@ const JsonValue* getChildFromJsonObject(const JsonValue& jvalue, const std::stri
if (it == jvalue.objectVal.end())
return nullptr;
- return it->second.get();
+ return &it->second;
}
@@ -240,8 +242,8 @@ void serialize(const JsonValue& jval, std::string& stream,
stream += '"' + jsonEscape(childName) + "\":";
- if ((childValue->type == JsonValue::Type::object && !childValue->objectVal.empty()) ||
- (childValue->type == JsonValue::Type::array && !childValue->arrayVal .empty()))
+ if ((childValue.type == JsonValue::Type::object && !childValue.objectVal.empty()) ||
+ (childValue.type == JsonValue::Type::array && !childValue.arrayVal .empty()))
{
stream += lineBreak;
writeIndent(indentLevel + 1);
@@ -249,7 +251,7 @@ void serialize(const JsonValue& jval, std::string& stream,
else if (!indent.empty())
stream += ' ';
- serialize(*childValue, stream, lineBreak, indent, indentLevel + 1);
+ serialize(childValue, stream, lineBreak, indent, indentLevel + 1);
}
stream += lineBreak;
writeIndent(indentLevel);
@@ -263,7 +265,7 @@ void serialize(const JsonValue& jval, std::string& stream,
{
for (auto it = jval.arrayVal.begin(); it != jval.arrayVal.end(); ++it)
{
- const auto& childValue = **it;
+ const auto& childValue = *it;
if (it != jval.arrayVal.begin())
stream += ',';
@@ -462,7 +464,7 @@ private:
consumeToken(Token::Type::colon); //throw JsonParsingError
JsonValue value = parseValue(); //throw JsonParsingError
- jval.objectVal.emplace(std::move(name), std::make_unique<JsonValue>(std::move(value)));
+ jval.objectVal.emplace(std::move(name), std::move(value));
if (token().type != Token::Type::comma)
break;
@@ -482,7 +484,7 @@ private:
for (;;)
{
JsonValue value = parseValue(); //throw JsonParsingError
- jval.arrayVal.emplace_back(std::make_unique<JsonValue>(std::move(value)));
+ jval.arrayVal.emplace_back(std::move(value));
if (token().type != Token::Type::comma)
break;
bgstack15