open-source-parsers / open-source-parsers/jsoncpp
some question about charReader
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 8.9k
- Forks
- 2.7k
- Avg merge
- 31m
- Merged PRs (30d)
- 1
Description
When I write testcases in #1095, I find some problems:
1. comment
I find the comments can be inserted anywhere except the place after the key value of an object. for example:
the input is:
char const doc[] = "//comment1\n [ //comment2\n \"value\" //comment3\n,"
" //comment4\n true //comment5\n ] //comment6\n";
char const doc[] = "//comment1\n { //comment2\n \"property\" :"
" \"value\" //comment3\n } //comment4\n";
after parse the doc, then print root[0], we get:
//comment2
"value" //comment3
Is this an ideal result? we should update the Wiki and tell the user what should be concerned when they add the comments.
2. Value::LargestUInt(Value::maxLargestInt) (9223372036854775807 )
if (isNegative) {
// We use the same magnitude assumption here, just in case.
const Value::UInt last_digit = static_cast<Value::UInt>(value % 10);
decoded = -Value::LargestInt(value / 10) * 10 - last_digit;
} else if (value <= Value::LargestUInt(Value::maxLargestInt)) {
decoded = Value::LargestInt(value);
} else {
decoded = value;
}
return true;
}
In order to cover this line, we add the testcase:
{
char const doc[] = "[9223372036854775808]";
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
JSONTEST_ASSERT(ok);
JSONTEST_ASSERT(errs.empty());
JSONTEST_ASSERT_EQUAL(9223372036854775808, root[0]);
}
and get the error message:
FAILED: jsoncpp_test@exe/src_test_lib_json_main.cpp.o
c++ -Ijsoncpp_test@exe -I. -I.. -I../include -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -std=c++11 -g -MD -MQ 'jsoncpp_test@exe/src_test_lib_json_main.cpp.o' -MF 'jsoncpp_test@exe/src_test_lib_json_main.cpp.o.d' -o 'jsoncpp_test@exe/src_test_lib_json_main.cpp.o' -c ../src/test_lib_json/main.cpp
../src/test_lib_json/main.cpp:2861:55: warning: integer constant is so large that it is unsigned
JSONTEST_ASSERT_EQUAL(9223372036854775808, root[0]);
^
In file included from ../src/test_lib_json/main.cpp:14:0:
../src/test_lib_json/jsontest.h: In instantiation of ‘JsonTest::TestResult& JsonTest::checkEqual(JsonTest::TestResult&, T, U, const char*, unsigned int, const char*) [with T = __int128; U = Json::Value]’:
../src/test_lib_json/main.cpp:2861:5: required from here
../src/test_lib_json/jsontest.h:178:7: error: call of overloaded ‘Value(__int128&)’ is ambiguous
Is this a bug? How can we remove this error?
3 some redundant code
while (current != end) {
Char c = *current++;
if (c == '"') {
break;
} else if (c == '\\') {
if (current == end)
return addError("Empty escape sequence in string", token, current);
Char escape = *current++;
switch (escape) {
I think we can never get this line:
https://github.com/open-source-parsers/jsoncpp/blob/d2e6a971f4544c55b8e3b25cf96db266971b778f/src/lib_json/json_reader.cpp#L1657
and this line:
https://github.com/open-source-parsers/jsoncpp/blob/d2e6a971f4544c55b8e3b25cf96db266971b778f/src/lib_json/json_reader.cpp#L1660
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the comment and number parsing paths in src/lib_json/json_reader.cpp, then inspect the related cases in src/test_lib_json/main.cpp and the assertion helper in src/test_lib_json/jsontest.h. Reproduce the comment behavior and large-integer test result, and verify the two string-parser branches identified by their source links. Done means the questions are resolved with focused tests or documentation updates where appropriate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100