1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-14 11:47:15 +01:00
SqMod/module/Vendor/CPR/cpr/curl_container.cpp
2021-01-27 07:27:48 +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