Bitcoin Core 28.99.0
P2P Digital Currency
Namespaces | Classes | Enumerations | Functions
util Namespace Reference

Namespaces

namespace  detail
 
namespace  hex_literals
 ""_hex is a compile-time user-defined literal returning a std::array<std::byte>, equivalent to ParseHex().
 

Classes

struct  ConstevalFormatString
 A wrapper for a compile-time partially validated format string. More...
 
struct  Error
 
class  ImmediateTaskRunner
 
struct  Overloaded
 Overloaded helper for std::visit. More...
 
class  Result
 
class  SignalInterrupt
 Helper class that manages an interrupt flag, and allows a thread or signal to interrupt another thread. More...
 
class  TaskRunnerInterface
 

Enumerations

enum class  LockResult { Success , ErrorWrite , ErrorLock }
 

Functions

void Xor (Span< std::byte > write, Span< const std::byte > key, size_t key_offset=0)
 
template<typename T >
T * AnyPtr (const std::any &any) noexcept
 Helper function to access the contained object of a std::any instance. More...
 
LockResult LockDirectory (const fs::path &directory, const fs::path &lockfile_name, bool probe_only)
 
template<typename Tdst , typename Tsrc >
void insert (Tdst &dst, const Tsrc &src)
 Simplification of std insertion. More...
 
template<typename TsetT , typename Tsrc >
void insert (std::set< TsetT > &dst, const Tsrc &src)
 
template<class... Ts>
 Overloaded (Ts...) -> Overloaded< Ts... >
 Explicit deduction guide (not needed after clang-17) More...
 
template<typename T >
bilingual_str ErrorString (const Result< T > &result)
 
consteval uint8_t ConstevalHexDigit (const char c)
 consteval version of HexDigit() without the lookup table. More...
 
template<util::detail::Hex str>
constexpr auto operator""_hex ()
 
template<util::detail::Hex str>
constexpr auto operator""_hex_u8 ()
 
template<util::detail::Hex str>
constexpr auto operator""_hex_v ()
 
template<util::detail::Hex str>
auto operator""_hex_v_u8 ()
 
void ReplaceAll (std::string &in_out, const std::string &search, const std::string &substitute)
 
template<typename T = Span<const char>>
std::vector< T > Split (const Span< const char > &sp, std::string_view separators)
 Split a string on any char found in separators, returning a vector. More...
 
template<typename T = Span<const char>>
std::vector< T > Split (const Span< const char > &sp, char sep)
 Split a string on every instance of sep, returning a vector. More...
 
std::vector< std::string > SplitString (std::string_view str, char sep)
 
std::vector< std::string > SplitString (std::string_view str, std::string_view separators)
 
std::string_view TrimStringView (std::string_view str, std::string_view pattern=" \f\n\r\t\v")
 
std::string TrimString (std::string_view str, std::string_view pattern=" \f\n\r\t\v")
 
std::string_view RemoveSuffixView (std::string_view str, std::string_view suffix)
 
std::string_view RemovePrefixView (std::string_view str, std::string_view prefix)
 
std::string RemovePrefix (std::string_view str, std::string_view prefix)
 
template<typename C , typename S , typename UnaryOp >
auto Join (const C &container, const S &separator, UnaryOp unary_op)
 Join all container items. More...
 
template<typename C , typename S >
auto Join (const C &container, const S &separator)
 
std::string MakeUnorderedList (const std::vector< std::string > &items)
 Create an unordered multi-line list of items. More...
 
bool ContainsNoNUL (std::string_view str) noexcept
 Check if a string does not contain any embedded NUL (\0) characters. More...
 
template<typename T >
std::string ToString (const T &t)
 Locale-independent version of std::to_string. More...
 
template<typename T1 , size_t PREFIX_LEN>
bool HasPrefix (const T1 &obj, const std::array< uint8_t, PREFIX_LEN > &prefix)
 Check whether a container begins with the given prefix. More...
 
void TraceThread (std::string_view thread_name, std::function< void()> thread_func)
 A wrapper for do-something-once thread functions. More...
 
void ThreadRename (const std::string &)
 Rename a thread both in terms of an internal (in-memory) name as well as its system thread name. More...
 
void ThreadSetInternalName (const std::string &)
 Set the internal (in-memory) name of the current thread only. More...
 
std::string ThreadGetInternalName ()
 Get the thread's internal (in-memory) name; used e.g. More...
 

Enumeration Type Documentation

◆ LockResult

enum class util::LockResult
strong
Enumerator
Success 
ErrorWrite 
ErrorLock 

Definition at line 40 of file fs_helpers.h.

Function Documentation

◆ AnyPtr()

template<typename T >
T * util::AnyPtr ( const std::any &  any)
noexcept

Helper function to access the contained object of a std::any instance.

Returns a pointer to the object if passed instance has a value and the type matches, nullptr otherwise.

Definition at line 18 of file any.h.

◆ ConstevalHexDigit()

consteval uint8_t util::ConstevalHexDigit ( const char  c)

consteval version of HexDigit() without the lookup table.

Definition at line 372 of file strencodings.h.

Here is the caller graph for this function:

◆ ContainsNoNUL()

bool util::ContainsNoNUL ( std::string_view  str)
inlinenoexcept

Check if a string does not contain any embedded NUL (\0) characters.

Definition at line 221 of file string.h.

Here is the caller graph for this function:

◆ ErrorString()

template<typename T >
bilingual_str util::ErrorString ( const Result< T > &  result)

Definition at line 93 of file result.h.

Here is the caller graph for this function:

◆ HasPrefix()

template<typename T1 , size_t PREFIX_LEN>
bool util::HasPrefix ( const T1 &  obj,
const std::array< uint8_t, PREFIX_LEN > &  prefix 
)
inline

Check whether a container begins with the given prefix.

Definition at line 245 of file string.h.

Here is the caller graph for this function:

◆ insert() [1/2]

template<typename TsetT , typename Tsrc >
void util::insert ( std::set< TsetT > &  dst,
const Tsrc &  src 
)
inline

Definition at line 18 of file insert.h.

◆ insert() [2/2]

template<typename Tdst , typename Tsrc >
void util::insert ( Tdst &  dst,
const Tsrc &  src 
)
inline

Simplification of std insertion.

Definition at line 14 of file insert.h.

Here is the caller graph for this function:

◆ Join() [1/2]

template<typename C , typename S >
auto util::Join ( const C &  container,
const S separator 
)

Definition at line 205 of file string.h.

Here is the call graph for this function:

◆ Join() [2/2]

template<typename C , typename S , typename UnaryOp >
auto util::Join ( const C &  container,
const S separator,
UnaryOp  unary_op 
)

Join all container items.

Typically used to concatenate strings but accepts containers with elements of any type.

Parameters
containerThe items to join
separatorThe separator
unary_opApply this operator to each item

Definition at line 192 of file string.h.

Here is the caller graph for this function:

◆ LockDirectory()

LockResult util::LockDirectory ( const fs::path directory,
const fs::path lockfile_name,
bool  probe_only 
)

Definition at line 53 of file fs_helpers.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MakeUnorderedList()

std::string util::MakeUnorderedList ( const std::vector< std::string > &  items)
inline

Create an unordered multi-line list of items.

Definition at line 213 of file string.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Overloaded()

template<class... Ts>
util::Overloaded ( Ts...  ) -> Overloaded< Ts... >

Explicit deduction guide (not needed after clang-17)

◆ RemovePrefix()

std::string util::RemovePrefix ( std::string_view  str,
std::string_view  prefix 
)
inline

Definition at line 177 of file string.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemovePrefixView()

std::string_view util::RemovePrefixView ( std::string_view  str,
std::string_view  prefix 
)
inline

Definition at line 169 of file string.h.

Here is the caller graph for this function:

◆ RemoveSuffixView()

std::string_view util::RemoveSuffixView ( std::string_view  str,
std::string_view  suffix 
)
inline

Definition at line 161 of file string.h.

Here is the caller graph for this function:

◆ ReplaceAll()

void util::ReplaceAll ( std::string &  in_out,
const std::string &  search,
const std::string &  substitute 
)

Definition at line 11 of file string.cpp.

Here is the caller graph for this function:

◆ Split() [1/2]

template<typename T = Span<const char>>
std::vector< T > util::Split ( const Span< const char > &  sp,
char  sep 
)

Split a string on every instance of sep, returning a vector.

If sep does not occur in sp, a singleton with the entirety of sp is returned.

Note that this function does not care about braces, so splitting "foo(bar(1),2),3) on ',' will return {"foo(bar(1)", "2)", "3)"}.

Definition at line 131 of file string.h.

◆ Split() [2/2]

template<typename T = Span<const char>>
std::vector< T > util::Split ( const Span< const char > &  sp,
std::string_view  separators 
)

Split a string on any char found in separators, returning a vector.

If sep does not occur in sp, a singleton with the entirety of sp is returned.

Note that this function does not care about braces, so splitting "foo(bar(1),2),3) on ',' will return {"foo(bar(1)", "2)", "3)"}.

Definition at line 107 of file string.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SplitString() [1/2]

std::vector< std::string > util::SplitString ( std::string_view  str,
char  sep 
)
inline

Definition at line 136 of file string.h.

Here is the caller graph for this function:

◆ SplitString() [2/2]

std::vector< std::string > util::SplitString ( std::string_view  str,
std::string_view  separators 
)
inline

Definition at line 141 of file string.h.

◆ ThreadGetInternalName()

std::string util::ThreadGetInternalName ( )

Get the thread's internal (in-memory) name; used e.g.

for identification in logging.

Definition at line 47 of file threadnames.cpp.

Here is the caller graph for this function:

◆ ThreadRename()

void util::ThreadRename ( const std::string &  name)

Rename a thread both in terms of an internal (in-memory) name as well as its system thread name.

Note
Do not call this for the main thread, as this will interfere with UNIX utilities such as top and killall. Use ThreadSetInternalName instead.

Definition at line 57 of file threadnames.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ThreadSetInternalName()

void util::ThreadSetInternalName ( const std::string &  name)

Set the internal (in-memory) name of the current thread only.

Definition at line 63 of file threadnames.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToString()

template<typename T >
std::string util::ToString ( const T &  t)

Locale-independent version of std::to_string.

Definition at line 233 of file string.h.

Here is the caller graph for this function:

◆ TraceThread()

void util::TraceThread ( std::string_view  thread_name,
std::function< void()>  thread_func 
)

A wrapper for do-something-once thread functions.

Definition at line 16 of file thread.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TrimString()

std::string util::TrimString ( std::string_view  str,
std::string_view  pattern = " \f\n\r\t\v" 
)
inline

Definition at line 156 of file string.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TrimStringView()

std::string_view util::TrimStringView ( std::string_view  str,
std::string_view  pattern = " \f\n\r\t\v" 
)
inline

Definition at line 146 of file string.h.

Here is the caller graph for this function:

◆ Xor()

void util::Xor ( Span< std::byte >  write,
Span< const std::byte >  key,
size_t  key_offset = 0 
)
inline

Definition at line 28 of file streams.h.

Here is the call graph for this function:
Here is the caller graph for this function: