From 97f06cb20c1e136fd37d58fb40f57dd8f8a3a4a7 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Fri, 24 Apr 2020 02:56:05 +0300 Subject: [PATCH] Add string->number conversions --- json11.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/json11.cpp b/json11.cpp index 9f593a0..d60c84f 100644 --- a/json11.cpp +++ b/json11.cpp @@ -206,6 +206,9 @@ public: class JsonString final : public Value { const string &string_value() const override { return m_value; } + double number_value() const override { size_t pos = 0; double v = std::stod(m_value, &pos); if (pos < m_value.length()) { v = 0; } return v; } + int64_ int64_value() const override { size_t pos = 0; int64_ v = std::stoll(m_value, &pos); if (pos < m_value.length()) { v = 0; } return v; } + uint64_ uint64_value() const override { size_t pos = 0; uint64_ v = std::stoull(m_value, &pos); if (pos < m_value.length()) { v = 0; } return v; } public: explicit JsonString(const string &value) : Value(value) {} explicit JsonString(string &&value) : Value(move(value)) {}