diff --git a/src/Makefile.am b/src/Makefile.am index 97176d1ad1..86d9913e3d 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -995,6 +995,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 \ diff --git a/src/init.cpp b/src/init.cpp index 802eb3f4d5..43fb8dfe2a 100755 --- a/src/init.cpp +++ b/src/init.cpp @@ -93,7 +93,6 @@ #include #endif -#include #include #include // InitGlobalAssetDir @@ -1784,7 +1783,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 }); diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp index e2a7cb4066..05dbc6057f 100644 --- a/src/torcontrol.cpp +++ b/src/torcontrol.cpp @@ -24,8 +24,6 @@ #include #include -#include - #include #include #include @@ -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"); diff --git a/src/util/string.cpp b/src/util/string.cpp index 8ea3a1afc6..d05222e8b8 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -3,3 +3,10 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include + +#include + +void ReplaceAll(std::string& in_out, std::string_view search, std::string_view substitute) +{ + boost::replace_all(in_out, search, substitute); +} diff --git a/src/util/string.h b/src/util/string.h index 91681109ba..19e5d3a1fe 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -5,11 +5,11 @@ #ifndef BITCOIN_UTIL_STRING_H #define BITCOIN_UTIL_STRING_H -#include #include #include #include +#include #include #include #include @@ -18,6 +18,8 @@ #include #include +void ReplaceAll(std::string& in_out, std::string_view search, std::string_view substitute); + [[nodiscard]] inline std::vector SplitString(std::string_view str, char sep) { return spanparsing::Split(str, sep); diff --git a/src/util/system.cpp b/src/util/system.cpp index 6905483fa5..cef8c3898c 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -76,7 +76,6 @@ #include #endif -#include #include #include @@ -1298,7 +1297,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 diff --git a/src/validation.cpp b/src/validation.cpp index abeb1fe4b7..cffb435b2b 100755 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -61,12 +61,11 @@ #include #include +#include #include #include #include -#include - using node::BLOCKFILE_CHUNK_SIZE; using node::BlockManager; using node::BlockMap; @@ -1670,7 +1669,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 diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp old mode 100644 new mode 100755 index 4e3e946252..8fe5eb333d --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -48,8 +48,6 @@ #include #include -#include - #include #include #include @@ -1028,14 +1026,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()) { - 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 @@ -1043,7 +1041,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