Skip to content

Commit 6288d95

Browse files
StilesCrisisStilesCrisis
authored andcommitted
SimplePullReader C++98 support
std::to_string can’t be used because it requires C++11.
1 parent 4232e40 commit 6288d95

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

example/simplepullreader/simplepullreader.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
#include "rapidjson/reader.h"
22
#include <iostream>
3+
#include <sstream>
34

45
using namespace rapidjson;
56
using namespace std;
67

8+
// If you can require C++11, you could use std::to_string here
9+
template <typename T> std::string stringify(T x) {
10+
return (std::stringstream() << x).str();
11+
}
12+
713
struct MyHandler {
814
const char* type;
915
std::string data;
1016

1117
bool Null() { type = "Null"; data.clear(); return true; }
1218
bool Bool(bool b) { type = "Bool:"; data = b? "true": "false"; return true; }
13-
bool Int(int i) { type = "Int:"; data = std::to_string(i); return true; }
14-
bool Uint(unsigned u) { type = "Uint:"; data = std::to_string(u); return true; }
15-
bool Int64(int64_t i) { type = "Int64:"; data = std::to_string(i); return true; }
16-
bool Uint64(uint64_t u) { type = "Uint64:"; data = std::to_string(u); return true; }
17-
bool Double(double d) { type = "Double:"; data = std::to_string(d); return true; }
19+
bool Int(int i) { type = "Int:"; data = stringify(i); return true; }
20+
bool Uint(unsigned u) { type = "Uint:"; data = stringify(u); return true; }
21+
bool Int64(int64_t i) { type = "Int64:"; data = stringify(i); return true; }
22+
bool Uint64(uint64_t u) { type = "Uint64:"; data = stringify(u); return true; }
23+
bool Double(double d) { type = "Double:"; data = stringify(d); return true; }
1824
bool RawNumber(const char* str, SizeType length, bool) { type = "Number:"; data = std::string(str, length); return true; }
1925
bool String(const char* str, SizeType length, bool) { type = "String:"; data = std::string(str, length); return true; }
2026
bool StartObject() { type = "StartObject"; data.clear(); return true; }
2127
bool Key(const char* str, SizeType length, bool) { type = "Key:"; data = std::string(str, length); return true; }
22-
bool EndObject(SizeType memberCount) { type = "EndObject:"; data = std::to_string(memberCount); return true; }
28+
bool EndObject(SizeType memberCount) { type = "EndObject:"; data = stringify(memberCount); return true; }
2329
bool StartArray() { type = "StartArray"; data.clear(); return true; }
24-
bool EndArray(SizeType elementCount) { type = "EndArray:"; data = std::to_string(elementCount); return true; }
30+
bool EndArray(SizeType elementCount) { type = "EndArray:"; data = stringify(elementCount); return true; }
2531
};
2632

2733
int main() {

0 commit comments

Comments
 (0)