mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-24 17:30:44 +02:00
pd_json.h is missing when installed via CMake in 1.8.0 #1923
This commit is contained in:
@@ -28,9 +28,10 @@
|
|||||||
#include "Poco/UTF8Encoding.h"
|
#include "Poco/UTF8Encoding.h"
|
||||||
#include "Poco/Dynamic/Var.h"
|
#include "Poco/Dynamic/Var.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "pd_json.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
struct json_stream;
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
namespace JSON {
|
namespace JSON {
|
||||||
|
|
||||||
@@ -94,6 +95,9 @@ protected:
|
|||||||
/// Returns the result of parsing as Dynamic::Var;
|
/// Returns the result of parsing as Dynamic::Var;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
ParserImpl(const ParserImpl&);
|
||||||
|
ParserImpl& operator =(const ParserImpl&);
|
||||||
|
|
||||||
void handleArray();
|
void handleArray();
|
||||||
void handleObject();
|
void handleObject();
|
||||||
void handle();
|
void handle();
|
||||||
@@ -101,7 +105,7 @@ private:
|
|||||||
void stripComments(std::string& json);
|
void stripComments(std::string& json);
|
||||||
bool checkError();
|
bool checkError();
|
||||||
|
|
||||||
json_stream _json;
|
json_stream* _pJSON;
|
||||||
Handler::Ptr _pHandler;
|
Handler::Ptr _pHandler;
|
||||||
int _depth;
|
int _depth;
|
||||||
char _decimalPoint;
|
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()
|
inline const Handler::Ptr& ParserImpl::getHandlerImpl()
|
||||||
{
|
{
|
||||||
return _pHandler;
|
return _pHandler;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <clocale>
|
#include <clocale>
|
||||||
#include <istream>
|
#include <istream>
|
||||||
|
#include "pd_json.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
@@ -33,6 +34,7 @@ namespace JSON {
|
|||||||
|
|
||||||
|
|
||||||
ParserImpl::ParserImpl(const Handler::Ptr& pHandler, std::size_t bufSize):
|
ParserImpl::ParserImpl(const Handler::Ptr& pHandler, std::size_t bufSize):
|
||||||
|
_pJSON(new json_stream),
|
||||||
_pHandler(pHandler),
|
_pHandler(pHandler),
|
||||||
_depth(JSON_UNLIMITED_DEPTH),
|
_depth(JSON_UNLIMITED_DEPTH),
|
||||||
_decimalPoint('.'),
|
_decimalPoint('.'),
|
||||||
@@ -44,6 +46,7 @@ ParserImpl::ParserImpl(const Handler::Ptr& pHandler, std::size_t bufSize):
|
|||||||
|
|
||||||
ParserImpl::~ParserImpl()
|
ParserImpl::~ParserImpl()
|
||||||
{
|
{
|
||||||
|
delete _pJSON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -54,7 +57,7 @@ void ParserImpl::handle(const std::string& json)
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
json_open_buffer(&_json, json.data(), json.size());
|
json_open_buffer(_pJSON, json.data(), json.size());
|
||||||
checkError();
|
checkError();
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
// Underlying parser is capable of parsing multiple consecutive JSONs;
|
// 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
|
// excessive characters past valid JSON end, this MUST be called
|
||||||
// AFTER opening the buffer - otherwise it is overwritten by
|
// AFTER opening the buffer - otherwise it is overwritten by
|
||||||
// json_open*() call, which calls internal init()
|
// json_open*() call, which calls internal init()
|
||||||
json_set_streaming(&_json, false);
|
json_set_streaming(_pJSON, false);
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
handle(); checkError();
|
handle(); checkError();
|
||||||
if (JSON_DONE != json_next(&_json))
|
if (JSON_DONE != json_next(_pJSON))
|
||||||
throw JSONException("Excess characters found after JSON end.");
|
throw JSONException("Excess characters found after JSON end.");
|
||||||
json_close(&_json);
|
json_close(_pJSON);
|
||||||
}
|
}
|
||||||
catch (std::exception&)
|
catch (std::exception&)
|
||||||
{
|
{
|
||||||
json_close(&_json);
|
json_close(_pJSON);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,11 +138,11 @@ void ParserImpl::stripComments(std::string& json)
|
|||||||
|
|
||||||
void ParserImpl::handleArray()
|
void ParserImpl::handleArray()
|
||||||
{
|
{
|
||||||
json_type tok = json_peek(&_json);
|
json_type tok = json_peek(_pJSON);
|
||||||
while (tok != JSON_ARRAY_END && checkError())
|
while (tok != JSON_ARRAY_END && checkError())
|
||||||
{
|
{
|
||||||
handle();
|
handle();
|
||||||
tok = json_peek(&_json);
|
tok = json_peek(_pJSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tok == JSON_ARRAY_END) handle();
|
if (tok == JSON_ARRAY_END) handle();
|
||||||
@@ -149,13 +152,13 @@ void ParserImpl::handleArray()
|
|||||||
|
|
||||||
void ParserImpl::handleObject()
|
void ParserImpl::handleObject()
|
||||||
{
|
{
|
||||||
json_type tok = json_peek(&_json);
|
json_type tok = json_peek(_pJSON);
|
||||||
while (tok != JSON_OBJECT_END && checkError())
|
while (tok != JSON_OBJECT_END && checkError())
|
||||||
{
|
{
|
||||||
json_next(&_json);
|
json_next(_pJSON);
|
||||||
if (_pHandler) _pHandler->key(std::string(json_get_string(&_json, NULL)));
|
if (_pHandler) _pHandler->key(std::string(json_get_string(_pJSON, NULL)));
|
||||||
handle();
|
handle();
|
||||||
tok = json_peek(&_json);
|
tok = json_peek(_pJSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tok == JSON_OBJECT_END) handle();
|
if (tok == JSON_OBJECT_END) handle();
|
||||||
@@ -165,7 +168,7 @@ void ParserImpl::handleObject()
|
|||||||
|
|
||||||
void ParserImpl::handle()
|
void ParserImpl::handle()
|
||||||
{
|
{
|
||||||
enum json_type type = json_next(&_json);
|
enum json_type type = json_next(_pJSON);
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case JSON_DONE:
|
case JSON_DONE:
|
||||||
@@ -183,7 +186,7 @@ void ParserImpl::handle()
|
|||||||
{
|
{
|
||||||
if (_pHandler)
|
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)
|
if (str.find(_decimalPoint) != str.npos || str.find('e') != str.npos || str.find('E') != str.npos)
|
||||||
{
|
{
|
||||||
_pHandler->value(NumberParser::parseFloat(str));
|
_pHandler->value(NumberParser::parseFloat(str));
|
||||||
@@ -200,7 +203,7 @@ void ParserImpl::handle()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case JSON_STRING:
|
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;
|
break;
|
||||||
case JSON_OBJECT:
|
case JSON_OBJECT:
|
||||||
if (_pHandler) _pHandler->startObject();
|
if (_pHandler) _pHandler->startObject();
|
||||||
@@ -218,7 +221,7 @@ void ParserImpl::handle()
|
|||||||
return;
|
return;
|
||||||
case JSON_ERROR:
|
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.");
|
std::string err(pErr ? pErr : "JSON parser error.");
|
||||||
throw JSONException(err);
|
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
|
} } // namespace Poco::JSON
|
||||||
|
|||||||
Reference in New Issue
Block a user