0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00

Wrap boost::replace_all

This commit is contained in:
MacroFake 2022-05-05 08:28:29 +02:00
parent c367736f85
commit fa2deae2a8
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
8 changed files with 22 additions and 19 deletions

View file

@ -919,6 +919,7 @@ libbitcoinkernel_la_SOURCES = \
util/serfloat.cpp \
util/settings.cpp \
util/strencodings.cpp \
util/string.cpp \
util/syscall_sandbox.cpp \
util/syserror.cpp \
util/system.cpp \

View file

@ -92,7 +92,6 @@
#include <sys/stat.h>
#endif
#include <boost/algorithm/string/replace.hpp>
#include <boost/signals2/signal.hpp>
#if ENABLE_ZMQ
@ -1641,7 +1640,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
uiInterface.NotifyBlockTip_connect([block_notify](SynchronizationState sync_state, const CBlockIndex* pBlockIndex) {
if (sync_state != SynchronizationState::POST_INIT || !pBlockIndex) return;
std::string command = block_notify;
boost::replace_all(command, "%s", pBlockIndex->GetBlockHash().GetHex());
ReplaceAll(command, "%s", pBlockIndex->GetBlockHash().GetHex());
std::thread t(runCommand, command);
t.detach(); // thread runs free
});

View file

@ -24,8 +24,6 @@
#include <set>
#include <vector>
#include <boost/algorithm/string/replace.hpp>
#include <event2/buffer.h>
#include <event2/bufferevent.h>
#include <event2/event.h>
@ -566,7 +564,7 @@ void TorController::protocolinfo_cb(TorControlConnection& _conn, const TorContro
if (!torpassword.empty()) {
if (methods.count("HASHEDPASSWORD")) {
LogPrint(BCLog::TOR, "tor: Using HASHEDPASSWORD authentication\n");
boost::replace_all(torpassword, "\"", "\\\"");
ReplaceAll(torpassword, "\"", "\\\"");
_conn.Command("AUTHENTICATE \"" + torpassword + "\"", std::bind(&TorController::auth_cb, this, std::placeholders::_1, std::placeholders::_2));
} else {
LogPrintf("tor: Password provided with -torpassword, but HASHEDPASSWORD authentication is not available\n");

View file

@ -3,3 +3,10 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <util/string.h>
#include <boost/algorithm/string/replace.hpp>
void ReplaceAll(std::string& in_out, std::string_view search, std::string_view substitute)
{
boost::replace_all(in_out, search, substitute);
}

View file

@ -5,11 +5,11 @@
#ifndef BITCOIN_UTIL_STRING_H
#define BITCOIN_UTIL_STRING_H
#include <attributes.h>
#include <util/spanparsing.h>
#include <algorithm>
#include <array>
#include <cstdint>
#include <cstring>
#include <locale>
#include <sstream>
@ -17,6 +17,8 @@
#include <string_view>
#include <vector>
void ReplaceAll(std::string& in_out, std::string_view search, std::string_view substitute);
[[nodiscard]] inline std::vector<std::string> SplitString(std::string_view str, char sep)
{
return spanparsing::Split<std::string>(str, sep);

View file

@ -76,7 +76,6 @@
#include <malloc.h>
#endif
#include <boost/algorithm/string/replace.hpp>
#include <univalue.h>
#include <fstream>
@ -1253,7 +1252,7 @@ fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
std::string ShellEscape(const std::string& arg)
{
std::string escaped = arg;
boost::replace_all(escaped, "'", "'\"'\"'");
ReplaceAll(escaped, "'", "'\"'\"'");
return "'" + escaped + "'";
}
#endif

View file

@ -55,12 +55,11 @@
#include <warnings.h>
#include <algorithm>
#include <deque>
#include <numeric>
#include <optional>
#include <string>
#include <boost/algorithm/string/replace.hpp>
using node::BLOCKFILE_CHUNK_SIZE;
using node::BlockManager;
using node::BlockMap;
@ -1577,7 +1576,7 @@ static void AlertNotify(const std::string& strMessage)
std::string singleQuote("'");
std::string safeStatus = SanitizeString(strMessage);
safeStatus = singleQuote+safeStatus+singleQuote;
boost::replace_all(strCmd, "%s", safeStatus);
ReplaceAll(strCmd, "%s", safeStatus);
std::thread t(runCommand, strCmd);
t.detach(); // thread runs free

View file

@ -44,8 +44,6 @@
#include <assert.h>
#include <optional>
#include <boost/algorithm/string/replace.hpp>
using interfaces::FoundBlock;
namespace wallet {
@ -1018,14 +1016,14 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const TxState& state, const
if (!strCmd.empty())
{
boost::replace_all(strCmd, "%s", hash.GetHex());
ReplaceAll(strCmd, "%s", hash.GetHex());
if (auto* conf = wtx.state<TxStateConfirmed>())
{
boost::replace_all(strCmd, "%b", conf->confirmed_block_hash.GetHex());
boost::replace_all(strCmd, "%h", ToString(conf->confirmed_block_height));
ReplaceAll(strCmd, "%b", conf->confirmed_block_hash.GetHex());
ReplaceAll(strCmd, "%h", ToString(conf->confirmed_block_height));
} else {
boost::replace_all(strCmd, "%b", "unconfirmed");
boost::replace_all(strCmd, "%h", "-1");
ReplaceAll(strCmd, "%b", "unconfirmed");
ReplaceAll(strCmd, "%h", "-1");
}
#ifndef WIN32
// Substituting the wallet name isn't currently supported on windows
@ -1033,7 +1031,7 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const TxState& state, const
// https://github.com/bitcoin/bitcoin/pull/13339#issuecomment-537384875
// A few ways it could be implemented in the future are described in:
// https://github.com/bitcoin/bitcoin/pull/13339#issuecomment-461288094
boost::replace_all(strCmd, "%w", ShellEscape(GetName()));
ReplaceAll(strCmd, "%w", ShellEscape(GetName()));
#endif
std::thread t(runCommand, strCmd);
t.detach(); // thread runs free