Skip to content

Commit

Permalink
removed std::string and receiving const Value in printIt
Browse files Browse the repository at this point in the history
  • Loading branch information
sekyHC committed Dec 5, 2018
1 parent c9060b4 commit d018846
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions example/sortkeys/sortkeys.cpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
#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>

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);
}
};

Expand All @@ -55,7 +51,7 @@ int main()
}
**/

std::sort(d.MemberBegin(), d.MemberEnd(), ValueNameComparator());
std::sort(d.MemberBegin(), d.MemberEnd(), NameComparator());

printIt(d);
/**
Expand Down

0 comments on commit d018846

Please sign in to comment.