removed std::string and receiving const Value in printIt
This commit is contained in:
parent
c9060b4a5c
commit
d0188462d9
@ -1,7 +1,6 @@
|
|||||||
#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 @@
|
|||||||
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()
|
|||||||
}
|
}
|
||||||
**/
|
**/
|
||||||
|
|
||||||
std::sort(d.MemberBegin(), d.MemberEnd(), ValueNameComparator());
|
std::sort(d.MemberBegin(), d.MemberEnd(), NameComparator());
|
||||||
|
|
||||||
printIt(d);
|
printIt(d);
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user