From a387e2dec8083a6a43b3a26eb43ead86997296e4 Mon Sep 17 00:00:00 2001 From: Alex Fabijanic Date: Fri, 6 Oct 2017 09:33:31 -0500 Subject: [PATCH] pd_json.h is missing when installed via CMake in 1.8.0 #1923 --- JSON/include/Poco/JSON/ParserImpl.h | 19 +++++-------- JSON/src/ParserImpl.cpp | 44 +++++++++++++++++++---------- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/JSON/include/Poco/JSON/ParserImpl.h b/JSON/include/Poco/JSON/ParserImpl.h index 02d2d5f9a..e66ff3a2d 100644 --- a/JSON/include/Poco/JSON/ParserImpl.h +++ b/JSON/include/Poco/JSON/ParserImpl.h @@ -28,9 +28,9 @@ #include "Poco/UTF8Encoding.h" #include "Poco/Dynamic/Var.h" #include -extern "C" { -#include "pd_json.h" -} + + +struct json_stream; namespace Poco { @@ -96,6 +96,9 @@ protected: /// Returns the result of parsing as Dynamic::Var; private: + ParserImpl(const ParserImpl&); + ParserImpl& operator =(const ParserImpl&); + void handleArray(); void handleObject(); void handle(); @@ -103,7 +106,7 @@ private: void stripComments(std::string& json); bool checkError(); - json_stream _json; + json_stream* _pJSON; Handler::Ptr _pHandler; int _depth; char _decimalPoint; @@ -167,14 +170,6 @@ inline void ParserImpl::setHandlerImpl(const Handler::Ptr& pHandler) } -inline bool ParserImpl::checkError() -{ - const char* err = json_get_error(&_json); - if (err) throw Poco::JSON::JSONException(err); - return true; -} - - inline const Handler::Ptr& ParserImpl::getHandlerImpl() { return _pHandler; diff --git a/JSON/src/ParserImpl.cpp b/JSON/src/ParserImpl.cpp index 121d3b309..7e33e0040 100644 --- a/JSON/src/ParserImpl.cpp +++ b/JSON/src/ParserImpl.cpp @@ -26,6 +26,9 @@ #include #include #include +extern "C" { +#include "pd_json.h" +} namespace Poco { @@ -33,6 +36,7 @@ namespace JSON { ParserImpl::ParserImpl(const Handler::Ptr& pHandler, std::size_t bufSize): + _pJSON(new json_stream), _pHandler(pHandler), _depth(JSON_UNLIMITED_DEPTH), _decimalPoint('.'), @@ -44,6 +48,7 @@ ParserImpl::ParserImpl(const Handler::Ptr& pHandler, std::size_t bufSize): ParserImpl::~ParserImpl() { + delete _pJSON; } @@ -54,7 +59,7 @@ void ParserImpl::handle(const std::string& json) try { - json_open_buffer(&_json, json.data(), json.size()); + json_open_buffer(_pJSON, json.data(), json.size()); checkError(); ////////////////////////////////// // Underlying parser is capable of parsing multiple consecutive JSONs; @@ -62,16 +67,16 @@ void ParserImpl::handle(const std::string& json) // excessive characters past valid JSON end, this MUST be called // AFTER opening the buffer - otherwise it is overwritten by // json_open*() call, which calls internal init() - json_set_streaming(&_json, false); + json_set_streaming(_pJSON, false); ///////////////////////////////// handle(); checkError(); - if (JSON_DONE != json_next(&_json)) + if (JSON_DONE != json_next(_pJSON)) throw JSONException("Excess characters found after JSON end."); - json_close(&_json); + json_close(_pJSON); } catch (std::exception&) { - json_close(&_json); + json_close(_pJSON); throw; } } @@ -135,11 +140,11 @@ void ParserImpl::stripComments(std::string& json) void ParserImpl::handleArray() { - json_type tok = json_peek(&_json); + json_type tok = json_peek(_pJSON); while (tok != JSON_ARRAY_END && checkError()) { handle(); - tok = json_peek(&_json); + tok = json_peek(_pJSON); } if (tok == JSON_ARRAY_END) handle(); @@ -149,13 +154,13 @@ void ParserImpl::handleArray() void ParserImpl::handleObject() { - json_type tok = json_peek(&_json); + json_type tok = json_peek(_pJSON); while (tok != JSON_OBJECT_END && checkError()) { - json_next(&_json); - if (_pHandler) _pHandler->key(std::string(json_get_string(&_json, NULL))); + json_next(_pJSON); + if (_pHandler) _pHandler->key(std::string(json_get_string(_pJSON, NULL))); handle(); - tok = json_peek(&_json); + tok = json_peek(_pJSON); } if (tok == JSON_OBJECT_END) handle(); @@ -165,7 +170,7 @@ void ParserImpl::handleObject() void ParserImpl::handle() { - enum json_type type = json_next(&_json); + enum json_type type = json_next(_pJSON); switch (type) { case JSON_DONE: @@ -183,7 +188,7 @@ void ParserImpl::handle() { if (_pHandler) { - std::string str(json_get_string(&_json, NULL)); + std::string str(json_get_string(_pJSON, NULL)); if (str.find(_decimalPoint) != str.npos || str.find('e') != str.npos || str.find('E') != str.npos) { _pHandler->value(NumberParser::parseFloat(str)); @@ -200,7 +205,7 @@ void ParserImpl::handle() break; } case JSON_STRING: - if (_pHandler) _pHandler->value(std::string(json_get_string(&_json, NULL))); + if (_pHandler) _pHandler->value(std::string(json_get_string(_pJSON, NULL))); break; case JSON_OBJECT: if (_pHandler) _pHandler->startObject(); @@ -218,7 +223,7 @@ void ParserImpl::handle() return; case JSON_ERROR: { - const char* pErr = json_get_error(&_json); + const char* pErr = json_get_error(_pJSON); std::string err(pErr ? pErr : "JSON parser error."); throw JSONException(err); } @@ -226,4 +231,13 @@ void ParserImpl::handle() } +bool ParserImpl::checkError() +{ + const char* err = json_get_error(_pJSON); + if (err) throw Poco::JSON::JSONException(err); + return true; +} + + + } } // namespace Poco::JSON