mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-03-03 12:58:02 +01:00
remove pushError in CharReader (#1055)
This commit is contained in:
parent
54bd178bd8
commit
6c9408d128
@ -895,9 +895,6 @@ public:
|
||||
bool collectComments = true);
|
||||
String getFormattedErrorMessages() const;
|
||||
std::vector<StructuredError> getStructuredErrors() const;
|
||||
bool pushError(const Value& value, const String& message);
|
||||
bool pushError(const Value& value, const String& message, const Value& extra);
|
||||
bool good() const;
|
||||
|
||||
private:
|
||||
OurReader(OurReader const&); // no impl
|
||||
@ -1841,42 +1838,6 @@ std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
|
||||
return allErrors;
|
||||
}
|
||||
|
||||
bool OurReader::pushError(const Value& value, const String& message) {
|
||||
ptrdiff_t length = end_ - begin_;
|
||||
if (value.getOffsetStart() > length || value.getOffsetLimit() > length)
|
||||
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_ = nullptr;
|
||||
errors_.push_back(info);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OurReader::pushError(const Value& value, const String& message,
|
||||
const Value& extra) {
|
||||
ptrdiff_t length = end_ - begin_;
|
||||
if (value.getOffsetStart() > length || value.getOffsetLimit() > length ||
|
||||
extra.getOffsetLimit() > length)
|
||||
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 OurReader::good() const { return errors_.empty(); }
|
||||
|
||||
class OurCharReader : public CharReader {
|
||||
bool const collectComments_;
|
||||
OurReader reader_;
|
||||
|
@ -2644,6 +2644,35 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseWithDetailError) {
|
||||
JSONTEST_ASSERT(errors.at(0).message == "Bad escape sequence in string");
|
||||
}
|
||||
|
||||
JSONTEST_FIXTURE_LOCAL(ReaderTest, pushErrorTest) {
|
||||
Json::Reader reader;
|
||||
Json::Value root;
|
||||
{
|
||||
bool ok = reader.parse("{ \"AUTHOR\" : 123 }", root);
|
||||
JSONTEST_ASSERT(ok);
|
||||
if (!root["AUTHOR"].isString()) {
|
||||
ok = reader.pushError(root["AUTHOR"], "AUTHOR must be a string");
|
||||
}
|
||||
JSONTEST_ASSERT(ok);
|
||||
JSONTEST_ASSERT(reader.getFormattedErrorMessages() ==
|
||||
"* Line 1, Column 14\n"
|
||||
" AUTHOR must be a string\n");
|
||||
}
|
||||
{
|
||||
bool ok = reader.parse("{ \"AUTHOR\" : 123 }", root);
|
||||
JSONTEST_ASSERT(ok);
|
||||
if (!root["AUTHOR"].isString()) {
|
||||
ok = reader.pushError(root["AUTHOR"], "AUTHOR must be a string",
|
||||
root["AUTHOR"]);
|
||||
}
|
||||
JSONTEST_ASSERT(ok);
|
||||
JSONTEST_ASSERT(reader.getFormattedErrorMessages() ==
|
||||
"* Line 1, Column 14\n"
|
||||
" AUTHOR must be a string\n"
|
||||
"See Line 1, Column 14 for detail.\n");
|
||||
}
|
||||
}
|
||||
|
||||
struct CharReaderTest : JsonTest::TestCase {};
|
||||
|
||||
JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithNoErrors) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user