Commit d0188462 authored by seky's avatar seky

removed std::string and receiving const Value in printIt

parent c9060b4a
#define RAPIDJSON_HAS_STDSTRING 1
#include "rapidjson/document.h" #include "rapidjson/document.h"
#include "rapidjson/filewritestream.h"
#include <rapidjson/prettywriter.h> #include <rapidjson/prettywriter.h>
#include <rapidjson/stringbuffer.h>
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
...@@ -9,26 +8,23 @@ ...@@ -9,26 +8,23 @@
using namespace rapidjson; using namespace rapidjson;
using namespace std; using namespace std;
void printIt(Document &doc) void printIt(const Value &doc)
{ {
string output; char writeBuffer[65536];
StringBuffer buffer; FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
PrettyWriter<StringBuffer> writer(buffer); PrettyWriter<FileWriteStream> writer(os);
doc.Accept(writer); doc.Accept(writer);
output = buffer.GetString(); cout << endl;
cout << output << endl;
} }
struct ValueNameComparator struct NameComparator
{ {
bool bool
operator()(const GenericMember<UTF8<>, MemoryPoolAllocator<>> &lhs, operator()(const GenericMember<UTF8<>, MemoryPoolAllocator<>> &lhs,
const GenericMember<UTF8<>, MemoryPoolAllocator<>> &rhs) const const GenericMember<UTF8<>, MemoryPoolAllocator<>> &rhs) const
{ {
string lhss = string(lhs.name.GetString()); return (strcmp(lhs.name.GetString(), rhs.name.GetString()) < 0);
string rhss = string(rhs.name.GetString());
return lhss < rhss;
} }
}; };
...@@ -55,7 +51,7 @@ int main() ...@@ -55,7 +51,7 @@ int main()
} }
**/ **/
std::sort(d.MemberBegin(), d.MemberEnd(), ValueNameComparator()); std::sort(d.MemberBegin(), d.MemberEnd(), NameComparator());
printIt(d); printIt(d);
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment