Wrap boost::replace_all

This commit is contained in:
MacroFake committed 2022-05-05 20:50:24 +02:00
1 parent c367736f85
commit fa2deae2a8
8 files changed
+22 -19

No files matched your search

+1
View File
@@ -919,6 +919,7 @@ libbitcoinkernel_la_SOURCES = \
util/serfloat.cpp \ util/serfloat.cpp \
util/settings.cpp \ util/settings.cpp \
util/strencodings.cpp \ util/strencodings.cpp \
util/string.cpp \
util/syscall_sandbox.cpp \ util/syscall_sandbox.cpp \
util/syserror.cpp \ util/syserror.cpp \
util/system.cpp \ util/system.cpp \
+1 -2
View File
@@ -92,7 +92,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#endif #endif
#include <boost/algorithm/string/replace.hpp>
#include <boost/signals2/signal.hpp> #include <boost/signals2/signal.hpp>
#if ENABLE_ZMQ #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) { uiInterface.NotifyBlockTip_connect([block_notify](SynchronizationState sync_state, const CBlockIndex* pBlockIndex) {
if (sync_state != SynchronizationState::POST_INIT || !pBlockIndex) return; if (sync_state != SynchronizationState::POST_INIT || !pBlockIndex) return;
std::string command = block_notify; std::string command = block_notify;
boost::replace_all(command, "%s", pBlockIndex->GetBlockHash().GetHex()); ReplaceAll(command, "%s", pBlockIndex->GetBlockHash().GetHex());
std::thread t(runCommand, command); std::thread t(runCommand, command);
t.detach(); // thread runs free t.detach(); // thread runs free
}); });
+1 -3
View File
@@ -24,8 +24,6 @@
#include <set> #include <set>
#include <vector> #include <vector>
#include <boost/algorithm/string/replace.hpp>
#include <event2/buffer.h> #include <event2/buffer.h>
#include <event2/bufferevent.h> #include <event2/bufferevent.h>
#include <event2/event.h> #include <event2/event.h>
@@ -566,7 +564,7 @@ void TorController::protocolinfo_cb(TorControlConnection& _conn, const TorContro
if (!torpassword.empty()) { if (!torpassword.empty()) {
if (methods.count("HASHEDPASSWORD")) { if (methods.count("HASHEDPASSWORD")) {
LogPrint(BCLog::TOR, "tor: Using HASHEDPASSWORD authentication\n"); 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)); _conn.Command("AUTHENTICATE \"" + torpassword + "\"", std::bind(&TorController::auth_cb, this, std::placeholders::_1, std::placeholders::_2));
} else { } else {
LogPrintf("tor: Password provided with -torpassword, but HASHEDPASSWORD authentication is not available\n"); LogPrintf("tor: Password provided with -torpassword, but HASHEDPASSWORD authentication is not available\n");
+7
View File
@@ -3,3 +3,10 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <util/string.h> #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);
}
+3 -1
View File
@@ -5,11 +5,11 @@
#ifndef BITCOIN_UTIL_STRING_H #ifndef BITCOIN_UTIL_STRING_H
#define BITCOIN_UTIL_STRING_H #define BITCOIN_UTIL_STRING_H
#include <attributes.h>
#include <util/spanparsing.h> #include <util/spanparsing.h>
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <cstdint>
#include <cstring> #include <cstring>
#include <locale> #include <locale>
#include <sstream> #include <sstream>
@@ -17,6 +17,8 @@
#include <string_view> #include <string_view>
#include <vector> #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) [[nodiscard]] inline std::vector<std::string> SplitString(std::string_view str, char sep)
{ {
return spanparsing::Split<std::string>(str, sep); return spanparsing::Split<std::string>(str, sep);
+1 -2
View File
@@ -76,7 +76,6 @@
#include <malloc.h> #include <malloc.h>
#endif #endif
#include <boost/algorithm/string/replace.hpp>
#include <univalue.h> #include <univalue.h>
#include <fstream> #include <fstream>
@@ -1253,7 +1252,7 @@ fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
std::string ShellEscape(const std::string& arg) std::string ShellEscape(const std::string& arg)
{ {
std::string escaped = arg; std::string escaped = arg;
boost::replace_all(escaped, "'", "'\"'\"'"); ReplaceAll(escaped, "'", "'\"'\"'");
return "'" + escaped + "'"; return "'" + escaped + "'";
} }
#endif #endif
+2 -3
View File
@@ -55,12 +55,11 @@
#include <warnings.h> #include <warnings.h>
#include <algorithm> #include <algorithm>
#include <deque>
#include <numeric> #include <numeric>
#include <optional> #include <optional>
#include <string> #include <string>
#include <boost/algorithm/string/replace.hpp>
using node::BLOCKFILE_CHUNK_SIZE; using node::BLOCKFILE_CHUNK_SIZE;
using node::BlockManager; using node::BlockManager;
using node::BlockMap; using node::BlockMap;
@@ -1577,7 +1576,7 @@ static void AlertNotify(const std::string& strMessage)
std::string singleQuote("'"); std::string singleQuote("'");
std::string safeStatus = SanitizeString(strMessage); std::string safeStatus = SanitizeString(strMessage);
safeStatus = singleQuote+safeStatus+singleQuote; safeStatus = singleQuote+safeStatus+singleQuote;
boost::replace_all(strCmd, "%s", safeStatus); ReplaceAll(strCmd, "%s", safeStatus);
std::thread t(runCommand, strCmd); std::thread t(runCommand, strCmd);
t.detach(); // thread runs free t.detach(); // thread runs free
+6 -8
View File
@@ -44,8 +44,6 @@
#include <assert.h> #include <assert.h>
#include <optional> #include <optional>
#include <boost/algorithm/string/replace.hpp>
using interfaces::FoundBlock; using interfaces::FoundBlock;
namespace wallet { namespace wallet {
@@ -1018,14 +1016,14 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const TxState& state, const
if (!strCmd.empty()) if (!strCmd.empty())
{ {
boost::replace_all(strCmd, "%s", hash.GetHex()); ReplaceAll(strCmd, "%s", hash.GetHex());
if (auto* conf = wtx.state<TxStateConfirmed>()) if (auto* conf = wtx.state<TxStateConfirmed>())
{ {
boost::replace_all(strCmd, "%b", conf->confirmed_block_hash.GetHex()); ReplaceAll(strCmd, "%b", conf->confirmed_block_hash.GetHex());
boost::replace_all(strCmd, "%h", ToString(conf->confirmed_block_height)); ReplaceAll(strCmd, "%h", ToString(conf->confirmed_block_height));
} else { } else {
boost::replace_all(strCmd, "%b", "unconfirmed"); ReplaceAll(strCmd, "%b", "unconfirmed");
boost::replace_all(strCmd, "%h", "-1"); ReplaceAll(strCmd, "%h", "-1");
} }
#ifndef WIN32 #ifndef WIN32
// Substituting the wallet name isn't currently supported on windows // 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 // https://github.com/bitcoin/bitcoin/pull/13339#issuecomment-537384875
// A few ways it could be implemented in the future are described in: // A few ways it could be implemented in the future are described in:
// https://github.com/bitcoin/bitcoin/pull/13339#issuecomment-461288094 // https://github.com/bitcoin/bitcoin/pull/13339#issuecomment-461288094
boost::replace_all(strCmd, "%w", ShellEscape(GetName())); ReplaceAll(strCmd, "%w", ShellEscape(GetName()));
#endif #endif
std::thread t(runCommand, strCmd); std::thread t(runCommand, strCmd);
t.detach(); // thread runs free t.detach(); // thread runs free