Commit f595f8a6 authored by Milo Yip's avatar Milo Yip

Update sortkeys.cpp

parent 18920132
......@@ -8,59 +8,52 @@
using namespace rapidjson;
using namespace std;
void printIt(const Value &doc)
{
static void printIt(const Value &doc) {
char writeBuffer[65536];
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
PrettyWriter<FileWriteStream> writer(os);
doc.Accept(writer);
cout << endl;
}
struct NameComparator
{
bool
operator()(const GenericMember<UTF8<>, MemoryPoolAllocator<>> &lhs,
const GenericMember<UTF8<>, MemoryPoolAllocator<>> &rhs) const
struct NameComparator {
bool operator()(
const GenericMember<UTF8<>, MemoryPoolAllocator<> > &lhs,
const GenericMember<UTF8<>, MemoryPoolAllocator<> > &rhs) const
{
return (strcmp(lhs.name.GetString(), rhs.name.GetString()) < 0);
}
};
int main()
{
int main() {
Document d = Document(kObjectType);
Document::AllocatorType &allocator = d.GetAllocator();
d.AddMember("zeta", Value().SetBool(false), allocator);
d.AddMember("gama", Value().SetString("test string", allocator), allocator);
d.AddMember("delta", Value().SetInt(123), allocator);
Value a(kArrayType);
d.AddMember("alpha", a, allocator);
d.AddMember("alpha", Value(kArrayType).Move(), allocator);
printIt(d);
/**
/*
{
"zeta": false,
"gama": "test string",
"delta": 123,
"alpha": []
}
**/
*/
std::sort(d.MemberBegin(), d.MemberEnd(), NameComparator());
printIt(d);
/**
/*
{
"alpha": [],
"delta": 123,
"gama": "test string",
"zeta": false
}
**/
return 0;
*/
}
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