Bitcoin Core 29.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  BilingualFmt
 
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
 
struct  TranslatedLiteral
 Compile-time literal string that can be translated with an optional translation function. More...
 

Enumerations

enum class  LockResult { Success , ErrorWrite , ErrorLock }
 

Functions

template<typename T >
T * AnyPtr (const std::any &any) noexcept
 Helper function to access the contained object of a std::any instance. More...
 
int ExecVp (const char *file, char *const argv[])
 Cross-platform wrapper for POSIX execvp function. More...
 
fs::path GetExePath (std::string_view argv0)
 Return path to current executable assuming it was invoked with argv0. 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 = std::span<const char>>
std::vector< T > Split (const std::span< const char > &sp, std::string_view separators, bool include_sep=false)
 Split a string on any char found in separators, returning a vector. More...
 
template<typename T = std::span<const char>>
std::vector< T > Split (const std::span< const char > &sp, char sep, bool include_sep=false)
 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...
 
std::ostream & operator<< (std::ostream &os, const TranslatedLiteral &lit)
 
template<typename T >
operator+ (const T &lhs, const TranslatedLiteral &rhs)
 
template<typename T >
operator+ (const TranslatedLiteral &lhs, const T &rhs)
 

Enumeration Type Documentation

◆ LockResult

enum class util::LockResult
strong
Enumerator
Success 
ErrorWrite 
ErrorLock 

Definition at line 57 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 329 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 233 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:

◆ ExecVp()

int util::ExecVp ( const char *  file,
char *const  argv[] 
)

Cross-platform wrapper for POSIX execvp function.

Arguments and return value are the same as for POSIX execvp, and the argv array should consist of null terminated strings and be null terminated itself, like the POSIX function.

Definition at line 21 of file exec.cpp.

Here is the caller graph for this function:

◆ GetExePath()

fs::path util::GetExePath ( std::string_view  argv0)

Return path to current executable assuming it was invoked with argv0.

If path could not be determined, returns an empty path.

Definition at line 40 of file exec.cpp.

Here is the call graph for this function:
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 257 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 217 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 204 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 47 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 225 of file string.h.

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

◆ operator+() [1/2]

template<typename T >
T util::operator+ ( const T &  lhs,
const TranslatedLiteral rhs 
)

Definition at line 67 of file translation.h.

◆ operator+() [2/2]

template<typename T >
T util::operator+ ( const TranslatedLiteral lhs,
const T &  rhs 
)

Definition at line 69 of file translation.h.

◆ operator<<()

std::ostream & util::operator<< ( std::ostream &  os,
const TranslatedLiteral lit 
)
inline

Definition at line 65 of file translation.h.

◆ 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 189 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 181 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 173 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 = std::span<const char>>
std::vector< T > util::Split ( const std::span< const char > &  sp,
char  sep,
bool  include_sep = false 
)

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 143 of file string.h.

◆ Split() [2/2]

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

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.

Parameters
[in]include_sepWhether to include the separator at the end of the left side of the splits.

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

  • foo(bar(1),
  • 2),
  • 3)

Definition at line 115 of file string.h.

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 148 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 153 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 45 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 55 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 61 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 245 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 168 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 158 of file string.h.

Here is the caller graph for this function: