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.
This commit is contained in:
Ryan Ofsky 2023-12-06 15:13:39 -05:00
parent 4d05d3f3b4
commit 4f74c59334
70 changed files with 159 additions and 14 deletions

View File

@ -14,6 +14,8 @@
#include <limits> #include <limits>
using util::ContainsNoNUL;
/** All alphanumeric characters except for "0", "I", "O", and "l" */ /** All alphanumeric characters except for "0", "I", "O", and "l" */
static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
static const int8_t mapBase58[256] = { static const int8_t mapBase58[256] = {

View File

@ -18,6 +18,7 @@
#include <vector> #include <vector>
using namespace std::chrono_literals; using namespace std::chrono_literals;
using util::Join;
const std::function<void(const std::string&)> G_TEST_LOG_FUN{}; const std::function<void(const std::string&)> G_TEST_LOG_FUN{};

View File

@ -16,6 +16,8 @@
#include <sstream> #include <sstream>
#include <vector> #include <vector>
using util::SplitString;
static const char* DEFAULT_BENCH_FILTER = ".*"; static const char* DEFAULT_BENCH_FILTER = ".*";
static constexpr int64_t DEFAULT_MIN_TIME_MS{10}; static constexpr int64_t DEFAULT_MIN_TIME_MS{10};
/** Priority level default value, run "all" priority levels */ /** Priority level default value, run "all" priority levels */

View File

@ -42,6 +42,9 @@
#include <event2/keyvalq_struct.h> #include <event2/keyvalq_struct.h>
#include <support/events.h> #include <support/events.h>
using util::Join;
using util::ToString;
// The server returns time values from a mockable system clock, but it is not // 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 // trivial to get the mocked time from the server, nor is it needed for now, so
// just use a plain system_clock. // just use a plain system_clock.

View File

@ -32,6 +32,11 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
using util::SplitString;
using util::ToString;
using util::TrimString;
using util::TrimStringView;
static bool fCreateBlank; static bool fCreateBlank;
static std::map<std::string,UniValue> registers; static std::map<std::string,UniValue> registers;
static const int CONTINUE_EXECUTION=-1; static const int CONTINUE_EXECUTION=-1;

View File

@ -24,6 +24,8 @@
#include <string> #include <string>
#include <tuple> #include <tuple>
using util::Join;
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr; const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
static void SetupWalletToolArgs(ArgsManager& argsman) static void SetupWalletToolArgs(ArgsManager& argsman)

View File

@ -16,6 +16,8 @@
#include <util/golombrice.h> #include <util/golombrice.h>
#include <util/string.h> #include <util/string.h>
using util::Join;
static const std::map<BlockFilterType, std::string> g_filter_types = { static const std::map<BlockFilterType, std::string> g_filter_types = {
{BlockFilterType::BASIC, "basic"}, {BlockFilterType::BASIC, "basic"},
}; };

View File

@ -21,6 +21,8 @@
#include <stdexcept> #include <stdexcept>
#include <vector> #include <vector>
using util::SplitString;
void ReadSigNetArgs(const ArgsManager& args, CChainParams::SigNetOptions& options) void ReadSigNetArgs(const ArgsManager& args, CChainParams::SigNetOptions& options)
{ {
if (args.IsArgSet("-signetseednode")) { if (args.IsArgSet("-signetseednode")) {

View File

@ -13,6 +13,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
using util::Join;
/** /**
* Name of client reported in the 'version' message. Report the same name * 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 * for both bitcoind and bitcoin-qt, to make it harder for attackers to

View File

@ -27,6 +27,9 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
using util::TrimString;
using util::TrimStringView;
static bool GetConfigOptions(std::istream& stream, const std::string& filepath, std::string& error, std::vector<std::pair<std::string, std::string>>& options, std::list<SectionInfo>& sections) static bool GetConfigOptions(std::istream& stream, const std::string& filepath, std::string& error, std::vector<std::pair<std::string, std::string>>& options, std::list<SectionInfo>& sections)
{ {
std::string str, prefix; std::string str, prefix;

View File

@ -20,6 +20,7 @@
#include <vector> #include <vector>
using node::TransactionError; using node::TransactionError;
using util::Join;
namespace common { namespace common {
std::string StringForFeeReason(FeeReason reason) std::string StringForFeeReason(FeeReason reason)

View File

@ -28,6 +28,8 @@
#include <string> #include <string>
#include <thread> #include <thread>
using util::ReplaceAll;
// Application startup time (used for uptime calculation) // Application startup time (used for uptime calculation)
const int64_t nStartupTime = GetTime(); const int64_t nStartupTime = GetTime();

View File

@ -16,6 +16,8 @@
#include <algorithm> #include <algorithm>
#include <string> #include <string>
using util::SplitString;
namespace { namespace {
class OpCodeParser class OpCodeParser
{ {

View File

@ -23,6 +23,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
using util::SplitString;
using util::TrimStringView;
/** WWW-Authenticate to present with 401 Unauthorized response */ /** WWW-Authenticate to present with 401 Unauthorized response */
static const char* WWW_AUTH_HEADER_DATA = "Basic realm=\"jsonrpc\""; static const char* WWW_AUTH_HEADER_DATA = "Basic realm=\"jsonrpc\"";

View File

@ -26,6 +26,8 @@
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
using util::Split;
namespace i2p { namespace i2p {
/** /**

View File

@ -137,6 +137,9 @@ using node::NodeContext;
using node::ShouldPersistMempool; using node::ShouldPersistMempool;
using node::ImportBlocks; using node::ImportBlocks;
using node::VerifyLoadedChainstate; using node::VerifyLoadedChainstate;
using util::Join;
using util::ReplaceAll;
using util::ToString;
static constexpr bool DEFAULT_PROXYRANDOMIZE{true}; static constexpr bool DEFAULT_PROXYRANDOMIZE{true};
static constexpr bool DEFAULT_REST_ENABLE{false}; static constexpr bool DEFAULT_REST_ENABLE{false};

View File

@ -20,6 +20,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
using util::SplitString;
namespace init { namespace init {
void AddLoggingArgs(ArgsManager& argsman) void AddLoggingArgs(ArgsManager& argsman)
{ {

View File

@ -13,6 +13,10 @@
#include <map> #include <map>
#include <optional> #include <optional>
using util::Join;
using util::RemovePrefix;
using util::ToString;
const char * const DEFAULT_DEBUGLOGFILE = "debug.log"; const char * const DEFAULT_DEBUGLOGFILE = "debug.log";
constexpr auto MAX_USER_SETABLE_SEVERITY_LEVEL{BCLog::Level::Info}; constexpr auto MAX_USER_SETABLE_SEVERITY_LEVEL{BCLog::Level::Info};

View File

@ -189,7 +189,7 @@ namespace BCLog {
/** Returns a string with the log categories in alphabetical order. */ /** Returns a string with the log categories in alphabetical order. */
std::string LogCategoriesString() const 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. //! Returns a string with all user-selectable log levels.

View File

@ -20,6 +20,9 @@
#include <iterator> #include <iterator>
#include <tuple> #include <tuple>
using util::ContainsNoNUL;
using util::HasPrefix;
CNetAddr::BIP155Network CNetAddr::GetBIP155Network() const CNetAddr::BIP155Network CNetAddr::GetBIP155Network() const
{ {
switch (m_net) { switch (m_net) {

View File

@ -448,7 +448,7 @@ private:
// Recognize NET_INTERNAL embedded in IPv6, such addresses are not // Recognize NET_INTERNAL embedded in IPv6, such addresses are not
// gossiped but could be coming from addrman, when unserializing from // gossiped but could be coming from addrman, when unserializing from
// disk. // disk.
if (HasPrefix(m_addr, INTERNAL_IN_IPV6_PREFIX)) { if (util::HasPrefix(m_addr, INTERNAL_IN_IPV6_PREFIX)) {
m_net = NET_INTERNAL; m_net = NET_INTERNAL;
memmove(m_addr.data(), m_addr.data() + INTERNAL_IN_IPV6_PREFIX.size(), memmove(m_addr.data(), m_addr.data() + INTERNAL_IN_IPV6_PREFIX.size(),
ADDR_INTERNAL_SIZE); ADDR_INTERNAL_SIZE);
@ -456,8 +456,8 @@ private:
return; return;
} }
if (!HasPrefix(m_addr, IPV4_IN_IPV6_PREFIX) && if (!util::HasPrefix(m_addr, IPV4_IN_IPV6_PREFIX) &&
!HasPrefix(m_addr, TORV2_IN_IPV6_PREFIX)) { !util::HasPrefix(m_addr, TORV2_IN_IPV6_PREFIX)) {
return; return;
} }

View File

@ -27,6 +27,8 @@
#include <sys/un.h> #include <sys/un.h>
#endif #endif
using util::ContainsNoNUL;
// Settings // Settings
static GlobalMutex g_proxyinfo_mutex; static GlobalMutex g_proxyinfo_mutex;
static Proxy proxyInfo[NET_MAX] GUARDED_BY(g_proxyinfo_mutex); static Proxy proxyInfo[NET_MAX] GUARDED_BY(g_proxyinfo_mutex);

View File

@ -10,6 +10,8 @@
#include <boost/signals2/optional_last_value.hpp> #include <boost/signals2/optional_last_value.hpp>
#include <boost/signals2/signal.hpp> #include <boost/signals2/signal.hpp>
using util::MakeUnorderedList;
CClientUIInterface uiInterface; CClientUIInterface uiInterface;
struct UISignals { struct UISignals {

View File

@ -71,6 +71,7 @@ using interfaces::Handler;
using interfaces::MakeSignalHandler; using interfaces::MakeSignalHandler;
using interfaces::Node; using interfaces::Node;
using interfaces::WalletLoader; using interfaces::WalletLoader;
using util::Join;
namespace node { namespace node {
// All members of the classes in this namespace are intentionally public, as the // All members of the classes in this namespace are intentionally public, as the

View File

@ -24,6 +24,8 @@
#include <string> #include <string>
#include <thread> #include <thread>
using util::ReplaceAll;
static void AlertNotify(const std::string& strMessage) static void AlertNotify(const std::string& strMessage)
{ {
uiInterface.NotifyAlertChanged(); uiInterface.NotifyAlertChanged();

View File

@ -85,6 +85,8 @@ Q_DECLARE_METATYPE(uint256)
Q_DECLARE_METATYPE(wallet::AddressPurpose) Q_DECLARE_METATYPE(wallet::AddressPurpose)
#endif // ENABLE_WALLET #endif // ENABLE_WALLET
using util::MakeUnorderedList;
static void RegisterMetaTypes() static void RegisterMetaTypes()
{ {
// Register meta types used for QMetaObject::invokeMethod and Qt::QueuedConnection // Register meta types used for QMetaObject::invokeMethod and Qt::QueuedConnection

View File

@ -20,6 +20,8 @@
#include <QLatin1Char> #include <QLatin1Char>
#include <QLatin1String> #include <QLatin1String>
using util::ToString;
RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) : RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) :
QAbstractTableModel(parent), walletModel(parent) QAbstractTableModel(parent), walletModel(parent)
{ {

View File

@ -48,6 +48,8 @@
#include <chrono> #include <chrono>
using util::Join;
const int CONSOLE_HISTORY = 50; const int CONSOLE_HISTORY = 50;
const int INITIAL_TRAFFIC_GRAPH_MINS = 30; const int INITIAL_TRAFFIC_GRAPH_MINS = 30;
const QSize FONT_RANGE(4, 40); const QSize FONT_RANGE(4, 40);

View File

@ -30,6 +30,7 @@
#include <QTimer> #include <QTimer>
#include <QWindow> #include <QWindow>
using util::Join;
using wallet::WALLET_FLAG_BLANK_WALLET; using wallet::WALLET_FLAG_BLANK_WALLET;
using wallet::WALLET_FLAG_DESCRIPTORS; using wallet::WALLET_FLAG_DESCRIPTORS;
using wallet::WALLET_FLAG_DISABLE_PRIVATE_KEYS; using wallet::WALLET_FLAG_DISABLE_PRIVATE_KEYS;

View File

@ -39,6 +39,7 @@
using node::GetTransaction; using node::GetTransaction;
using node::NodeContext; 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 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; static constexpr unsigned int MAX_REST_HEADERS_RESULTS = 2000;

View File

@ -60,6 +60,9 @@ using kernel::CoinStatsHashType;
using node::BlockManager; using node::BlockManager;
using node::NodeContext; using node::NodeContext;
using node::SnapshotMetadata; using node::SnapshotMetadata;
using util::Join;
using util::MakeUnorderedList;
using util::ToString;
struct CUpdatedBlock struct CUpdatedBlock
{ {

View File

@ -34,6 +34,7 @@ using node::DEFAULT_MAX_RAW_TX_FEE_RATE;
using node::MempoolPath; using node::MempoolPath;
using node::NodeContext; using node::NodeContext;
using node::TransactionError; using node::TransactionError;
using util::ToString;
static RPCHelpMan sendrawtransaction() static RPCHelpMan sendrawtransaction()
{ {

View File

@ -47,6 +47,7 @@ using node::CBlockTemplate;
using node::NodeContext; using node::NodeContext;
using node::RegenerateCommitments; using node::RegenerateCommitments;
using node::UpdateTime; using node::UpdateTime;
using util::ToString;
/** /**
* Return average network hashes per second based on the last 'lookup' blocks, * Return average network hashes per second based on the last 'lookup' blocks,

View File

@ -35,6 +35,8 @@
#include <univalue.h> #include <univalue.h>
using node::NodeContext; using node::NodeContext;
using util::Join;
using util::TrimString;
const std::vector<std::string> CONNECTION_TYPE_DOC{ const std::vector<std::string> CONNECTION_TYPE_DOC{
"outbound-full-relay (default automatic connections)", "outbound-full-relay (default automatic connections)",

View File

@ -27,6 +27,8 @@
#include <mutex> #include <mutex>
#include <unordered_map> #include <unordered_map>
using util::SplitString;
static GlobalMutex g_rpc_warmup_mutex; static GlobalMutex g_rpc_warmup_mutex;
static std::atomic<bool> g_rpc_running{false}; static std::atomic<bool> g_rpc_running{false};
static bool fRPCInWarmup GUARDED_BY(g_rpc_warmup_mutex) = true; static bool fRPCInWarmup GUARDED_BY(g_rpc_warmup_mutex) = true;

View File

@ -37,6 +37,9 @@ using common::PSBTError;
using common::PSBTErrorString; using common::PSBTErrorString;
using common::TransactionErrorString; using common::TransactionErrorString;
using node::TransactionError; using node::TransactionError;
using util::Join;
using util::SplitString;
using util::TrimString;
const std::string UNIX_EPOCH_TIME = "UNIX epoch time"; const std::string UNIX_EPOCH_TIME = "UNIX epoch time";
const std::string EXAMPLE_ADDRESS[2] = {"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl", "bc1q02ad21edsxd23d32dfgqqsz4vv4nmtfzuklhy3"}; 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 if (arg.m_opts.hidden) break; // Any arg that follows is also hidden
// Push named argument name and description // 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()); sections.m_max_pad = std::max(sections.m_max_pad, sections.m_sections.back().m_left.size());
// Recursively push nested args // Recursively push nested args

View File

@ -27,6 +27,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
using util::Split;
namespace { namespace {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////

View File

@ -863,8 +863,8 @@ public:
if (!key_str) return {}; if (!key_str) return {};
return std::move(ret) + "pk_h(" + std::move(*key_str) + ")"; return std::move(ret) + "pk_h(" + std::move(*key_str) + ")";
} }
case Fragment::AFTER: return std::move(ret) + "after(" + ::ToString(node.k) + ")"; case Fragment::AFTER: return std::move(ret) + "after(" + util::ToString(node.k) + ")";
case Fragment::OLDER: return std::move(ret) + "older(" + ::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::HASH256: return std::move(ret) + "hash256(" + HexStr(node.data) + ")";
case Fragment::HASH160: return std::move(ret) + "hash160(" + 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) + ")"; 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]) + ")"; return std::move(ret) + "andor(" + std::move(subs[0]) + "," + std::move(subs[1]) + "," + std::move(subs[2]) + ")";
case Fragment::MULTI: { case Fragment::MULTI: {
CHECK_NONFATAL(!is_tapscript); 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) { for (const auto& key : node.keys) {
auto key_str = ctx.ToString(key); auto key_str = ctx.ToString(key);
if (!key_str) return {}; if (!key_str) return {};
@ -893,7 +893,7 @@ public:
} }
case Fragment::MULTI_A: { case Fragment::MULTI_A: {
CHECK_NONFATAL(is_tapscript); 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) { for (const auto& key : node.keys) {
auto key_str = ctx.ToString(key); auto key_str = ctx.ToString(key);
if (!key_str) return {}; if (!key_str) return {};
@ -902,7 +902,7 @@ public:
return std::move(str) + ")"; return std::move(str) + ")";
} }
case Fragment::THRESH: { 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) { for (auto& sub : subs) {
str += "," + std::move(sub); str += "," + std::move(sub);
} }

View File

@ -22,6 +22,7 @@
using namespace std::literals; using namespace std::literals;
using node::NodeContext; using node::NodeContext;
using util::ToString;
static NetGroupManager EMPTY_NETGROUPMAN{std::vector<bool>()}; static NetGroupManager EMPTY_NETGROUPMAN{std::vector<bool>()};
static const bool DETERMINISTIC{true}; static const bool DETERMINISTIC{true};

View File

@ -20,6 +20,8 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
using util::ToString;
BOOST_FIXTURE_TEST_SUITE(argsman_tests, BasicTestingSetup) BOOST_FIXTURE_TEST_SUITE(argsman_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(util_datadir) BOOST_AUTO_TEST_CASE(util_datadir)

View File

@ -11,6 +11,8 @@
#include <cstdlib> #include <cstdlib>
using util::ToString;
/* Equality between doubles is imprecise. Comparison should be done /* Equality between doubles is imprecise. Comparison should be done
* with a small threshold of tolerance, rather than exact equality. * with a small threshold of tolerance, rather than exact equality.
*/ */

View File

@ -12,6 +12,8 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
using util::ToString;
// Test if a string consists entirely of null characters // Test if a string consists entirely of null characters
static bool is_null_key(const std::vector<unsigned char>& key) { static bool is_null_key(const std::vector<unsigned char>& key) {
bool isnull = true; bool isnull = true;

View File

@ -15,6 +15,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
using util::Split;
namespace { namespace {
void CheckUnparsable(const std::string& prv, const std::string& pub, const std::string& expected_error) void CheckUnparsable(const std::string& prv, const std::string& pub, const std::string& expected_error)

View File

@ -14,6 +14,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
using util::TrimString;
using util::TrimStringView;
FUZZ_TARGET(base_encode_decode) FUZZ_TARGET(base_encode_decode)
{ {
const std::string random_encoded_string(buffer.begin(), buffer.end()); const std::string random_encoded_string(buffer.begin(), buffer.end());

View File

@ -40,6 +40,8 @@
#include <set> #include <set>
#include <vector> #include <vector>
using util::ToString;
void initialize_integer() void initialize_integer()
{ {
SelectParams(ChainType::REGTEST); SelectParams(ChainType::REGTEST);

View File

@ -51,7 +51,7 @@ FUZZ_TARGET(locale)
int64_t parseint64_out_without_locale; int64_t parseint64_out_without_locale;
const bool parseint64_without_locale = ParseInt64(random_string, &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<int64_t>(); const int64_t random_int64 = fuzzed_data_provider.ConsumeIntegral<int64_t>();
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 // 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. // consume the same data that it did previously to not invalidate existing seeds.
const int32_t random_int32 = fuzzed_data_provider.ConsumeIntegral<int32_t>(); const int32_t random_int32 = fuzzed_data_provider.ConsumeIntegral<int32_t>();
@ -75,7 +75,7 @@ FUZZ_TARGET(locale)
if (parseint64_without_locale) { if (parseint64_without_locale) {
assert(parseint64_out_without_locale == parseint64_out_with_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); assert(tostring_without_locale == tostring_with_locale);
const std::string strprintf_int_with_locale = strprintf("%d", random_int64); const std::string strprintf_int_with_locale = strprintf("%d", random_int64);
assert(strprintf_int_without_locale == strprintf_int_with_locale); assert(strprintf_int_without_locale == strprintf_int_with_locale);

View File

@ -36,6 +36,9 @@
#include <vector> #include <vector>
enum class ChainType; enum class ChainType;
using util::Join;
using util::ToString;
namespace { namespace {
struct RPCFuzzTestingSetup : public TestingSetup { struct RPCFuzzTestingSetup : public TestingSetup {
RPCFuzzTestingSetup(const ChainType chain_type, const std::vector<const char*>& extra_args) : TestingSetup{chain_type, extra_args} RPCFuzzTestingSetup(const ChainType chain_type, const std::vector<const char*>& extra_args) : TestingSetup{chain_type, extra_args}

View File

@ -17,6 +17,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
using util::SplitString;
// This fuzz "test" can be used to minimize test cases for script_assets_test in // 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, // 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. // fuzzing the inputs is unlikely to construct useful test cases.

View File

@ -7,6 +7,8 @@
#include <test/fuzz/fuzz.h> #include <test/fuzz/fuzz.h>
#include <util/string.h> #include <util/string.h>
using util::Split;
FUZZ_TARGET(script_parsing) FUZZ_TARGET(script_parsing)
{ {
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());

View File

@ -40,6 +40,11 @@ using common::AmountErrMsg;
using common::AmountHighWarn; using common::AmountHighWarn;
using common::FeeModeFromString; using common::FeeModeFromString;
using common::ResolveErrMsg; using common::ResolveErrMsg;
using util::ContainsNoNUL;
using util::Join;
using util::RemovePrefix;
using util::SplitString;
using util::TrimString;
FUZZ_TARGET(string) FUZZ_TARGET(string)
{ {

View File

@ -21,6 +21,7 @@
using node::BlockAssembler; using node::BlockAssembler;
using node::NodeContext; using node::NodeContext;
using util::ToString;
namespace { namespace {

View File

@ -16,6 +16,8 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
using util::SplitString;
BOOST_FIXTURE_TEST_SUITE(getarg_tests, BasicTestingSetup) BOOST_FIXTURE_TEST_SUITE(getarg_tests, BasicTestingSetup)
void ResetArgs(ArgsManager& local_args, const std::string& strArg) void ResetArgs(ArgsManager& local_args, const std::string& strArg)

View File

@ -18,6 +18,8 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
using util::ToString;
static const std::string strSecret1 = "5HxWvvfubhXpYYpS3tJkw6fq9jE9j18THftkZjHHfmFiWtmAbrj"; static const std::string strSecret1 = "5HxWvvfubhXpYYpS3tJkw6fq9jE9j18THftkZjHHfmFiWtmAbrj";
static const std::string strSecret2 = "5KC4ejrDjv152FGwP386VD1i2NYc5KkfSMyv1nGy1VGDxGHqVY3"; static const std::string strSecret2 = "5KC4ejrDjv152FGwP386VD1i2NYc5KkfSMyv1nGy1VGDxGHqVY3";
static const std::string strSecret1C = "Kwr371tjA9u2rFSMZjTNun2PXXP3WPZu2afRHTcta6KxEUdm1vEw"; static const std::string strSecret1C = "Kwr371tjA9u2rFSMZjTNun2PXXP3WPZu2afRHTcta6KxEUdm1vEw";

View File

@ -17,6 +17,9 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
using util::SplitString;
using util::TrimString;
BOOST_FIXTURE_TEST_SUITE(logging_tests, BasicTestingSetup) BOOST_FIXTURE_TEST_SUITE(logging_tests, BasicTestingSetup)
static void ResetLogger() static void ResetLogger()

View File

@ -32,6 +32,7 @@
#include <string> #include <string>
using namespace std::literals; using namespace std::literals;
using util::ToString;
BOOST_FIXTURE_TEST_SUITE(net_tests, RegTestingSetup) BOOST_FIXTURE_TEST_SUITE(net_tests, RegTestingSetup)

View File

@ -17,6 +17,8 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
using util::SplitString;
static UniValue JSON(std::string_view json) static UniValue JSON(std::string_view json)
{ {
UniValue value; UniValue value;

View File

@ -21,6 +21,8 @@
#include <system_error> #include <system_error>
#include <vector> #include <vector>
using util::ToString;
inline bool operator==(const common::SettingsValue& a, const common::SettingsValue& b) inline bool operator==(const common::SettingsValue& a, const common::SettingsValue& b)
{ {
return a.write() == b.write(); return a.write() == b.write();

View File

@ -38,6 +38,9 @@
#include <univalue.h> #include <univalue.h>
using util::SplitString;
using util::ToString;
typedef std::vector<unsigned char> valtype; typedef std::vector<unsigned char> valtype;
static CFeeRate g_dust{DUST_RELAY_TX_FEE}; static CFeeRate g_dust{DUST_RELAY_TX_FEE};

View File

@ -45,6 +45,15 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
using namespace std::literals; 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}; static const std::string STRING_WITH_EMBEDDED_NULL_CHAR{"1"s "\0" "1"s};
/* defined in logging.cpp */ /* defined in logging.cpp */

View File

@ -15,6 +15,8 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
using util::ToString;
BOOST_AUTO_TEST_SUITE(util_threadnames_tests) BOOST_AUTO_TEST_SUITE(util_threadnames_tests)
const std::string TEST_THREAD_NAME_BASE = "test_thread."; const std::string TEST_THREAD_NAME_BASE = "test_thread.";

View File

@ -42,6 +42,10 @@
#include <event2/thread.h> #include <event2/thread.h>
#include <event2/util.h> #include <event2/util.h>
using util::ReplaceAll;
using util::SplitString;
using util::ToString;
/** Default control ip and port */ /** Default control ip and port */
const std::string DEFAULT_TOR_CONTROL = "127.0.0.1:" + ToString(DEFAULT_TOR_CONTROL_PORT); const std::string DEFAULT_TOR_CONTROL = "127.0.0.1:" + ToString(DEFAULT_TOR_CONTROL_PORT);
/** Tor cookie size (from control-spec.txt) */ /** Tor cookie size (from control-spec.txt) */

View File

@ -13,6 +13,9 @@
#include <cstdint> #include <cstdint>
#include <optional> #include <optional>
using util::ContainsNoNUL;
using util::TrimString;
std::string FormatMoney(const CAmount n) std::string FormatMoney(const CAmount n)
{ {
// Note: not using straight sprintf here because we do NOT want // Note: not using straight sprintf here because we do NOT want

View File

@ -122,7 +122,7 @@ T LocaleIndependentAtoi(std::string_view str)
static_assert(std::is_integral<T>::value); static_assert(std::is_integral<T>::value);
T result; T result;
// Emulate atoi(...) handling of white space and leading +/-. // 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.empty() && s[0] == '+') {
if (s.length() >= 2 && s[1] == '-') { if (s.length() >= 2 && s[1] == '-') {
return 0; return 0;

View File

@ -7,8 +7,10 @@
#include <regex> #include <regex>
#include <string> #include <string>
namespace util {
void ReplaceAll(std::string& in_out, const std::string& search, const std::string& substitute) void ReplaceAll(std::string& in_out, const std::string& search, const std::string& substitute)
{ {
if (search.empty()) return; if (search.empty()) return;
in_out = std::regex_replace(in_out, std::regex(search), substitute); in_out = std::regex_replace(in_out, std::regex(search), substitute);
} }
} // namespace util

View File

@ -16,6 +16,7 @@
#include <string_view> // IWYU pragma: export #include <string_view> // IWYU pragma: export
#include <vector> #include <vector>
namespace util {
void ReplaceAll(std::string& in_out, const std::string& search, const std::string& substitute); 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. /** Split a string on any char found in separators, returning a vector.
@ -162,5 +163,6 @@ template <typename T1, size_t PREFIX_LEN>
return obj.size() >= PREFIX_LEN && return obj.size() >= PREFIX_LEN &&
std::equal(std::begin(prefix), std::end(prefix), std::begin(obj)); std::equal(std::begin(prefix), std::end(prefix), std::begin(obj));
} }
} // namespace util
#endif // BITCOIN_UTIL_STRING_H #endif // BITCOIN_UTIL_STRING_H

View File

@ -21,6 +21,8 @@
#include <system_error> #include <system_error>
using util::Join;
namespace wallet { namespace wallet {
bool VerifyWallets(WalletContext& context) bool VerifyWallets(WalletContext& context)
{ {

View File

@ -34,6 +34,7 @@
using interfaces::FoundBlock; using interfaces::FoundBlock;
using util::SplitString;
namespace wallet { namespace wallet {
std::string static EncodeDumpString(const std::string &str) { std::string static EncodeDumpString(const std::string &str) {

View File

@ -22,6 +22,7 @@
#include <optional> #include <optional>
using common::PSBTError; using common::PSBTError;
using util::ToString;
namespace wallet { 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. //! 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.

View File

@ -273,7 +273,7 @@ public:
mapValueCopy["fromaccount"] = ""; mapValueCopy["fromaccount"] = "";
if (nOrderPos != -1) { if (nOrderPos != -1) {
mapValueCopy["n"] = ToString(nOrderPos); mapValueCopy["n"] = util::ToString(nOrderPos);
} }
if (nTimeSmart) { if (nTimeSmart) {
mapValueCopy["timesmart"] = strprintf("%u", nTimeSmart); mapValueCopy["timesmart"] = strprintf("%u", nTimeSmart);

View File

@ -86,6 +86,8 @@ using common::AmountErrMsg;
using common::AmountHighWarn; using common::AmountHighWarn;
using common::PSBTError; using common::PSBTError;
using interfaces::FoundBlock; using interfaces::FoundBlock;
using util::ReplaceAll;
using util::ToString;
namespace wallet { namespace wallet {