pd_json.h is missing when installed via CMake in 1.8.0 #1923

This commit is contained in:
Alex Fabijanic 2017-10-06 09:22:55 -05:00
parent 210bc6d30c
commit 7943d95b31
2 changed files with 32 additions and 25 deletions

View File

@ -28,9 +28,10 @@
#include "Poco/UTF8Encoding.h"
#include "Poco/Dynamic/Var.h"
#include <string>
#include "pd_json.h"
struct json_stream;
namespace Poco {
namespace JSON {
@ -94,6 +95,9 @@ protected:
/// Returns the result of parsing as Dynamic::Var;
private:
ParserImpl(const ParserImpl&);
ParserImpl& operator =(const ParserImpl&);
void handleArray();
void handleObject();
void handle();
@ -101,7 +105,7 @@ private:
void stripComments(std::string& json);
bool checkError();
json_stream _json;
json_stream* _pJSON;
Handler::Ptr _pHandler;
int _depth;
char _decimalPoint;
@ -165,14 +169,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;

View File

@ -26,6 +26,7 @@
#include <limits>
#include <clocale>
#include <istream>
#include "pd_json.h"
namespace Poco {
@ -33,6 +34,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 +46,7 @@ ParserImpl::ParserImpl(const Handler::Ptr& pHandler, std::size_t bufSize):
ParserImpl::~ParserImpl()
{
delete _pJSON;
}
@ -54,7 +57,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 +65,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 +138,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 +152,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 +168,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 +186,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 +203,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 +221,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 +229,12 @@ 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