mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-10-14 23:07:55 +02:00
Add public semantic error reporting
Closes open-source-parsers/jsoncpp#57
This commit is contained in:
@@ -830,6 +830,43 @@ std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
|
||||
return allErrors;
|
||||
}
|
||||
|
||||
bool Reader::pushError(const Value& value, const std::string& message) {
|
||||
if(value.getOffsetStart() > end_ - begin_
|
||||
|| value.getOffsetLimit() > end_ - begin_)
|
||||
return false;
|
||||
Token token;
|
||||
token.type_ = tokenError;
|
||||
token.start_ = begin_ + value.getOffsetStart();
|
||||
token.end_ = end_ + value.getOffsetLimit();
|
||||
ErrorInfo info;
|
||||
info.token_ = token;
|
||||
info.message_ = message;
|
||||
info.extra_ = 0;
|
||||
errors_.push_back(info);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Reader::pushError(const Value& value, const std::string& message, const Value& extra) {
|
||||
if(value.getOffsetStart() > end_ - begin_
|
||||
|| value.getOffsetLimit() > end_ - begin_
|
||||
|| extra.getOffsetLimit() > end_ - begin_)
|
||||
return false;
|
||||
Token token;
|
||||
token.type_ = tokenError;
|
||||
token.start_ = begin_ + value.getOffsetStart();
|
||||
token.end_ = begin_ + value.getOffsetLimit();
|
||||
ErrorInfo info;
|
||||
info.token_ = token;
|
||||
info.message_ = message;
|
||||
info.extra_ = begin_ + extra.getOffsetStart();
|
||||
errors_.push_back(info);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Reader::good() const {
|
||||
return !errors_.size();
|
||||
}
|
||||
|
||||
std::istream& operator>>(std::istream& sin, Value& root) {
|
||||
Json::Reader reader;
|
||||
bool ok = reader.parse(sin, root, true);
|
||||
|
Reference in New Issue
Block a user