Handle more than one replacement in replace_parameter_in_uri().
continuous-integration/drone/push Build is passing Details

This commit is contained in:
tastytea 2020-03-12 12:06:31 +01:00
parent 00056c224e
commit da1c2ba409
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 12 additions and 1 deletions

View File

@ -22,6 +22,7 @@
#include <algorithm>
#include <array>
#include <atomic>
#include <cctype>
#include <cstdint>
namespace mastodonpp
@ -30,8 +31,10 @@ namespace mastodonpp
using std::get;
using std::holds_alternative;
using std::any_of;
using std::transform;
using std::array; // NOLINT(misc-unused-using-decls)
using std::atomic;
using std::toupper;
using std::uint8_t;
using std::uint16_t;
@ -362,7 +365,15 @@ bool CURLWrapper::replace_parameter_in_uri(string &uri,
if (any_of(replace.begin(), replace.end(),
[&parameter](const auto &s) { return s == parameter.first; }))
{
const auto pos{uri.find('<')};
const string searchstring{[&parameter]
{
string s{"<"};
s += parameter.first;
transform(s.begin(), s.end(), s.begin(),
[](const unsigned char c){ return toupper(c); });
return s;
}()};
const auto pos{uri.find(searchstring)};
if (pos != string::npos)
{
uri.replace(pos, parameter.first.size() + 2,