From 6c9408d12848773d74fb2c5879dab04851ddd901 Mon Sep 17 00:00:00 2001 From: dota17 <50514813+dota17@users.noreply.github.com> Date: Thu, 24 Oct 2019 06:31:25 +0800 Subject: [PATCH] remove pushError in CharReader (#1055) --- src/lib_json/json_reader.cpp | 39 ------------------------------------ src/test_lib_json/main.cpp | 29 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 39 deletions(-) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 4d4f89b..38aab78 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -895,9 +895,6 @@ public: bool collectComments = true); String getFormattedErrorMessages() const; std::vector 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::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_; diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index 950e92e..1d636d8 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -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) {