diff options
author | seky <hrvoje.seketa@homecontrol.no> | 2018-12-05 10:24:59 +0300 |
---|---|---|
committer | seky <hrvoje.seketa@homecontrol.no> | 2018-12-05 10:24:59 +0300 |
commit | d0188462d909d221bcd55c2a64ca5943b931dc08 (patch) | |
tree | 8da32f6083bbb244b354804744027fab36e2934c /example | |
parent | c9060b4a5c29a0d9fc69573695e600add61b75fc (diff) |
removed std::string and receiving const Value in printIt
Diffstat (limited to 'example')
-rw-r--r-- | example/sortkeys/sortkeys.cpp | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/example/sortkeys/sortkeys.cpp b/example/sortkeys/sortkeys.cpp index fb45d4aa..85e08074 100644 --- a/example/sortkeys/sortkeys.cpp +++ b/example/sortkeys/sortkeys.cpp @@ -1,7 +1,6 @@ -#define RAPIDJSON_HAS_STDSTRING 1 #include "rapidjson/document.h" +#include "rapidjson/filewritestream.h" #include <rapidjson/prettywriter.h> -#include <rapidjson/stringbuffer.h> #include <algorithm> #include <iostream> @@ -9,26 +8,23 @@ using namespace rapidjson; using namespace std; -void printIt(Document &doc) +void printIt(const Value &doc) { - string output; - StringBuffer buffer; - PrettyWriter<StringBuffer> writer(buffer); + char writeBuffer[65536]; + FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer)); + PrettyWriter<FileWriteStream> writer(os); doc.Accept(writer); - output = buffer.GetString(); - cout << output << endl; + cout << endl; } -struct ValueNameComparator +struct NameComparator { bool operator()(const GenericMember<UTF8<>, MemoryPoolAllocator<>> &lhs, const GenericMember<UTF8<>, MemoryPoolAllocator<>> &rhs) const { - string lhss = string(lhs.name.GetString()); - string rhss = string(rhs.name.GetString()); - return lhss < rhss; + return (strcmp(lhs.name.GetString(), rhs.name.GetString()) < 0); } }; @@ -55,7 +51,7 @@ int main() } **/ - std::sort(d.MemberBegin(), d.MemberEnd(), ValueNameComparator()); + std::sort(d.MemberBegin(), d.MemberEnd(), NameComparator()); printIt(d); /** |