From 4f74c59334d496f28e1a5c0d84c412f9020b366f Mon Sep 17 00:00:00 2001 From: Ryan Ofsky Date: Wed, 6 Dec 2023 15:13:39 -0500 Subject: [PATCH] util: Move util/string.h functions to util namespace There are no changes to behavior. Changes in this commit are all additions, and are easiest to review using "git diff -U0 --word-diff-regex=." options. Motivation for this change is to keep util functions with really generic names like "Split" and "Join" out of the global namespace so it is easier to see where these functions are defined, and so they don't interfere with function overloading, especially since the util library is a dependency of the kernel library and intended to be used with external code. --- src/base58.cpp | 2 ++ src/bench/bench.cpp | 1 + src/bench/bench_bitcoin.cpp | 2 ++ src/bitcoin-cli.cpp | 3 +++ src/bitcoin-tx.cpp | 5 +++++ src/bitcoin-wallet.cpp | 2 ++ src/blockfilter.cpp | 2 ++ src/chainparams.cpp | 2 ++ src/clientversion.cpp | 2 ++ src/common/config.cpp | 3 +++ src/common/messages.cpp | 1 + src/common/system.cpp | 2 ++ src/core_read.cpp | 2 ++ src/httprpc.cpp | 3 +++ src/i2p.cpp | 2 ++ src/init.cpp | 3 +++ src/init/common.cpp | 2 ++ src/logging.cpp | 4 ++++ src/logging.h | 2 +- src/netaddress.cpp | 3 +++ src/netaddress.h | 6 +++--- src/netbase.cpp | 2 ++ src/node/interface_ui.cpp | 2 ++ src/node/interfaces.cpp | 1 + src/node/kernel_notifications.cpp | 2 ++ src/qt/bitcoin.cpp | 2 ++ src/qt/recentrequeststablemodel.cpp | 2 ++ src/qt/rpcconsole.cpp | 2 ++ src/qt/walletcontroller.cpp | 1 + src/rest.cpp | 1 + src/rpc/blockchain.cpp | 3 +++ src/rpc/mempool.cpp | 1 + src/rpc/mining.cpp | 1 + src/rpc/net.cpp | 2 ++ src/rpc/server.cpp | 2 ++ src/rpc/util.cpp | 5 ++++- src/script/descriptor.cpp | 2 ++ src/script/miniscript.h | 10 +++++----- src/test/addrman_tests.cpp | 1 + src/test/argsman_tests.cpp | 2 ++ src/test/blockchain_tests.cpp | 2 ++ src/test/dbwrapper_tests.cpp | 2 ++ src/test/descriptor_tests.cpp | 2 ++ src/test/fuzz/base_encode_decode.cpp | 3 +++ src/test/fuzz/integer.cpp | 2 ++ src/test/fuzz/locale.cpp | 4 ++-- src/test/fuzz/rpc.cpp | 3 +++ src/test/fuzz/script_assets_test_minimizer.cpp | 2 ++ src/test/fuzz/script_parsing.cpp | 2 ++ src/test/fuzz/string.cpp | 5 +++++ src/test/fuzz/tx_pool.cpp | 1 + src/test/getarg_tests.cpp | 2 ++ src/test/key_tests.cpp | 2 ++ src/test/logging_tests.cpp | 3 +++ src/test/net_tests.cpp | 1 + src/test/rpc_tests.cpp | 2 ++ src/test/settings_tests.cpp | 2 ++ src/test/transaction_tests.cpp | 3 +++ src/test/util_tests.cpp | 9 +++++++++ src/test/util_threadnames_tests.cpp | 2 ++ src/torcontrol.cpp | 4 ++++ src/util/moneystr.cpp | 3 +++ src/util/strencodings.h | 2 +- src/util/string.cpp | 2 ++ src/util/string.h | 2 ++ src/wallet/load.cpp | 2 ++ src/wallet/rpc/backup.cpp | 1 + src/wallet/scriptpubkeyman.cpp | 1 + src/wallet/transaction.h | 2 +- src/wallet/wallet.cpp | 2 ++ 70 files changed, 159 insertions(+), 14 deletions(-) diff --git a/src/base58.cpp b/src/base58.cpp index cf5d62f164f..f9165ed55f7 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -14,6 +14,8 @@ #include +using util::ContainsNoNUL; + /** All alphanumeric characters except for "0", "I", "O", and "l" */ static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; static const int8_t mapBase58[256] = { diff --git a/src/bench/bench.cpp b/src/bench/bench.cpp index a13a693ad77..733f8085ca7 100644 --- a/src/bench/bench.cpp +++ b/src/bench/bench.cpp @@ -18,6 +18,7 @@ #include using namespace std::chrono_literals; +using util::Join; const std::function G_TEST_LOG_FUN{}; diff --git a/src/bench/bench_bitcoin.cpp b/src/bench/bench_bitcoin.cpp index 8c421c3fec6..a1b880e40b0 100644 --- a/src/bench/bench_bitcoin.cpp +++ b/src/bench/bench_bitcoin.cpp @@ -16,6 +16,8 @@ #include #include +using util::SplitString; + static const char* DEFAULT_BENCH_FILTER = ".*"; static constexpr int64_t DEFAULT_MIN_TIME_MS{10}; /** Priority level default value, run "all" priority levels */ diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index b7e4e641035..2d9689fc06c 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -42,6 +42,9 @@ #include #include +using util::Join; +using util::ToString; + // The server returns time values from a mockable system clock, but it is not // trivial to get the mocked time from the server, nor is it needed for now, so // just use a plain system_clock. diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index cfac50e0907..935218acbd9 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -32,6 +32,11 @@ #include #include +using util::SplitString; +using util::ToString; +using util::TrimString; +using util::TrimStringView; + static bool fCreateBlank; static std::map registers; static const int CONTINUE_EXECUTION=-1; diff --git a/src/bitcoin-wallet.cpp b/src/bitcoin-wallet.cpp index e6d20b55c23..861c130530e 100644 --- a/src/bitcoin-wallet.cpp +++ b/src/bitcoin-wallet.cpp @@ -24,6 +24,8 @@ #include #include +using util::Join; + const std::function G_TRANSLATION_FUN = nullptr; static void SetupWalletToolArgs(ArgsManager& argsman) diff --git a/src/blockfilter.cpp b/src/blockfilter.cpp index e045b88513e..5e6702ccc3c 100644 --- a/src/blockfilter.cpp +++ b/src/blockfilter.cpp @@ -16,6 +16,8 @@ #include #include +using util::Join; + static const std::map g_filter_types = { {BlockFilterType::BASIC, "basic"}, }; diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 539578085b5..5d4401b719c 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -21,6 +21,8 @@ #include #include +using util::SplitString; + void ReadSigNetArgs(const ArgsManager& args, CChainParams::SigNetOptions& options) { if (args.IsArgSet("-signetseednode")) { diff --git a/src/clientversion.cpp b/src/clientversion.cpp index 6b9727a158b..e52703c8bf1 100644 --- a/src/clientversion.cpp +++ b/src/clientversion.cpp @@ -13,6 +13,8 @@ #include #include +using util::Join; + /** * Name of client reported in the 'version' message. Report the same name * for both bitcoind and bitcoin-qt, to make it harder for attackers to diff --git a/src/common/config.cpp b/src/common/config.cpp index 1c85273f69c..98223fc3e3a 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -27,6 +27,9 @@ #include #include +using util::TrimString; +using util::TrimStringView; + static bool GetConfigOptions(std::istream& stream, const std::string& filepath, std::string& error, std::vector>& options, std::list& sections) { std::string str, prefix; diff --git a/src/common/messages.cpp b/src/common/messages.cpp index c547ccb59d7..9e88ca8b0f9 100644 --- a/src/common/messages.cpp +++ b/src/common/messages.cpp @@ -20,6 +20,7 @@ #include using node::TransactionError; +using util::Join; namespace common { std::string StringForFeeReason(FeeReason reason) diff --git a/src/common/system.cpp b/src/common/system.cpp index ddd0feda3b8..6d04c8a7bc3 100644 --- a/src/common/system.cpp +++ b/src/common/system.cpp @@ -28,6 +28,8 @@ #include #include +using util::ReplaceAll; + // Application startup time (used for uptime calculation) const int64_t nStartupTime = GetTime(); diff --git a/src/core_read.cpp b/src/core_read.cpp index 5956d9df5fa..114f92fc458 100644 --- a/src/core_read.cpp +++ b/src/core_read.cpp @@ -16,6 +16,8 @@ #include #include +using util::SplitString; + namespace { class OpCodeParser { diff --git a/src/httprpc.cpp b/src/httprpc.cpp index 3eb34dbe6ab..128597157d6 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -23,6 +23,9 @@ #include #include +using util::SplitString; +using util::TrimStringView; + /** WWW-Authenticate to present with 401 Unauthorized response */ static const char* WWW_AUTH_HEADER_DATA = "Basic realm=\"jsonrpc\""; diff --git a/src/i2p.cpp b/src/i2p.cpp index cb24a93db9c..a907cfeacb6 100644 --- a/src/i2p.cpp +++ b/src/i2p.cpp @@ -26,6 +26,8 @@ #include #include +using util::Split; + namespace i2p { /** diff --git a/src/init.cpp b/src/init.cpp index 080c79f3be9..759cc23c9bd 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -137,6 +137,9 @@ using node::NodeContext; using node::ShouldPersistMempool; using node::ImportBlocks; using node::VerifyLoadedChainstate; +using util::Join; +using util::ReplaceAll; +using util::ToString; static constexpr bool DEFAULT_PROXYRANDOMIZE{true}; static constexpr bool DEFAULT_REST_ENABLE{false}; diff --git a/src/init/common.cpp b/src/init/common.cpp index 3a6df3e8bd5..180cd62590b 100644 --- a/src/init/common.cpp +++ b/src/init/common.cpp @@ -20,6 +20,8 @@ #include #include +using util::SplitString; + namespace init { void AddLoggingArgs(ArgsManager& argsman) { diff --git a/src/logging.cpp b/src/logging.cpp index 578650f856e..a9fea433be4 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -13,6 +13,10 @@ #include #include +using util::Join; +using util::RemovePrefix; +using util::ToString; + const char * const DEFAULT_DEBUGLOGFILE = "debug.log"; constexpr auto MAX_USER_SETABLE_SEVERITY_LEVEL{BCLog::Level::Info}; diff --git a/src/logging.h b/src/logging.h index cfef65221fd..fe6b7051baf 100644 --- a/src/logging.h +++ b/src/logging.h @@ -189,7 +189,7 @@ namespace BCLog { /** Returns a string with the log categories in alphabetical order. */ std::string LogCategoriesString() const { - return Join(LogCategoriesList(), ", ", [&](const LogCategory& i) { return i.category; }); + return util::Join(LogCategoriesList(), ", ", [&](const LogCategory& i) { return i.category; }); }; //! Returns a string with all user-selectable log levels. diff --git a/src/netaddress.cpp b/src/netaddress.cpp index 74ab6dd8d87..00534648229 100644 --- a/src/netaddress.cpp +++ b/src/netaddress.cpp @@ -20,6 +20,9 @@ #include #include +using util::ContainsNoNUL; +using util::HasPrefix; + CNetAddr::BIP155Network CNetAddr::GetBIP155Network() const { switch (m_net) { diff --git a/src/netaddress.h b/src/netaddress.h index ea2d14336e4..52fecada1c9 100644 --- a/src/netaddress.h +++ b/src/netaddress.h @@ -448,7 +448,7 @@ private: // Recognize NET_INTERNAL embedded in IPv6, such addresses are not // gossiped but could be coming from addrman, when unserializing from // disk. - if (HasPrefix(m_addr, INTERNAL_IN_IPV6_PREFIX)) { + if (util::HasPrefix(m_addr, INTERNAL_IN_IPV6_PREFIX)) { m_net = NET_INTERNAL; memmove(m_addr.data(), m_addr.data() + INTERNAL_IN_IPV6_PREFIX.size(), ADDR_INTERNAL_SIZE); @@ -456,8 +456,8 @@ private: return; } - if (!HasPrefix(m_addr, IPV4_IN_IPV6_PREFIX) && - !HasPrefix(m_addr, TORV2_IN_IPV6_PREFIX)) { + if (!util::HasPrefix(m_addr, IPV4_IN_IPV6_PREFIX) && + !util::HasPrefix(m_addr, TORV2_IN_IPV6_PREFIX)) { return; } diff --git a/src/netbase.cpp b/src/netbase.cpp index e231766487f..ff46061d3d8 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -27,6 +27,8 @@ #include #endif +using util::ContainsNoNUL; + // Settings static GlobalMutex g_proxyinfo_mutex; static Proxy proxyInfo[NET_MAX] GUARDED_BY(g_proxyinfo_mutex); diff --git a/src/node/interface_ui.cpp b/src/node/interface_ui.cpp index 9dd1e7d9cf9..4f4d240d1b5 100644 --- a/src/node/interface_ui.cpp +++ b/src/node/interface_ui.cpp @@ -10,6 +10,8 @@ #include #include +using util::MakeUnorderedList; + CClientUIInterface uiInterface; struct UISignals { diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 164a3b97da9..19f4aaf9c48 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -71,6 +71,7 @@ using interfaces::Handler; using interfaces::MakeSignalHandler; using interfaces::Node; using interfaces::WalletLoader; +using util::Join; namespace node { // All members of the classes in this namespace are intentionally public, as the diff --git a/src/node/kernel_notifications.cpp b/src/node/kernel_notifications.cpp index e326d4a1f20..1f07014ee22 100644 --- a/src/node/kernel_notifications.cpp +++ b/src/node/kernel_notifications.cpp @@ -24,6 +24,8 @@ #include #include +using util::ReplaceAll; + static void AlertNotify(const std::string& strMessage) { uiInterface.NotifyAlertChanged(); diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 44a858c16b3..6c5725533b8 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -85,6 +85,8 @@ Q_DECLARE_METATYPE(uint256) Q_DECLARE_METATYPE(wallet::AddressPurpose) #endif // ENABLE_WALLET +using util::MakeUnorderedList; + static void RegisterMetaTypes() { // Register meta types used for QMetaObject::invokeMethod and Qt::QueuedConnection diff --git a/src/qt/recentrequeststablemodel.cpp b/src/qt/recentrequeststablemodel.cpp index 52d4e45d49f..a8d54cdc0c6 100644 --- a/src/qt/recentrequeststablemodel.cpp +++ b/src/qt/recentrequeststablemodel.cpp @@ -20,6 +20,8 @@ #include #include +using util::ToString; + RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) : QAbstractTableModel(parent), walletModel(parent) { diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 702ca44395d..edf417a7cbf 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -48,6 +48,8 @@ #include +using util::Join; + const int CONSOLE_HISTORY = 50; const int INITIAL_TRAFFIC_GRAPH_MINS = 30; const QSize FONT_RANGE(4, 40); diff --git a/src/qt/walletcontroller.cpp b/src/qt/walletcontroller.cpp index c7fe62f4e91..34b47c90a3b 100644 --- a/src/qt/walletcontroller.cpp +++ b/src/qt/walletcontroller.cpp @@ -30,6 +30,7 @@ #include #include +using util::Join; using wallet::WALLET_FLAG_BLANK_WALLET; using wallet::WALLET_FLAG_DESCRIPTORS; using wallet::WALLET_FLAG_DISABLE_PRIVATE_KEYS; diff --git a/src/rest.cpp b/src/rest.cpp index 9fc5d4af047..7857abea92f 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -39,6 +39,7 @@ using node::GetTransaction; using node::NodeContext; +using util::SplitString; static const size_t MAX_GETUTXOS_OUTPOINTS = 15; //allow a max of 15 outpoints to be queried at once static constexpr unsigned int MAX_REST_HEADERS_RESULTS = 2000; diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 1abaeafb2af..f2b484d0fa7 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -60,6 +60,9 @@ using kernel::CoinStatsHashType; using node::BlockManager; using node::NodeContext; using node::SnapshotMetadata; +using util::Join; +using util::MakeUnorderedList; +using util::ToString; struct CUpdatedBlock { diff --git a/src/rpc/mempool.cpp b/src/rpc/mempool.cpp index 17d576920bd..655b3f1113c 100644 --- a/src/rpc/mempool.cpp +++ b/src/rpc/mempool.cpp @@ -34,6 +34,7 @@ using node::DEFAULT_MAX_RAW_TX_FEE_RATE; using node::MempoolPath; using node::NodeContext; using node::TransactionError; +using util::ToString; static RPCHelpMan sendrawtransaction() { diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 2391392bd75..3a79f7b5eee 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -47,6 +47,7 @@ using node::CBlockTemplate; using node::NodeContext; using node::RegenerateCommitments; using node::UpdateTime; +using util::ToString; /** * Return average network hashes per second based on the last 'lookup' blocks, diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 59397aa84dd..780229093f4 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -35,6 +35,8 @@ #include using node::NodeContext; +using util::Join; +using util::TrimString; const std::vector CONNECTION_TYPE_DOC{ "outbound-full-relay (default automatic connections)", diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 1ed406354af..411f535da8a 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -27,6 +27,8 @@ #include #include +using util::SplitString; + static GlobalMutex g_rpc_warmup_mutex; static std::atomic g_rpc_running{false}; static bool fRPCInWarmup GUARDED_BY(g_rpc_warmup_mutex) = true; diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index d18b28fa1f8..ad361746614 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -37,6 +37,9 @@ using common::PSBTError; using common::PSBTErrorString; using common::TransactionErrorString; using node::TransactionError; +using util::Join; +using util::SplitString; +using util::TrimString; const std::string UNIX_EPOCH_TIME = "UNIX epoch time"; const std::string EXAMPLE_ADDRESS[2] = {"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl", "bc1q02ad21edsxd23d32dfgqqsz4vv4nmtfzuklhy3"}; @@ -796,7 +799,7 @@ std::string RPCHelpMan::ToString() const if (arg.m_opts.hidden) break; // Any arg that follows is also hidden // Push named argument name and description - sections.m_sections.emplace_back(::ToString(i + 1) + ". " + arg.GetFirstName(), arg.ToDescriptionString(/*is_named_arg=*/true)); + sections.m_sections.emplace_back(util::ToString(i + 1) + ". " + arg.GetFirstName(), arg.ToDescriptionString(/*is_named_arg=*/true)); sections.m_max_pad = std::max(sections.m_max_pad, sections.m_sections.back().m_left.size()); // Recursively push nested args diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index 3bc0730c732..0987db194c4 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -27,6 +27,8 @@ #include #include +using util::Split; + namespace { //////////////////////////////////////////////////////////////////////////// diff --git a/src/script/miniscript.h b/src/script/miniscript.h index 17e0cf5c8da..21e2789502d 100644 --- a/src/script/miniscript.h +++ b/src/script/miniscript.h @@ -863,8 +863,8 @@ public: if (!key_str) return {}; return std::move(ret) + "pk_h(" + std::move(*key_str) + ")"; } - case Fragment::AFTER: return std::move(ret) + "after(" + ::ToString(node.k) + ")"; - case Fragment::OLDER: return std::move(ret) + "older(" + ::ToString(node.k) + ")"; + case Fragment::AFTER: return std::move(ret) + "after(" + util::ToString(node.k) + ")"; + case Fragment::OLDER: return std::move(ret) + "older(" + util::ToString(node.k) + ")"; case Fragment::HASH256: return std::move(ret) + "hash256(" + HexStr(node.data) + ")"; case Fragment::HASH160: return std::move(ret) + "hash160(" + HexStr(node.data) + ")"; case Fragment::SHA256: return std::move(ret) + "sha256(" + HexStr(node.data) + ")"; @@ -883,7 +883,7 @@ public: return std::move(ret) + "andor(" + std::move(subs[0]) + "," + std::move(subs[1]) + "," + std::move(subs[2]) + ")"; case Fragment::MULTI: { CHECK_NONFATAL(!is_tapscript); - auto str = std::move(ret) + "multi(" + ::ToString(node.k); + auto str = std::move(ret) + "multi(" + util::ToString(node.k); for (const auto& key : node.keys) { auto key_str = ctx.ToString(key); if (!key_str) return {}; @@ -893,7 +893,7 @@ public: } case Fragment::MULTI_A: { CHECK_NONFATAL(is_tapscript); - auto str = std::move(ret) + "multi_a(" + ::ToString(node.k); + auto str = std::move(ret) + "multi_a(" + util::ToString(node.k); for (const auto& key : node.keys) { auto key_str = ctx.ToString(key); if (!key_str) return {}; @@ -902,7 +902,7 @@ public: return std::move(str) + ")"; } case Fragment::THRESH: { - auto str = std::move(ret) + "thresh(" + ::ToString(node.k); + auto str = std::move(ret) + "thresh(" + util::ToString(node.k); for (auto& sub : subs) { str += "," + std::move(sub); } diff --git a/src/test/addrman_tests.cpp b/src/test/addrman_tests.cpp index 9668a854842..e5d25637bd4 100644 --- a/src/test/addrman_tests.cpp +++ b/src/test/addrman_tests.cpp @@ -22,6 +22,7 @@ using namespace std::literals; using node::NodeContext; +using util::ToString; static NetGroupManager EMPTY_NETGROUPMAN{std::vector()}; static const bool DETERMINISTIC{true}; diff --git a/src/test/argsman_tests.cpp b/src/test/argsman_tests.cpp index 340208a1c91..5f0318e8c44 100644 --- a/src/test/argsman_tests.cpp +++ b/src/test/argsman_tests.cpp @@ -20,6 +20,8 @@ #include +using util::ToString; + BOOST_FIXTURE_TEST_SUITE(argsman_tests, BasicTestingSetup) BOOST_AUTO_TEST_CASE(util_datadir) diff --git a/src/test/blockchain_tests.cpp b/src/test/blockchain_tests.cpp index be515a9eac2..9b8f419290c 100644 --- a/src/test/blockchain_tests.cpp +++ b/src/test/blockchain_tests.cpp @@ -11,6 +11,8 @@ #include +using util::ToString; + /* Equality between doubles is imprecise. Comparison should be done * with a small threshold of tolerance, rather than exact equality. */ diff --git a/src/test/dbwrapper_tests.cpp b/src/test/dbwrapper_tests.cpp index 723a1ceee3e..167e4be2880 100644 --- a/src/test/dbwrapper_tests.cpp +++ b/src/test/dbwrapper_tests.cpp @@ -12,6 +12,8 @@ #include +using util::ToString; + // Test if a string consists entirely of null characters static bool is_null_key(const std::vector& key) { bool isnull = true; diff --git a/src/test/descriptor_tests.cpp b/src/test/descriptor_tests.cpp index 8556d4e2182..e6821dd3218 100644 --- a/src/test/descriptor_tests.cpp +++ b/src/test/descriptor_tests.cpp @@ -15,6 +15,8 @@ #include #include +using util::Split; + namespace { void CheckUnparsable(const std::string& prv, const std::string& pub, const std::string& expected_error) diff --git a/src/test/fuzz/base_encode_decode.cpp b/src/test/fuzz/base_encode_decode.cpp index d322416d348..0cc8cb58862 100644 --- a/src/test/fuzz/base_encode_decode.cpp +++ b/src/test/fuzz/base_encode_decode.cpp @@ -14,6 +14,9 @@ #include #include +using util::TrimString; +using util::TrimStringView; + FUZZ_TARGET(base_encode_decode) { const std::string random_encoded_string(buffer.begin(), buffer.end()); diff --git a/src/test/fuzz/integer.cpp b/src/test/fuzz/integer.cpp index db246bb84ee..8f1d7b6d454 100644 --- a/src/test/fuzz/integer.cpp +++ b/src/test/fuzz/integer.cpp @@ -40,6 +40,8 @@ #include #include +using util::ToString; + void initialize_integer() { SelectParams(ChainType::REGTEST); diff --git a/src/test/fuzz/locale.cpp b/src/test/fuzz/locale.cpp index 0f2985b5044..68db8422477 100644 --- a/src/test/fuzz/locale.cpp +++ b/src/test/fuzz/locale.cpp @@ -51,7 +51,7 @@ FUZZ_TARGET(locale) int64_t parseint64_out_without_locale; const bool parseint64_without_locale = ParseInt64(random_string, &parseint64_out_without_locale); const int64_t random_int64 = fuzzed_data_provider.ConsumeIntegral(); - const std::string tostring_without_locale = ToString(random_int64); + const std::string tostring_without_locale = util::ToString(random_int64); // The variable `random_int32` is no longer used, but the harness still needs to // consume the same data that it did previously to not invalidate existing seeds. const int32_t random_int32 = fuzzed_data_provider.ConsumeIntegral(); @@ -75,7 +75,7 @@ FUZZ_TARGET(locale) if (parseint64_without_locale) { assert(parseint64_out_without_locale == parseint64_out_with_locale); } - const std::string tostring_with_locale = ToString(random_int64); + const std::string tostring_with_locale = util::ToString(random_int64); assert(tostring_without_locale == tostring_with_locale); const std::string strprintf_int_with_locale = strprintf("%d", random_int64); assert(strprintf_int_without_locale == strprintf_int_with_locale); diff --git a/src/test/fuzz/rpc.cpp b/src/test/fuzz/rpc.cpp index 2325bf09413..4e52c1c0911 100644 --- a/src/test/fuzz/rpc.cpp +++ b/src/test/fuzz/rpc.cpp @@ -36,6 +36,9 @@ #include enum class ChainType; +using util::Join; +using util::ToString; + namespace { struct RPCFuzzTestingSetup : public TestingSetup { RPCFuzzTestingSetup(const ChainType chain_type, const std::vector& extra_args) : TestingSetup{chain_type, extra_args} diff --git a/src/test/fuzz/script_assets_test_minimizer.cpp b/src/test/fuzz/script_assets_test_minimizer.cpp index 511b581f606..5a8b599df6f 100644 --- a/src/test/fuzz/script_assets_test_minimizer.cpp +++ b/src/test/fuzz/script_assets_test_minimizer.cpp @@ -17,6 +17,8 @@ #include #include +using util::SplitString; + // This fuzz "test" can be used to minimize test cases for script_assets_test in // src/test/script_tests.cpp. While it written as a fuzz test, and can be used as such, // fuzzing the inputs is unlikely to construct useful test cases. diff --git a/src/test/fuzz/script_parsing.cpp b/src/test/fuzz/script_parsing.cpp index 77f4503d47b..d29a6ea90c4 100644 --- a/src/test/fuzz/script_parsing.cpp +++ b/src/test/fuzz/script_parsing.cpp @@ -7,6 +7,8 @@ #include #include +using util::Split; + FUZZ_TARGET(script_parsing) { FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); diff --git a/src/test/fuzz/string.cpp b/src/test/fuzz/string.cpp index 5b1353c70bb..5b822b03f6b 100644 --- a/src/test/fuzz/string.cpp +++ b/src/test/fuzz/string.cpp @@ -40,6 +40,11 @@ using common::AmountErrMsg; using common::AmountHighWarn; using common::FeeModeFromString; using common::ResolveErrMsg; +using util::ContainsNoNUL; +using util::Join; +using util::RemovePrefix; +using util::SplitString; +using util::TrimString; FUZZ_TARGET(string) { diff --git a/src/test/fuzz/tx_pool.cpp b/src/test/fuzz/tx_pool.cpp index 9f0aedf29b8..37fa216ff2a 100644 --- a/src/test/fuzz/tx_pool.cpp +++ b/src/test/fuzz/tx_pool.cpp @@ -21,6 +21,7 @@ using node::BlockAssembler; using node::NodeContext; +using util::ToString; namespace { diff --git a/src/test/getarg_tests.cpp b/src/test/getarg_tests.cpp index c73b675388d..8734735fd5b 100644 --- a/src/test/getarg_tests.cpp +++ b/src/test/getarg_tests.cpp @@ -16,6 +16,8 @@ #include +using util::SplitString; + BOOST_FIXTURE_TEST_SUITE(getarg_tests, BasicTestingSetup) void ResetArgs(ArgsManager& local_args, const std::string& strArg) diff --git a/src/test/key_tests.cpp b/src/test/key_tests.cpp index 86a8d17a764..63a82dca6d6 100644 --- a/src/test/key_tests.cpp +++ b/src/test/key_tests.cpp @@ -18,6 +18,8 @@ #include +using util::ToString; + static const std::string strSecret1 = "5HxWvvfubhXpYYpS3tJkw6fq9jE9j18THftkZjHHfmFiWtmAbrj"; static const std::string strSecret2 = "5KC4ejrDjv152FGwP386VD1i2NYc5KkfSMyv1nGy1VGDxGHqVY3"; static const std::string strSecret1C = "Kwr371tjA9u2rFSMZjTNun2PXXP3WPZu2afRHTcta6KxEUdm1vEw"; diff --git a/src/test/logging_tests.cpp b/src/test/logging_tests.cpp index 88e3ec94b7c..cebd000df86 100644 --- a/src/test/logging_tests.cpp +++ b/src/test/logging_tests.cpp @@ -17,6 +17,9 @@ #include +using util::SplitString; +using util::TrimString; + BOOST_FIXTURE_TEST_SUITE(logging_tests, BasicTestingSetup) static void ResetLogger() diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp index b9dff966101..46a6a33b345 100644 --- a/src/test/net_tests.cpp +++ b/src/test/net_tests.cpp @@ -32,6 +32,7 @@ #include using namespace std::literals; +using util::ToString; BOOST_FIXTURE_TEST_SUITE(net_tests, RegTestingSetup) diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp index 1c7d11d8a43..a1ff208d9ae 100644 --- a/src/test/rpc_tests.cpp +++ b/src/test/rpc_tests.cpp @@ -17,6 +17,8 @@ #include +using util::SplitString; + static UniValue JSON(std::string_view json) { UniValue value; diff --git a/src/test/settings_tests.cpp b/src/test/settings_tests.cpp index 41190b35798..95f38fc0ce6 100644 --- a/src/test/settings_tests.cpp +++ b/src/test/settings_tests.cpp @@ -21,6 +21,8 @@ #include #include +using util::ToString; + inline bool operator==(const common::SettingsValue& a, const common::SettingsValue& b) { return a.write() == b.write(); diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index e6cf64611ef..466368e20ed 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -38,6 +38,9 @@ #include +using util::SplitString; +using util::ToString; + typedef std::vector valtype; static CFeeRate g_dust{DUST_RELAY_TX_FEE}; diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index f59ce260585..a371753adf0 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -45,6 +45,15 @@ #include using namespace std::literals; +using util::Join; +using util::RemovePrefix; +using util::RemovePrefixView; +using util::ReplaceAll; +using util::Split; +using util::SplitString; +using util::TrimString; +using util::TrimStringView; + static const std::string STRING_WITH_EMBEDDED_NULL_CHAR{"1"s "\0" "1"s}; /* defined in logging.cpp */ diff --git a/src/test/util_threadnames_tests.cpp b/src/test/util_threadnames_tests.cpp index df5b1a4461d..228a6a7a105 100644 --- a/src/test/util_threadnames_tests.cpp +++ b/src/test/util_threadnames_tests.cpp @@ -15,6 +15,8 @@ #include +using util::ToString; + BOOST_AUTO_TEST_SUITE(util_threadnames_tests) const std::string TEST_THREAD_NAME_BASE = "test_thread."; diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp index 442c1c4d422..4f79644c8d9 100644 --- a/src/torcontrol.cpp +++ b/src/torcontrol.cpp @@ -42,6 +42,10 @@ #include #include +using util::ReplaceAll; +using util::SplitString; +using util::ToString; + /** Default control ip and port */ const std::string DEFAULT_TOR_CONTROL = "127.0.0.1:" + ToString(DEFAULT_TOR_CONTROL_PORT); /** Tor cookie size (from control-spec.txt) */ diff --git a/src/util/moneystr.cpp b/src/util/moneystr.cpp index 9181329afc8..1ed3b2ac968 100644 --- a/src/util/moneystr.cpp +++ b/src/util/moneystr.cpp @@ -13,6 +13,9 @@ #include #include +using util::ContainsNoNUL; +using util::TrimString; + std::string FormatMoney(const CAmount n) { // Note: not using straight sprintf here because we do NOT want diff --git a/src/util/strencodings.h b/src/util/strencodings.h index 7b3316d7c2b..e5c2d3ddf2d 100644 --- a/src/util/strencodings.h +++ b/src/util/strencodings.h @@ -122,7 +122,7 @@ T LocaleIndependentAtoi(std::string_view str) static_assert(std::is_integral::value); T result; // Emulate atoi(...) handling of white space and leading +/-. - std::string_view s = TrimStringView(str); + std::string_view s = util::TrimStringView(str); if (!s.empty() && s[0] == '+') { if (s.length() >= 2 && s[1] == '-') { return 0; diff --git a/src/util/string.cpp b/src/util/string.cpp index 3d318497458..47c6b74d4fd 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -7,8 +7,10 @@ #include #include +namespace util { void ReplaceAll(std::string& in_out, const std::string& search, const std::string& substitute) { if (search.empty()) return; in_out = std::regex_replace(in_out, std::regex(search), substitute); } +} // namespace util diff --git a/src/util/string.h b/src/util/string.h index 7060a4822df..e2e470f4ab5 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -16,6 +16,7 @@ #include // IWYU pragma: export #include +namespace util { void ReplaceAll(std::string& in_out, const std::string& search, const std::string& substitute); /** Split a string on any char found in separators, returning a vector. @@ -162,5 +163,6 @@ template return obj.size() >= PREFIX_LEN && std::equal(std::begin(prefix), std::end(prefix), std::begin(obj)); } +} // namespace util #endif // BITCOIN_UTIL_STRING_H diff --git a/src/wallet/load.cpp b/src/wallet/load.cpp index 8b78a670e49..fe35f6b223e 100644 --- a/src/wallet/load.cpp +++ b/src/wallet/load.cpp @@ -21,6 +21,8 @@ #include +using util::Join; + namespace wallet { bool VerifyWallets(WalletContext& context) { diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp index 8d3eea59ee0..7594fc455f3 100644 --- a/src/wallet/rpc/backup.cpp +++ b/src/wallet/rpc/backup.cpp @@ -34,6 +34,7 @@ using interfaces::FoundBlock; +using util::SplitString; namespace wallet { std::string static EncodeDumpString(const std::string &str) { diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 8cbaaea5332..c64aff5fe25 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -22,6 +22,7 @@ #include using common::PSBTError; +using util::ToString; namespace wallet { //! Value for the first BIP 32 hardened derivation. Can be used as a bit mask and as a value. See BIP 32 for more details. diff --git a/src/wallet/transaction.h b/src/wallet/transaction.h index 9c27574103b..9079f6dd82a 100644 --- a/src/wallet/transaction.h +++ b/src/wallet/transaction.h @@ -273,7 +273,7 @@ public: mapValueCopy["fromaccount"] = ""; if (nOrderPos != -1) { - mapValueCopy["n"] = ToString(nOrderPos); + mapValueCopy["n"] = util::ToString(nOrderPos); } if (nTimeSmart) { mapValueCopy["timesmart"] = strprintf("%u", nTimeSmart); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 934bc661568..cc0b35fe885 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -86,6 +86,8 @@ using common::AmountErrMsg; using common::AmountHighWarn; using common::PSBTError; using interfaces::FoundBlock; +using util::ReplaceAll; +using util::ToString; namespace wallet {