1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 16:57:16 +01:00
SqMod/vendor/CPR/cpr/curl_container.cpp
Sandu Liviu Catalin 4a6bfc086c Major plugin refactor and cleanup.
Switched to POCO library for unified platform/library interface.
Deprecated the external module API. It was creating more problems than solving.
Removed most built-in libraries in favor of system libraries for easier maintenance.
Cleaned and secured code with help from static analyzers.
2021-01-30 08:51:39 +02:00

60 lines
1.6 KiB
C++

#include "cpr/curl_container.h"
namespace cpr {
template <class T>
CurlContainer<T>::CurlContainer(const std::initializer_list<T>& containerList)
: containerList_(containerList) {}
template <class T>
void CurlContainer<T>::Add(const std::initializer_list<T>& containerList) {
for (const T& element : containerList) {
containerList_.push_back(std::move(element));
}
}
template <class T>
void CurlContainer<T>::Add(const T& element) {
containerList_.push_back(std::move(element));
}
template <>
const std::string CurlContainer<Parameter>::GetContent(const CurlHolder& holder) const {
std::string content{};
for (const Parameter& parameter : containerList_) {
if (!content.empty()) {
content += "&";
}
std::string escapedKey = holder.urlEncode(parameter.key);
if (parameter.value.empty()) {
content += escapedKey;
} else {
std::string escapedValue = holder.urlEncode(parameter.value);
content += escapedKey + "=";
content += escapedValue;
}
};
return content;
}
template <>
const std::string CurlContainer<Pair>::GetContent(const CurlHolder& holder) const {
std::string content{};
for (const cpr::Pair& element : containerList_) {
if (!content.empty()) {
content += "&";
}
std::string escaped = holder.urlEncode(element.value);
content += element.key + "=" + escaped;
}
return content;
}
template class CurlContainer<Pair>;
template class CurlContainer<Parameter>;
} // namespace cpr