From f3aba5cb3cca0f99f2a39d61acd960a836295593 Mon Sep 17 00:00:00 2001 From: kukin-konstantin Date: Tue, 10 Jan 2017 17:07:34 +0300 Subject: fix ReplyKeyboardMarkup --- src/TgTypeParser.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 45124e2..0952d75 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -442,16 +442,12 @@ string TgTypeParser::parseFile(const File::Ptr& object) const { ReplyKeyboardMarkup::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardMarkup(const boost::property_tree::ptree& data) const { ReplyKeyboardMarkup::Ptr result(new ReplyKeyboardMarkup); - for (const pair& item : data.find("keyboard")->second) { - vector array; - for (const pair& innerItem : item.second) { - array.push_back(innerItem.second.data()); - } - result->keyboard.push_back(array); + for (const boost::property_tree::ptree::value_type& item : data.find("keyboard")->second){ + result->keyboard.push_back(parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetKeyboardButton, item.second)); } - result->resizeKeyboard = data.get("resize_keyboard"); - result->oneTimeKeyboard = data.get("one_time_keyboard"); - result->selective = data.get("selective"); + result->resizeKeyboard = data.get("resize_keyboard", false); + result->oneTimeKeyboard = data.get("one_time_keyboard", false); + result->selective = data.get("selective", false); return result; } @@ -462,12 +458,11 @@ std::string TgTypeParser::parseReplyKeyboardMarkup(const ReplyKeyboardMarkup::Pt string result; result += '{'; result += "\"keyboard\":["; - for (vector& item : object->keyboard) { + for (vector& item : object->keyboard) { result += '['; - for (string& innerItem : item) { - result += '"'; - result += innerItem; - result += "\","; + for (KeyboardButton::Ptr& innerItem : item) { + result += parseKeyboardButton(innerItem); + result += ','; } result.erase(result.length() - 1); result += "],"; -- cgit v1.2.3 From 54a50a7c8a7e9d15c03bdb64babe54e5c123e5c7 Mon Sep 17 00:00:00 2001 From: kukin-konstantin Date: Wed, 11 Jan 2017 20:33:18 +0300 Subject: fix encodeUrl function --- src/tools/StringTools.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/tools/StringTools.cpp b/src/tools/StringTools.cpp index c682b35..d5270db 100644 --- a/src/tools/StringTools.cpp +++ b/src/tools/StringTools.cpp @@ -84,20 +84,22 @@ string generateRandomString(size_t length) { return result; } + string urlEncode(const string& value, const std::string& additionalLegitChars) { - static const string legitPunctuation = "-_.~"; - ostringstream result; - result.fill('0'); - result << hex; - for (const char& c : value) { - if (isalnum(c) || legitPunctuation.find(c) != legitPunctuation.npos || additionalLegitChars.find(c) != additionalLegitChars.npos) { - result << c; + static const string legitPunctuation = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-~:"; + std::stringstream ss; + std::string t; + for (auto const &c : value) { + if ((legitPunctuation.find(c) == std::string::npos) + && (additionalLegitChars.find(c)==std::string::npos)) { + ss << '%' << std::uppercase << std::setfill('0') << std::setw(2) << std::hex << (unsigned int)(unsigned char)c; + t = ss.str(); } else { - result << '%' << setw(2) << int((unsigned char) c); + ss << c; } } - return result.str(); + return ss.str(); } string urlDecode(const string& value) { -- cgit v1.2.3 From 19a83123e908e8d80b404d47ec843fa6f0d4a5a6 Mon Sep 17 00:00:00 2001 From: kukin-konstantin Date: Thu, 12 Jan 2017 18:01:49 +0300 Subject: fix parse Array error --- src/TgTypeParser.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 0952d75..f22a868 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -467,7 +467,8 @@ std::string TgTypeParser::parseReplyKeyboardMarkup(const ReplyKeyboardMarkup::Pt result.erase(result.length() - 1); result += "],"; } - result.erase(result.length() - 1); + if (!object->keyboard.empty()) + result.erase(result.length() - 1); result += "],"; appendToJson(result, "resize_keyboard", object->resizeKeyboard); appendToJson(result, "one_time_keyboard", object->oneTimeKeyboard); @@ -1329,7 +1330,8 @@ std::string TgTypeParser::parseInlineKeyboardMarkup(const InlineKeyboardMarkup:: result.erase(result.length() - 1); result += "],"; } - result.erase(result.length() - 1); + if (!object->inlineKeyboard.empty()) + result.erase(result.length() - 1); result += "]}"; return result; } -- cgit v1.2.3