mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-02 01:04:43 +02:00
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:
@@ -13,6 +13,9 @@
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
|
||||
using util::ContainsNoNUL;
|
||||
using util::TrimString;
|
||||
|
||||
std::string FormatMoney(const CAmount n)
|
||||
{
|
||||
// Note: not using straight sprintf here because we do NOT want
|
||||
|
||||
@@ -122,7 +122,7 @@ T LocaleIndependentAtoi(std::string_view str)
|
||||
static_assert(std::is_integral<T>::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;
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
#include <regex>
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <string_view> // IWYU pragma: export
|
||||
#include <vector>
|
||||
|
||||
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 <typename T1, size_t PREFIX_LEN>
|
||||
return obj.size() >= PREFIX_LEN &&
|
||||
std::equal(std::begin(prefix), std::end(prefix), std::begin(obj));
|
||||
}
|
||||
} // namespace util
|
||||
|
||||
#endif // BITCOIN_UTIL_STRING_H
|
||||
|
||||
Reference in New Issue
Block a user