mirror of
https://github.com/yourWaifu/sleepy-discord.git
synced 2025-12-17 18:54:17 -06:00
When compiling for C++17, was getting an error about the to_string method not existing in json_wrapper.cpp. Detailed in issue #221. Fixed it by adding the necessary import statement to the file.
47 lines
1.3 KiB
C++
47 lines
1.3 KiB
C++
#include "json_wrapper.h"
|
|
#include <stdexcept>
|
|
#include <string>
|
|
|
|
namespace SleepyDiscord { namespace json {
|
|
const std::string createJSON(std::initializer_list<std::pair<std::string, std::string>> json) {
|
|
std::string target;
|
|
target.reserve(2); //revents crash
|
|
for (std::pair<std::string, std::string> pair : json) {
|
|
if (pair.second != "") {
|
|
target += ",\"" + pair.first + "\":" + pair.second;
|
|
}
|
|
}
|
|
target[0] = '{';
|
|
target.push_back('}');
|
|
return target;
|
|
}
|
|
|
|
const std::string string(const std::string& s) {
|
|
if (s.empty())
|
|
return "";
|
|
rapidjson::StringBuffer buffer;
|
|
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
|
writer.String(s.data(), s.length());
|
|
return std::string(buffer.GetString(), buffer.GetSize());
|
|
}
|
|
|
|
const std::string UInteger(const uint64_t num) {
|
|
return std::to_string(num & 0x3FFFFFFFFFFFFF); //just in case numbers are larger then 53 bits
|
|
}
|
|
|
|
const std::string optionalUInteger(const uint64_t num) {
|
|
return num ? UInteger(num) : "";
|
|
}
|
|
|
|
const std::string integer(const int64_t num) {
|
|
return std::to_string(num & 0x803FFFFFFFFFFFFF); //just in case numbers are larger then 53 bits
|
|
}
|
|
|
|
const std::string optionalInteger(const int64_t num) {
|
|
return num ? integer(num) : "";
|
|
}
|
|
|
|
const std::string boolean(const bool boolean) {
|
|
return boolean ? "true" : "false";
|
|
}
|
|
}} |