2 Commits

Author SHA1 Message Date
fd37016cf8 Allow trailing comma 2023-02-23 01:15:28 +03:00
52a3af664f Fix compilation under clang 2022-01-15 23:38:58 +03:00

View File

@@ -41,10 +41,6 @@ using std::move;
* Serialization * Serialization
*/ */
static void dump(std::nullptr_t, string &out) {
out += "null";
}
static void dump(double value, string &out) { static void dump(double value, string &out) {
if (std::isfinite(value)) { if (std::isfinite(value)) {
char buf[32]; char buf[32];
@@ -55,10 +51,6 @@ static void dump(double value, string &out) {
} }
} }
static void dump(int value, string &out) {
out += std::to_string(value);
}
static void dump(int64_ value, string &out) { static void dump(int64_ value, string &out) {
out += std::to_string(value); out += std::to_string(value);
} }
@@ -169,7 +161,7 @@ protected:
}; };
class JsonDouble final : public Value<Json::NUMBER, double> { class JsonDouble final : public Value<Json::NUMBER, double> {
string as_string() const { return std::to_string(m_value); } string as_string() const override { return std::to_string(m_value); }
bool bool_value() const override { return m_value != 0; } bool bool_value() const override { return m_value != 0; }
double number_value() const override { return static_cast<double>(m_value); } double number_value() const override { return static_cast<double>(m_value); }
int64_ int64_value() const override { return static_cast<int64_>(m_value); } int64_ int64_value() const override { return static_cast<int64_>(m_value); }
@@ -181,7 +173,7 @@ public:
}; };
class JsonInt64 final : public Value<Json::NUMBER, int64_> { class JsonInt64 final : public Value<Json::NUMBER, int64_> {
string as_string() const { return std::to_string(m_value); } string as_string() const override { return std::to_string(m_value); }
bool bool_value() const override { return m_value != 0; } bool bool_value() const override { return m_value != 0; }
double number_value() const override { return static_cast<double>(m_value); } double number_value() const override { return static_cast<double>(m_value); }
int64_ int64_value() const override { return static_cast<int64_>(m_value); } int64_ int64_value() const override { return static_cast<int64_>(m_value); }
@@ -193,7 +185,7 @@ public:
}; };
class JsonUInt64 final : public Value<Json::NUMBER, uint64_> { class JsonUInt64 final : public Value<Json::NUMBER, uint64_> {
string as_string() const { return std::to_string(m_value); } string as_string() const override { return std::to_string(m_value); }
bool bool_value() const override { return m_value != 0; } bool bool_value() const override { return m_value != 0; }
double number_value() const override { return static_cast<double>(m_value); } double number_value() const override { return static_cast<double>(m_value); }
int64_ int64_value() const override { return static_cast<int64_>(m_value); } int64_ int64_value() const override { return static_cast<int64_>(m_value); }
@@ -211,7 +203,7 @@ public:
}; };
class JsonString final : public Value<Json::STRING, string> { class JsonString final : public Value<Json::STRING, string> {
string as_string() const { return m_value; } string as_string() const override { return m_value; }
const string &string_value() const override { return m_value; } const string &string_value() const override { return m_value; }
bool bool_value() const override { return m_value != "" && m_value != "0"; } bool bool_value() const override { return m_value != "" && m_value != "0"; }
double number_value() const override double number_value() const override
@@ -259,9 +251,23 @@ public:
explicit JsonObject(Json::object &&value) : Value(move(value)) {} explicit JsonObject(Json::object &&value) : Value(move(value)) {}
}; };
class JsonNull final : public Value<Json::NUL, std::nullptr_t> { class JsonNull final : public JsonValue {
public: public:
JsonNull() : Value(nullptr) {} JsonNull() {}
// Get type tag
Json::Type type() const override {
return Json::NUL;
}
// Comparisons - only within type
bool equals(const JsonValue * other) const override {
return true;
}
bool less(const JsonValue * other) const override {
return false;
}
void dump(string &out) const override {
out += "null";
}
}; };
/* * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * *
@@ -763,6 +769,8 @@ struct JsonParser final {
return fail("expected ',' in object, got " + esc(ch)); return fail("expected ',' in object, got " + esc(ch));
ch = get_next_token(); ch = get_next_token();
if (ch == '}')
break;
} }
return data; return data;
} }
@@ -786,6 +794,8 @@ struct JsonParser final {
return fail("expected ',' in list, got " + esc(ch)); return fail("expected ',' in list, got " + esc(ch));
ch = get_next_token(); ch = get_next_token();
if (ch == ']')
break;
(void)ch; (void)ch;
} }
return data; return data;