Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
util Namespace Reference

Namespaces

namespace  log
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...
class  Unexpected
 The util::Unexpected class represents an unexpected value stored in util::Expected. More...
struct  BadExpectedAccess
class  Expected
 The util::Expected class provides a standard way for low-level functions to return either error values or result values. More...
class  Expected< void, E >
struct  Overloaded
struct  Error
class  Result
class  SignalInterrupt
 Helper class that manages an interrupt flag, and allows a thread or signal to interrupt another thread. More...
struct  AsciiCaseInsensitiveKeyEqual
struct  AsciiCaseInsensitiveHash
struct  LineReader
class  TaskRunnerInterface
class  ImmediateTaskRunner
struct  TranslatedLiteral
 Compile-time literal string that can be translated with an optional translation function. More...
struct  BilingualFmt

Enumerations

enum class  LockResult { Success , ErrorWrite , ErrorLock }

Functions

template<typename T>
TAnyPtr (const std::any &any) noexcept
 Helper function to access the contained object of a std::any instance.
int ExecVp (const char *file, char *const argv[])
fs::path GetExePath (std::string_view argv0)
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.
template<typename TsetT, typename Tsrc>
void insert (std::set< TsetT > &dst, const Tsrc &src)
template<typename TsetT, typename Compare, typename Tsrc>
void insert (std::set< TsetT, Compare > &dst, const Tsrc &src)
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.
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< TSplit (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.
template<typename T = std::span<const char>>
std::vector< TSplit (const std::span< const char > &sp, char sep, bool include_sep=false)
 Split a string on every instance of sep, returning a vector.
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.
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.
bool ContainsNoNUL (std::string_view str) noexcept
 Check if a string does not contain any embedded NUL (\0) characters.
template<typename T>
std::string ToString (const T &t)
 Locale-independent version of std::to_string.
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.
void TraceThread (std::string_view thread_name, std::function< void()> thread_func)
 A wrapper for do-something-once thread functions.
void ThreadRename (const std::string &)
void ThreadSetInternalName (const std::string &)
 Set the internal (in-memory) name of the current thread only.
std::string ThreadGetInternalName ()
std::ostream & operator<< (std::ostream &os, const TranslatedLiteral &lit)
template<typename T>
T operator+ (const T &lhs, const TranslatedLiteral &rhs)
template<typename T>
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.

Here is the caller graph for this function:

◆ ConstevalHexDigit()

uint8_t util::ConstevalHexDigit ( const char c)
consteval

consteval version of HexDigit() without the lookup table.

Definition at line 331 of file strencodings.h.

Here is the caller graph for this function:

◆ ContainsNoNUL()

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

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

Definition at line 234 of file string.h.

◆ ErrorString()

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

Definition at line 93 of file result.h.

Here is the call graph for this function:
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 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 )
inlinenodiscard

Check whether a container begins with the given prefix.

Definition at line 258 of file string.h.

Here is the caller graph for this function:

◆ insert() [1/3]

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/3]

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

Definition at line 23 of file insert.h.

◆ insert() [3/3]

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 218 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 205 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 )
nodiscard

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

Here is the call 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.

◆ RemovePrefix()

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

Definition at line 190 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 )
inlinenodiscard

Definition at line 182 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 )
inlinenodiscard

Definition at line 174 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.

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

Here is the call graph for this function:

◆ 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 116 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 )
inlinenodiscard

Definition at line 149 of file string.h.

Here is the call graph for this function:

◆ SplitString() [2/2]

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

Definition at line 154 of file string.h.

Here is the call graph for this function:

◆ 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 246 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" )
inlinenodiscard

Definition at line 169 of file string.h.

Here is the call graph for this function:

◆ TrimStringView()

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

Definition at line 159 of file string.h.

Here is the caller graph for this function: