Skip to content

Commit d018846

Browse files
committed
removed std::string and receiving const Value in printIt
1 parent c9060b4 commit d018846

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

example/sortkeys/sortkeys.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
1-
#define RAPIDJSON_HAS_STDSTRING 1
21
#include "rapidjson/document.h"
2+
#include "rapidjson/filewritestream.h"
33
#include <rapidjson/prettywriter.h>
4-
#include <rapidjson/stringbuffer.h>
54

65
#include <algorithm>
76
#include <iostream>
87

98
using namespace rapidjson;
109
using namespace std;
1110

12-
void printIt(Document &doc)
11+
void printIt(const Value &doc)
1312
{
14-
string output;
15-
StringBuffer buffer;
16-
PrettyWriter<StringBuffer> writer(buffer);
13+
char writeBuffer[65536];
14+
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
15+
PrettyWriter<FileWriteStream> writer(os);
1716
doc.Accept(writer);
1817

19-
output = buffer.GetString();
20-
cout << output << endl;
18+
cout << endl;
2119
}
2220

23-
struct ValueNameComparator
21+
struct NameComparator
2422
{
2523
bool
2624
operator()(const GenericMember<UTF8<>, MemoryPoolAllocator<>> &lhs,
2725
const GenericMember<UTF8<>, MemoryPoolAllocator<>> &rhs) const
2826
{
29-
string lhss = string(lhs.name.GetString());
30-
string rhss = string(rhs.name.GetString());
31-
return lhss < rhss;
27+
return (strcmp(lhs.name.GetString(), rhs.name.GetString()) < 0);
3228
}
3329
};
3430

@@ -55,7 +51,7 @@ int main()
5551
}
5652
**/
5753

58-
std::sort(d.MemberBegin(), d.MemberEnd(), ValueNameComparator());
54+
std::sort(d.MemberBegin(), d.MemberEnd(), NameComparator());
5955

6056
printIt(d);
6157
/**

0 commit comments

Comments
 (0)