Skip to content

Commit 6c9408d

Browse files
dota17baylesj
authored andcommitted
remove pushError in CharReader (open-source-parsers#1055)
1 parent 54bd178 commit 6c9408d

File tree

2 files changed

+29
-39
lines changed

2 files changed

+29
-39
lines changed

src/lib_json/json_reader.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -895,9 +895,6 @@ class OurReader {
895895
bool collectComments = true);
896896
String getFormattedErrorMessages() const;
897897
std::vector<StructuredError> getStructuredErrors() const;
898-
bool pushError(const Value& value, const String& message);
899-
bool pushError(const Value& value, const String& message, const Value& extra);
900-
bool good() const;
901898

902899
private:
903900
OurReader(OurReader const&); // no impl
@@ -1841,42 +1838,6 @@ std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
18411838
return allErrors;
18421839
}
18431840

1844-
bool OurReader::pushError(const Value& value, const String& message) {
1845-
ptrdiff_t length = end_ - begin_;
1846-
if (value.getOffsetStart() > length || value.getOffsetLimit() > length)
1847-
return false;
1848-
Token token;
1849-
token.type_ = tokenError;
1850-
token.start_ = begin_ + value.getOffsetStart();
1851-
token.end_ = begin_ + value.getOffsetLimit();
1852-
ErrorInfo info;
1853-
info.token_ = token;
1854-
info.message_ = message;
1855-
info.extra_ = nullptr;
1856-
errors_.push_back(info);
1857-
return true;
1858-
}
1859-
1860-
bool OurReader::pushError(const Value& value, const String& message,
1861-
const Value& extra) {
1862-
ptrdiff_t length = end_ - begin_;
1863-
if (value.getOffsetStart() > length || value.getOffsetLimit() > length ||
1864-
extra.getOffsetLimit() > length)
1865-
return false;
1866-
Token token;
1867-
token.type_ = tokenError;
1868-
token.start_ = begin_ + value.getOffsetStart();
1869-
token.end_ = begin_ + value.getOffsetLimit();
1870-
ErrorInfo info;
1871-
info.token_ = token;
1872-
info.message_ = message;
1873-
info.extra_ = begin_ + extra.getOffsetStart();
1874-
errors_.push_back(info);
1875-
return true;
1876-
}
1877-
1878-
bool OurReader::good() const { return errors_.empty(); }
1879-
18801841
class OurCharReader : public CharReader {
18811842
bool const collectComments_;
18821843
OurReader reader_;

src/test_lib_json/main.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,6 +2644,35 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, parseWithDetailError) {
26442644
JSONTEST_ASSERT(errors.at(0).message == "Bad escape sequence in string");
26452645
}
26462646

2647+
JSONTEST_FIXTURE_LOCAL(ReaderTest, pushErrorTest) {
2648+
Json::Reader reader;
2649+
Json::Value root;
2650+
{
2651+
bool ok = reader.parse("{ \"AUTHOR\" : 123 }", root);
2652+
JSONTEST_ASSERT(ok);
2653+
if (!root["AUTHOR"].isString()) {
2654+
ok = reader.pushError(root["AUTHOR"], "AUTHOR must be a string");
2655+
}
2656+
JSONTEST_ASSERT(ok);
2657+
JSONTEST_ASSERT(reader.getFormattedErrorMessages() ==
2658+
"* Line 1, Column 14\n"
2659+
" AUTHOR must be a string\n");
2660+
}
2661+
{
2662+
bool ok = reader.parse("{ \"AUTHOR\" : 123 }", root);
2663+
JSONTEST_ASSERT(ok);
2664+
if (!root["AUTHOR"].isString()) {
2665+
ok = reader.pushError(root["AUTHOR"], "AUTHOR must be a string",
2666+
root["AUTHOR"]);
2667+
}
2668+
JSONTEST_ASSERT(ok);
2669+
JSONTEST_ASSERT(reader.getFormattedErrorMessages() ==
2670+
"* Line 1, Column 14\n"
2671+
" AUTHOR must be a string\n"
2672+
"See Line 1, Column 14 for detail.\n");
2673+
}
2674+
}
2675+
26472676
struct CharReaderTest : JsonTest::TestCase {};
26482677

26492678
JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithNoErrors) {

0 commit comments

Comments
 (0)