handle yajl 2.1.0 API changes

This commit is contained in:
Michael Davidsaver
2017-10-31 17:45:40 -05:00
parent e247a2c4eb
commit 51cbe538e8
5 changed files with 79 additions and 25 deletions

View File

@@ -15,7 +15,7 @@
namespace {
void check_trailing(const std::string& line, bool commentok)
void check_trailing(const std::string& line)
{
size_t idx = line.find_first_not_of(" \t\n\r");
if(idx==line.npos) return;
@@ -29,37 +29,46 @@ void check_trailing(const std::string& line, bool commentok)
namespace epics{namespace pvData{
bool yajl_parse_helper(std::istream& src,
yajl_handle handle,
const yajl_parser_config& config)
yajl_handle handle)
{
unsigned linenum=0;
#ifndef EPICS_YAJL_VERSION
bool done = false;
#endif
std::string line;
while(std::getline(src, line)) {
linenum++;
#ifndef EPICS_YAJL_VERSION
if(done) {
check_trailing(line, config.allowComments);
check_trailing(line);
continue;
}
#endif
yajl_status sts = yajl_parse(handle, (const unsigned char*)line.c_str(), line.size());
switch(sts) {
case yajl_status_ok: {
size_t consumed = yajl_get_bytes_consumed(handle);
if(consumed<line.size()) {
check_trailing(line.substr(consumed), config.allowComments);
check_trailing(line.substr(consumed));
}
#ifndef EPICS_YAJL_VERSION
done = true;
#endif
break;
}
case yajl_status_client_canceled:
return false;
#ifndef EPICS_YAJL_VERSION
case yajl_status_insufficient_data:
// continue with next line
break;
#endif
case yajl_status_error:
{
std::ostringstream msg;
@@ -85,15 +94,24 @@ bool yajl_parse_helper(std::istream& src,
msg<<"I/O error after line "<<linenum;
throw std::runtime_error(msg.str());
} else if(!done) switch(yajl_parse_complete(handle)) {
case yajl_status_ok:
break;
case yajl_status_client_canceled:
return false;
case yajl_status_insufficient_data:
throw std::runtime_error("unexpected end of input");
case yajl_status_error:
throw std::runtime_error("Error while completing parsing");
#ifndef EPICS_YAJL_VERSION
} else if(!done) {
switch(yajl_parse_complete(handle)) {
#else
} else {
switch(yajl_complete_parse(handle)) {
#endif
case yajl_status_ok:
break;
case yajl_status_client_canceled:
return false;
#ifndef EPICS_YAJL_VERSION
case yajl_status_insufficient_data:
throw std::runtime_error("unexpected end of input");
#endif
case yajl_status_error:
throw std::runtime_error("Error while completing parsing");
}
}
return true;