Skip to content

Commit 9229a9c

Browse files
committed
fix typo
1 parent e87b86c commit 9229a9c

File tree

6 files changed

+81
-79
lines changed

6 files changed

+81
-79
lines changed

example/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
***NOTE***
22

33
If you get linker errors about undefined references to symbols that involve types in the `std::__cxx11` namespace or the tag
4-
`[abi:cxx11]` then it probably indicates that you are trying to link together object files that were compiles with different
4+
`[abi:cxx11]` then it probably indicates that you are trying to link together object files that were compiled with different
55
values for the _GLIBCXX_USE_CXX11_ABI marco. This commonly happens when linking to a third-party library that was compiled with
6-
an older version of GCC. If the third-party library cannot be rebuilt with the new ABI then you need to recompole your code with
7-
the old ABI,just like :
6+
an older version of GCC. If the third-party library cannot be rebuilt with the new ABI, then you need to recompile your code with
7+
the old ABI,just like:
88
**g++ stringWrite.cpp -ljsoncpp -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0 -o stringWrite**
99

10-
Not all of uses of the new ABI will cause changes in symbol names,for example a class with a `std::string` member variable will
11-
have the same mangled bane whether compiled with the older or new ABI. In order to detect such problems the new types and functions
12-
asre annotated with the abi_tag attribute,allowing the compiler to warn about potential ABI incompatibilities in code using them.
13-
Those warnings can be enabled with the `-Wabi-tag` option.
10+
Not all of uses of the new ABI will cause changes in symbol names, for example a class with a `std::string` member variable will
11+
have the same mangled name whether compiled with the older or new ABI. In order to detect such problems, the new types and functions
12+
are annotated with the abi_tag attribute, allowing the compiler to warn about potential ABI incompatibilities in code using them.
13+
Those warnings can be enabled with the `-Wabi-tag` option.

example/readFromStream/readFromStream.cpp

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
#include "json/json.h"
22
#include <fstream>
33
#include <iostream>
4-
/*
5-
parse from stream,collect comments and capture error info.
6-
7-
$g++ readFromStream.cpp -ljsoncpp -std=c++11 -o readFromStream
8-
$./readFromStream
9-
// comment head
10-
{
11-
// comment before
12-
"key" : "value"
13-
}
14-
// comment after
15-
// comment tail
16-
*/
4+
/** \brief Parse from stream, collect comments and capture error info.
5+
* Example Usage:
6+
* $g++ readFromStream.cpp -ljsoncpp -std=c++11 -o readFromStream
7+
* $./readFromStream
8+
* // comment head
9+
* {
10+
* // comment before
11+
* "key" : "value"
12+
* }
13+
* // comment after
14+
* // comment tail
15+
*/
1716
int main(int argc, char* argv[]) {
1817
Json::Value root;
1918
std::ifstream ifs;
2019
ifs.open(argv[1]);
21-
root.clear();
2220

2321
Json::CharReaderBuilder builder;
2422
builder["collectComments"] = true;
+27-23
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
11
#include "json/json.h"
22
#include <iostream>
3-
/*
4-
parse a string to Value object with CharReaderBuilder class or Reader class
5-
$g++ readFromString.cpp -ljsoncpp -std=c++11 -o readFromString
6-
$./readFromString
7-
colin
8-
20
9-
*/
3+
/**
4+
* \brief Parse a raw string into Value object using the CharReaderBuilder
5+
* class, or the legacy Reader class.
6+
* Example Usage:
7+
* $g++ readFromString.cpp -ljsoncpp -std=c++11 -o readFromString
8+
* $./readFromString
9+
* colin
10+
* 20
11+
*/
1012
int main() {
11-
std::string strRes = R"({"Age": 20, "Name": "colin"})";
12-
auto nLen = (int)strRes.length();
13+
const std::string rawJson = R"({"Age": 20, "Name": "colin"})";
14+
const int rawJsonLength = static_cast<int>(rawJson.length());
15+
constexpr bool shouldUseOldWay = false;
1316
JSONCPP_STRING err;
1417
Json::Value root;
1518

16-
#if 0 // old way
17-
Json::Reader myreader;
18-
myreader.parse(strRes,root);
19-
#else // new way
20-
Json::CharReaderBuilder builder;
21-
std::unique_ptr<Json::CharReader> const reader(builder.newCharReader());
22-
if (!reader->parse(strRes.c_str(), strRes.c_str() + nLen, &root, &err)) {
23-
std::cout << "error" << std::endl;
24-
return EXIT_FAILURE;
19+
if (shouldUseOldWay) {
20+
Json::Reader reader;
21+
reader.parse(rawJson, root);
22+
} else {
23+
Json::CharReaderBuilder builder;
24+
std::unique_ptr<Json::CharReader> const reader(builder.newCharReader());
25+
if (!reader->parse(rawJson.c_str(), rawJson.c_str() + rawJsonLength, &root,
26+
&err)) {
27+
std::cout << "error" << std::endl;
28+
return EXIT_FAILURE;
29+
}
2530
}
26-
#endif
27-
std::string strName = root["Name"].asString();
28-
int strAge = root["Age"].asInt();
31+
const std::string name = root["Name"].asString();
32+
const int age = root["Age"].asInt();
2933

30-
std::cout << strName << std::endl;
31-
std::cout << strAge << std::endl;
34+
std::cout << name << std::endl;
35+
std::cout << age << std::endl;
3236
return EXIT_SUCCESS;
3337
}

example/streamWrite/streamWrite.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#include "json/json.h"
22
#include <iostream>
3-
/*
4-
write the Value object to stream
5-
$g++ streamWrite.cpp -ljsoncpp -std=c++11 -o streamWrite
6-
$./streamWrite
7-
{
8-
"Age" : 20,
9-
"Name" : "robin"
10-
}
11-
*/
3+
/** \brief Write the Value object to a stream.
4+
* Example Usage:
5+
* $g++ streamWrite.cpp -ljsoncpp -std=c++11 -o streamWrite
6+
* $./streamWrite
7+
* {
8+
* "Age" : 20,
9+
* "Name" : "robin"
10+
* }
11+
*/
1212
int main() {
1313
Json::Value root;
1414
Json::StreamWriterBuilder builder;
15-
std::unique_ptr<Json::StreamWriter> const writer(builder.newStreamWriter());
15+
const std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
1616

1717
root["Name"] = "robin";
1818
root["Age"] = 20;

example/stringWrite/stringWrite.cpp

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
#include "json/json.h"
22
#include <iostream>
3-
/*
4-
write a Value object to a string
5-
$g++ stringWrite.cpp -ljsoncpp -std=c++11 -o stringWrite
6-
$./stringWrite
7-
{
8-
"action" : "run",
9-
"data" :
10-
{
11-
"number" : 1
12-
}
13-
}
14-
*/
3+
/** \brief Write a Value object to a string.
4+
* Example Usage:
5+
* $g++ stringWrite.cpp -ljsoncpp -std=c++11 -o stringWrite
6+
* $./stringWrite
7+
* {
8+
* "action" : "run",
9+
* "data" :
10+
* {
11+
* "number" : 1
12+
* }
13+
* }
14+
*/
1515
int main() {
16-
1716
Json::Value root;
18-
Json::Value t_data;
19-
17+
Json::Value data;
18+
constexpr bool shouldUseOldWay = false;
2019
root["action"] = "run";
21-
t_data["number"] = 1;
22-
root["data"] = t_data;
20+
data["number"] = 1;
21+
root["data"] = data;
2322

24-
#if 0 // old way
23+
if (shouldUseOldWay) {
2524
Json::FastWriter writer;
26-
std::string json_file = writer.write(root);
27-
#else // new way
28-
Json::StreamWriterBuilder builder;
29-
std::string json_file = Json::writeString(builder, root);
30-
#endif
31-
std::cout << json_file << std::endl;
25+
const std::string json_file = writer.write(root);
26+
std::cout << json_file << std::endl;
27+
} else {
28+
Json::StreamWriterBuilder builder;
29+
const std::string json_file = Json::writeString(builder, root);
30+
std::cout << json_file << std::endl;
31+
}
3232
return EXIT_SUCCESS;
3333
}

src/lib_json/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ endif()
8787
# See https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html#prop_gbl:CMAKE_CXX_KNOWN_FEATURES
8888
# for complete list of features available
8989
target_compile_features(jsoncpp_lib PUBLIC
90-
# cxx_std_11 # Compiler mode is aware of C++ 11.
90+
cxx_std_11 # Compiler mode is aware of C++ 11.
9191
#MSVC 1900 cxx_alignas # Alignment control alignas, as defined in N2341.
9292
#MSVC 1900 cxx_alignof # Alignment control alignof, as defined in N2341.
9393
#MSVC 1900 cxx_attributes # Generic attributes, as defined in N2761.

0 commit comments

Comments
 (0)