From f239eef1eb7e7145bf8eddbeb7e496f266101723 Mon Sep 17 00:00:00 2001 From: YJBeetle Date: Tue, 12 Nov 2019 03:59:42 +0800 Subject: fix #113 InlineQueryResult json parse bug --- include/tgbot/TgTypeParser.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'include') diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index dbfa27e..979ba55 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -468,6 +468,24 @@ private: json += ','; } + template + inline void appendToJsonNumber(std::string& json, const std::string& varName, const T& value) const { + json += '"'; + json += varName; + json += R"(":)"; + json += std::to_string(value); + json += ','; + } + inline void appendToJson(std::string &json, const std::string &varName, const int &value) const { appendToJsonNumber(json, varName, value); } + inline void appendToJson(std::string &json, const std::string &varName, const long &value) const { appendToJsonNumber(json, varName, value); } + inline void appendToJson(std::string &json, const std::string &varName, const long long &value) const { appendToJsonNumber(json, varName, value); } + inline void appendToJson(std::string &json, const std::string &varName, const unsigned &value) const { appendToJsonNumber(json, varName, value); } + inline void appendToJson(std::string &json, const std::string &varName, const unsigned long &value) const { appendToJsonNumber(json, varName, value); } + inline void appendToJson(std::string &json, const std::string &varName, const unsigned long long &value) const { appendToJsonNumber(json, varName, value); } + inline void appendToJson(std::string &json, const std::string &varName, const float &value) const { appendToJsonNumber(json, varName, value); } + inline void appendToJson(std::string &json, const std::string &varName, const double &value) const { appendToJsonNumber(json, varName, value); } + inline void appendToJson(std::string &json, const std::string &varName, const long double &value) const { appendToJsonNumber(json, varName, value); } + inline void appendToJson(std::string& json, const std::string& varName, const bool& value) const { json += '"'; json += varName; -- cgit v1.2.3