Fixed deletion of parameters.
This commit is contained in:
parent
64d4c65668
commit
7d245e0df1
@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include "debug.hpp"
|
||||
#include "mastodon-cpp.hpp"
|
||||
|
||||
@ -224,10 +225,8 @@ const return_call API::get(const Mastodon::API::v1 &call,
|
||||
|
||||
if (params.size() > 0)
|
||||
{
|
||||
// Delete the params that are already in strcall
|
||||
parameters newparams = params;
|
||||
newparams.erase(newparams.find("id"));
|
||||
newparams.erase(newparams.find("tag"));
|
||||
// Delete the parameters that are already in strcall
|
||||
const parameters newparams = delete_params(params, { "id", "tag" });
|
||||
strcall += maptostr(newparams);
|
||||
}
|
||||
|
||||
@ -263,10 +262,8 @@ const return_call API::get(const Mastodon::API::v2 &call,
|
||||
|
||||
if (params.size() > 0)
|
||||
{
|
||||
// Delete the params that are already in strcall
|
||||
parameters newparams = params;
|
||||
newparams.erase(newparams.find("id"));
|
||||
newparams.erase(newparams.find("tag"));
|
||||
// Delete the parameterss that are already in strcall
|
||||
const parameters newparams = delete_params(params, { "id", "tag" });
|
||||
strcall += maptostr(newparams);
|
||||
}
|
||||
|
||||
|
@ -578,3 +578,24 @@ void API::get_proxy(string &proxy, string &userpw) const
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const parameters API::delete_params(const parameters ¶ms,
|
||||
const vector<string> &keys)
|
||||
{
|
||||
// Iterate through params. For each item in keys (k), compare to key of
|
||||
// current parameter (p). Return false if parameter is to be deleted. Copy
|
||||
// to new list of parameters (newparams) if true is returned.
|
||||
parameters newparams(params.size());
|
||||
const auto it =
|
||||
std::copy_if(params.begin(), params.end(), newparams.begin(),
|
||||
[&keys](const param &p)
|
||||
{
|
||||
return std::any_of(keys.begin(), keys.end(),
|
||||
[&p](const string &k)
|
||||
{
|
||||
return (k != p.key);
|
||||
});
|
||||
});
|
||||
newparams.resize(std::distance(newparams.begin(), it));
|
||||
return newparams;
|
||||
}
|
||||
|
@ -687,6 +687,19 @@ namespace Mastodon
|
||||
* @return Form data as curlpp::Forms
|
||||
*/
|
||||
const curlpp::Forms maptoformdata(const parameters &map);
|
||||
|
||||
/*!
|
||||
* @brief Delete Mastodon::param from Mastodon::parameters.
|
||||
*
|
||||
* @param params Old vector of parameters.
|
||||
* @param key keys of Mastodon::param to delete.
|
||||
*
|
||||
* @return New vector of parameters.
|
||||
*
|
||||
* @since 0.102.0
|
||||
*/
|
||||
const parameters delete_params(const parameters ¶ms,
|
||||
const vector<string> &keys);
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user