Skip to content

Commit

Permalink
boost::replace_all > std::replace
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Jan 22, 2025
1 parent 224fb70 commit 34ea1b9
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions modules/geoipbackend/geoipinterface-dat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class GeoIPInterfaceDAT : public GeoIPInterface
free(result);
gl.netmask = tmp_gl.netmask;
// reduce space to dash
ret = boost::replace_all_copy(ret, " ", "-");
std::replace(ret.begin(), ret.end(), ' ', '-');
return true;
}
}
Expand All @@ -306,7 +306,7 @@ class GeoIPInterfaceDAT : public GeoIPInterface
free(result);
gl.netmask = tmp_gl.netmask;
// reduce space to dash
ret = boost::replace_all_copy(ret, " ", "-");
std::replace(ret.begin(), ret.end(), ' ', '-');
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnsdistdist/dnsdist-actions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ DNSAction::Action DNSAction::typeFromString(const std::string& str)
};

auto lower = boost::to_lower_copy(str);
boost::replace_all(lower, "-", "");
lower.erase(std::remove(lower.begin(), lower.end(), '-'), lower.end());
auto mappingIt = s_mappings.find(lower);
if (mappingIt != s_mappings.end()) {
return mappingIt->second;
Expand Down
16 changes: 8 additions & 8 deletions pdns/dnsdistdist/dnsdist-carbon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static bool doOneCarbonExport(const Carbon::Endpoint& endpoint)

for (const auto& state : dnsdist::configuration::getCurrentRuntimeConfiguration().d_backends) {
string serverName = state->getName().empty() ? state->d_config.remote.toStringWithPort() : state->getName();
boost::replace_all(serverName, ".", "_");
std::replace(serverName.begin(), serverName.end(), '.', '_');
string base = namespace_name;
base += ".";
base += hostname;
Expand Down Expand Up @@ -123,7 +123,7 @@ static bool doOneCarbonExport(const Carbon::Endpoint& endpoint)
}

string frontName = front->local.toStringWithPort() + (front->udpFD >= 0 ? "_udp" : "_tcp");
boost::replace_all(frontName, ".", "_");
std::replace(frontName.begin(), frontName.end(), '.', '_');
auto dupPair = frontendDuplicates.insert({frontName, 1});
if (!dupPair.second) {
frontName += "_" + std::to_string(dupPair.first->second);
Expand Down Expand Up @@ -180,7 +180,7 @@ static bool doOneCarbonExport(const Carbon::Endpoint& endpoint)

for (const auto& entry : dnsdist::configuration::getCurrentRuntimeConfiguration().d_pools) {
string poolName = entry.first;
boost::replace_all(poolName, ".", "_");
std::replace(poolName.begin(), poolName.end(), '.', '_');
if (poolName.empty()) {
poolName = "_default_";
}
Expand Down Expand Up @@ -228,10 +228,10 @@ static bool doOneCarbonExport(const Carbon::Endpoint& endpoint)
const string base = "dnsdist." + hostname + ".main.doh.";
for (const auto& doh : dnsdist::getDoHFrontends()) {
string name = doh->d_tlsContext.d_addr.toStringWithPort();
boost::replace_all(name, ".", "_");
boost::replace_all(name, ":", "_");
boost::replace_all(name, "[", "_");
boost::replace_all(name, "]", "_");
std::replace(name.begin(), name.end(), '.', '_');
std::replace(name.begin(), name.end(), ':', '_');
std::replace(name.begin(), name.end(), '[', '_');
std::replace(name.begin(), name.end(), ']', '_');

auto dupPair = dohFrontendDuplicates.insert({name, 1});
if (!dupPair.second) {
Expand Down Expand Up @@ -274,7 +274,7 @@ static bool doOneCarbonExport(const Carbon::Endpoint& endpoint)
auto records = dnsdist::QueryCount::g_queryCountRecords.write_lock();
for (const auto& record : *records) {
qname = record.first;
boost::replace_all(qname, ".", "_");
std::replace(qname.begin(), qname.end(), '.', '_');
str << "dnsdist.querycount." << qname << ".queries " << record.second << " " << now << "\r\n";
}
records->clear();
Expand Down
4 changes: 2 additions & 2 deletions pdns/dnsdistdist/dnsdist-secpoll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ void doSecPoll(const std::string& suffix)
queriedName += '.';
}

boost::replace_all(queriedName, "+", "_");
boost::replace_all(queriedName, "~", "_");
std::replace(queriedName.begin(), queriedName.end(), '+', '_');
std::replace(queriedName.begin(), queriedName.end(), '~', '_');

try {
std::string status = getSecPollStatus(queriedName);
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnsdistdist/dnsdist-web.cc
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ static void handlePrometheus(const YaHTTP::Request& req, YaHTTP::Response& resp)
serverName = state->getName();
}

boost::replace_all(serverName, ".", "_");
std::replace(serverName.begin(), serverName.end(), '.', '_');

const std::string label = boost::str(boost::format(R"({server="%1%",address="%2%"})")
% serverName % state->d_config.remote.toStringWithPort());
Expand Down
4 changes: 2 additions & 2 deletions pdns/dnsdistdist/doh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1145,8 +1145,8 @@ static int doh_handler(h2o_handler_t *self, h2o_req_t *req)
if (pos != string::npos) {
// need to base64url decode this
string sdns(path.substr(pos+5));
boost::replace_all(sdns,"-", "+");
boost::replace_all(sdns,"_", "/");
std::replace(sdns.begin(), sdns.end(), '-', '+');
std::replace(sdns.begin(), sdns.end(), '_', '/');
// re-add padding that may have been missing
switch (sdns.size() % 4) {
case 2:
Expand Down
6 changes: 3 additions & 3 deletions pdns/lua-record.cc
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn
vector<ComboAddress> candidates;
// Getting something like 192-0-2-1.192-0-2-2.198-51-100-1.example.org
for(auto l : s_lua_record_ctx->qname.getRawLabels()) {
boost::replace_all(l, "-", ".");
std::replace(l.begin(), l.end(), '-', '.');
try {
candidates.emplace_back(l);
} catch (const PDNSException& e) {
Expand Down Expand Up @@ -1071,7 +1071,7 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn
}
else if(parts.size()==1) {
if (parts[0].find('-') != std::string::npos) {
boost::replace_all(parts[0],"-",":");
std::replace(parts[0].begin(), parts[0].end(), '-', ':');
ComboAddress ca(parts[0]);
return ca.toString();
} else {
Expand Down Expand Up @@ -1130,7 +1130,7 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn
}

string dashed=ip6.toString();
boost::replace_all(dashed, ":", "-");
std::replace(dashed.begin(), dashed.end(), ':', '-');

for(int i=31; i>=0; --i)
fmt % labels[i];
Expand Down
2 changes: 1 addition & 1 deletion pdns/misc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ std::string getCarbonHostName()
throw std::runtime_error(stringerror());
}

boost::replace_all(*hostname, ".", "_");
std::replace(hostname->begin(), hostname->end(), '.', '_');
return *hostname;
}

Expand Down
4 changes: 2 additions & 2 deletions pdns/recursordist/secpoll-recursor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ void doSecPoll(time_t* last_secpoll, Logr::log_t log)
qstring += '.';
}

boost::replace_all(qstring, "+", "_");
boost::replace_all(qstring, "~", "_");
std::replace(qstring.begin(), qstring.end(), '+', '_');
std::replace(qstring.begin(), qstring.end(), '~', '_');

vState state = vState::Indeterminate;
DNSName query(qstring);
Expand Down
4 changes: 2 additions & 2 deletions pdns/secpoll-auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ void doSecPoll(bool first)
if(*query.rbegin()!='.')
query+='.';

boost::replace_all(query, "+", "_");
boost::replace_all(query, "~", "_");
std::replace(query.begin(), query.end(), '+', '_');
std::replace(query.begin(), query.end(), '~', '_');

int security_status = std::stoi(S.getValueStr("security-status"));

Expand Down
2 changes: 1 addition & 1 deletion pdns/test-misc_hh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ BOOST_AUTO_TEST_CASE(test_getCarbonHostName)

BOOST_CHECK_EQUAL(gethostname(buffer, sizeof buffer), 0);
std::string my_hostname(buffer);
boost::replace_all(my_hostname, ".", "_");
std::replace(my_hostname.begin(), my_hostname.end(), '.', '_');

std::string hostname = getCarbonHostName();
// ensure it matches what we get
Expand Down

0 comments on commit 34ea1b9

Please sign in to comment.