forked from idealvin/coost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rapidjson.h
40 lines (31 loc) · 872 Bytes
/
rapidjson.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once
#include "rapidjson/allocators.h"
#include "rapidjson/document.h"
#include "rapidjson/rapidjson.h"
#include "rapidjson/reader.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
#include "rapidjson/prettywriter.h"
#include <string>
namespace rapidjson {
inline std::string str(const Document& doc) {
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
doc.Accept(writer);
return buffer.GetString();
}
inline std::string pretty(const Document& doc) {
StringBuffer buffer;
PrettyWriter<StringBuffer> writer(buffer);
doc.Accept(writer);
return buffer.GetString();
}
inline bool parse(const char* s, Document& doc) {
doc.Parse(s);
return !doc.HasParseError();
}
inline bool parse(const std::string& s, Document& doc) {
doc.Parse(s.data(), s.size());
return !doc.HasParseError();
}
}