Skip to content

Commit fa2deae

Browse files
author
MacroFake
committed
Wrap boost::replace_all
1 parent c367736 commit fa2deae

File tree

8 files changed

+22
-19
lines changed

8 files changed

+22
-19
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,7 @@ libbitcoinkernel_la_SOURCES = \
919919
util/serfloat.cpp \
920920
util/settings.cpp \
921921
util/strencodings.cpp \
922+
util/string.cpp \
922923
util/syscall_sandbox.cpp \
923924
util/syserror.cpp \
924925
util/system.cpp \

src/init.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
#include <sys/stat.h>
9393
#endif
9494

95-
#include <boost/algorithm/string/replace.hpp>
9695
#include <boost/signals2/signal.hpp>
9796

9897
#if ENABLE_ZMQ
@@ -1641,7 +1640,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
16411640
uiInterface.NotifyBlockTip_connect([block_notify](SynchronizationState sync_state, const CBlockIndex* pBlockIndex) {
16421641
if (sync_state != SynchronizationState::POST_INIT || !pBlockIndex) return;
16431642
std::string command = block_notify;
1644-
boost::replace_all(command, "%s", pBlockIndex->GetBlockHash().GetHex());
1643+
ReplaceAll(command, "%s", pBlockIndex->GetBlockHash().GetHex());
16451644
std::thread t(runCommand, command);
16461645
t.detach(); // thread runs free
16471646
});

src/torcontrol.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#include <set>
2525
#include <vector>
2626

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

src/util/string.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <util/string.h>
6+
7+
#include <boost/algorithm/string/replace.hpp>
8+
9+
void ReplaceAll(std::string& in_out, std::string_view search, std::string_view substitute)
10+
{
11+
boost::replace_all(in_out, search, substitute);
12+
}

src/util/string.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
#ifndef BITCOIN_UTIL_STRING_H
66
#define BITCOIN_UTIL_STRING_H
77

8-
#include <attributes.h>
98
#include <util/spanparsing.h>
109

1110
#include <algorithm>
1211
#include <array>
12+
#include <cstdint>
1313
#include <cstring>
1414
#include <locale>
1515
#include <sstream>
1616
#include <string>
1717
#include <string_view>
1818
#include <vector>
1919

20+
void ReplaceAll(std::string& in_out, std::string_view search, std::string_view substitute);
21+
2022
[[nodiscard]] inline std::vector<std::string> SplitString(std::string_view str, char sep)
2123
{
2224
return spanparsing::Split<std::string>(str, sep);

src/util/system.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
#include <malloc.h>
7777
#endif
7878

79-
#include <boost/algorithm/string/replace.hpp>
8079
#include <univalue.h>
8180

8281
#include <fstream>
@@ -1253,7 +1252,7 @@ fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
12531252
std::string ShellEscape(const std::string& arg)
12541253
{
12551254
std::string escaped = arg;
1256-
boost::replace_all(escaped, "'", "'\"'\"'");
1255+
ReplaceAll(escaped, "'", "'\"'\"'");
12571256
return "'" + escaped + "'";
12581257
}
12591258
#endif

src/validation.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@
5555
#include <warnings.h>
5656

5757
#include <algorithm>
58+
#include <deque>
5859
#include <numeric>
5960
#include <optional>
6061
#include <string>
6162

62-
#include <boost/algorithm/string/replace.hpp>
63-
6463
using node::BLOCKFILE_CHUNK_SIZE;
6564
using node::BlockManager;
6665
using node::BlockMap;
@@ -1577,7 +1576,7 @@ static void AlertNotify(const std::string& strMessage)
15771576
std::string singleQuote("'");
15781577
std::string safeStatus = SanitizeString(strMessage);
15791578
safeStatus = singleQuote+safeStatus+singleQuote;
1580-
boost::replace_all(strCmd, "%s", safeStatus);
1579+
ReplaceAll(strCmd, "%s", safeStatus);
15811580

15821581
std::thread t(runCommand, strCmd);
15831582
t.detach(); // thread runs free

src/wallet/wallet.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
#include <assert.h>
4545
#include <optional>
4646

47-
#include <boost/algorithm/string/replace.hpp>
48-
4947
using interfaces::FoundBlock;
5048

5149
namespace wallet {
@@ -1018,22 +1016,22 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const TxState& state, const
10181016

10191017
if (!strCmd.empty())
10201018
{
1021-
boost::replace_all(strCmd, "%s", hash.GetHex());
1019+
ReplaceAll(strCmd, "%s", hash.GetHex());
10221020
if (auto* conf = wtx.state<TxStateConfirmed>())
10231021
{
1024-
boost::replace_all(strCmd, "%b", conf->confirmed_block_hash.GetHex());
1025-
boost::replace_all(strCmd, "%h", ToString(conf->confirmed_block_height));
1022+
ReplaceAll(strCmd, "%b", conf->confirmed_block_hash.GetHex());
1023+
ReplaceAll(strCmd, "%h", ToString(conf->confirmed_block_height));
10261024
} else {
1027-
boost::replace_all(strCmd, "%b", "unconfirmed");
1028-
boost::replace_all(strCmd, "%h", "-1");
1025+
ReplaceAll(strCmd, "%b", "unconfirmed");
1026+
ReplaceAll(strCmd, "%h", "-1");
10291027
}
10301028
#ifndef WIN32
10311029
// Substituting the wallet name isn't currently supported on windows
10321030
// because windows shell escaping has not been implemented yet:
10331031
// https://github.com/bitcoin/bitcoin/pull/13339#issuecomment-537384875
10341032
// A few ways it could be implemented in the future are described in:
10351033
// https://github.com/bitcoin/bitcoin/pull/13339#issuecomment-461288094
1036-
boost::replace_all(strCmd, "%w", ShellEscape(GetName()));
1034+
ReplaceAll(strCmd, "%w", ShellEscape(GetName()));
10371035
#endif
10381036
std::thread t(runCommand, strCmd);
10391037
t.detach(); // thread runs free

0 commit comments

Comments
 (0)