OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::string Namespace Reference

Functions

int strcasecmp (const char *s1, const char *s2)
 
int strcasecmp (const std::string &s1, const char *s2)
 
int strcasecmp (const char *s1, const std::string &s2)
 
int strcasecmp (const std::string &s1, const std::string &s2)
 
void strncpynt (char *dest, const char *src, size_t maxlen)
 
void copy_fill (void *dest, const std::string &src, const size_t dest_size)
 
bool is_true (const std::string &str)
 
template<typename STRING >
bool starts_with_delim (const STRING &str, const std::string &prefix, const char delim)
 
template<typename STRING >
bool ends_with_newline (const STRING &str)
 
template<typename STRING >
bool ends_with_crlf (const STRING &str)
 
std::string add_leading (const std::string &str, const size_t min_len, const char c)
 
std::string add_trailing_copy (const std::string &str, const char c)
 
void add_trailing (std::string &str, const char c)
 
void add_trailing_crlf (std::string &str)
 
std::string add_trailing_crlf_copy (std::string str)
 
std::string add_trailing_unless_empty_copy (const std::string &str, const char c)
 
template<typename STRING >
void trim_crlf (STRING &str)
 
std::string trim_crlf_copy (std::string str)
 
bool embedded_null (const char *str, size_t len)
 
size_t len_without_trailing_nulls (const char *str, size_t len)
 
bool is_multiline (const std::string &str)
 
std::string to_delim (const std::string &str, const char delim)
 
std::string first_line (const std::string &str)
 
bool is_space (const char c)
 
bool is_digit (const char c)
 
bool is_alpha (const char c)
 
bool is_alphanumeric (const char c)
 
bool is_printable (const char c)
 
bool is_printable (const unsigned char c)
 
bool is_ctrl (const char c)
 
bool is_ctrl (const unsigned char c)
 
bool is_word (const std::string &str)
 
bool is_printable (const std::string &str)
 
bool contains_non_space_ctrl (const std::string &str)
 
bool contains_space (const std::string &str)
 
std::string remove_spaces (const std::string &str)
 
std::string replace_spaces (const std::string &str, const char rep)
 
std::string reduce_spaces (const std::string &str, const char rep)
 
std::string repeat (const char c, size_t n)
 
std::string spaces (size_t n)
 
std::string indent (const std::string &str, const int first, const int remaining)
 
std::string replace_copy (const std::string &str, const char from, const char to)
 
bool is_empty (const std::string &str)
 
bool is_empty (const char *str)
 
std::string unix2dos (const std::string &str, const bool force_eol=false)
 
template<typename T >
std::vector< T > split (const T &str, const typename T::value_type sep, const int maxsplit=-1)
 
template<class T >
auto join (const T &strings, const typename T::value_type &delim, const bool tail=false)
 
std::vector< std::string > from_argv (int argc, char *argv[], const bool skip_first)
 
std::string trim_left_copy (const std::string &str)
 
std::string trim_copy (const std::string &str)
 
std::string to_upper_copy (const std::string &str)
 
std::string to_lower_copy (const std::string &str)
 
void trim (std::string &str)
 
void trim_left (std::string &str)
 
void to_lower (std::string &str)
 
void to_upper (std::string &str)
 
std::string remove_blanks (const std::string &str)
 
std::string remove_char (const std::string &str, const char remove)
 
template<typename... ArgsT>
auto args_to_string (std::string_view delim, ArgsT &&...args) -> std::string
 Convert variadic arguments to a string.
 
template<typename... ArgsT>
auto format_safe (std::string format, ArgsT &&...args) noexcept -> std::optional< std::string >
 Format a string with error handling.
 

Function Documentation

◆ add_leading()

std::string openvpn::string::add_leading ( const std::string &  str,
const size_t  min_len,
const char  c 
)
inline

Definition at line 112 of file string.hpp.

◆ add_trailing()

void openvpn::string::add_trailing ( std::string &  str,
const char  c 
)
inline

Definition at line 134 of file string.hpp.

Here is the caller graph for this function:

◆ add_trailing_copy()

std::string openvpn::string::add_trailing_copy ( const std::string &  str,
const char  c 
)
inline

Definition at line 126 of file string.hpp.

Here is the caller graph for this function:

◆ add_trailing_crlf()

void openvpn::string::add_trailing_crlf ( std::string &  str)
inline

Definition at line 141 of file string.hpp.

Here is the caller graph for this function:

◆ add_trailing_crlf_copy()

std::string openvpn::string::add_trailing_crlf_copy ( std::string  str)
inline

Definition at line 157 of file string.hpp.

Here is the caller graph for this function:

◆ add_trailing_unless_empty_copy()

std::string openvpn::string::add_trailing_unless_empty_copy ( const std::string &  str,
const char  c 
)
inline

Definition at line 164 of file string.hpp.

◆ args_to_string()

template<typename... ArgsT>
auto openvpn::string::args_to_string ( std::string_view  delim,
ArgsT &&...  args 
) -> std::string
inline

Convert variadic arguments to a string.

This function takes a delimiter and a variadic number of arguments, and concatenates them into a single string, separated by the specified delimiter. The function uses a fold expression to handle the variadic arguments and formats each argument using format. The resulting string is returned.

Note
The function is designed to work with any type that can be formatted
Template Parameters
ArgsTvariadic template parameter pack for the arguments to be formatted.
Parameters
delimThe delimiter to be used for separating the arguments in the resulting string.
argsThe variadic arguments to be concatenated into a string.
Returns
std::string The concatenated string with the specified delimiter separating the arguments.
Exceptions
format_errorif formatting fails.
exceptionsfrom std::string operations

Definition at line 659 of file string.hpp.

Here is the caller graph for this function:

◆ contains_non_space_ctrl()

bool openvpn::string::contains_non_space_ctrl ( const std::string &  str)
inline

Definition at line 298 of file string.hpp.

◆ contains_space()

bool openvpn::string::contains_space ( const std::string &  str)
inline

Definition at line 307 of file string.hpp.

◆ copy_fill()

void openvpn::string::copy_fill ( void *  dest,
const std::string &  src,
const size_t  dest_size 
)
inline

Definition at line 67 of file string.hpp.

◆ embedded_null()

bool openvpn::string::embedded_null ( const char *  str,
size_t  len 
)
inline

Definition at line 187 of file string.hpp.

Here is the caller graph for this function:

◆ ends_with_crlf()

template<typename STRING >
bool openvpn::string::ends_with_crlf ( const STRING &  str)
inline

Definition at line 100 of file string.hpp.

Here is the caller graph for this function:

◆ ends_with_newline()

template<typename STRING >
bool openvpn::string::ends_with_newline ( const STRING &  str)
inline

Definition at line 93 of file string.hpp.

Here is the caller graph for this function:

◆ first_line()

std::string openvpn::string::first_line ( const std::string &  str)
inline

Definition at line 220 of file string.hpp.

◆ format_safe()

template<typename... ArgsT>
auto openvpn::string::format_safe ( std::string  format,
ArgsT &&...  args 
) -> std::optional<std::string>
inlinenoexcept

Format a string with error handling.

This function attempts to format a string using the provided format and arguments. If an exception occurs during formatting, it catches the exception and returns std::nullopt to indicate that the formatting failed.

Template Parameters
ArgsTvariadic template parameter pack for the arguments to be formatted.
Parameters
formatThe format string to be used for formatting.
argsThe arguments to be formatted into the string.
Returns
std::optional<std::string> The formatted string or nullopt on format error
Note
This function uses vformat and make_format_args for formatting.
The function is designed to handle exceptions that may occur during formatting, including std::exception and other unknown exceptions. If an exception occurs, it returns a nullopt to indicate that the formatting failed.

Definition at line 681 of file string.hpp.

Here is the caller graph for this function:

◆ from_argv()

std::vector< std::string > openvpn::string::from_argv ( int  argc,
char *  argv[],
const bool  skip_first 
)
inline

Definition at line 501 of file string.hpp.

Here is the caller graph for this function:

◆ indent()

std::string openvpn::string::indent ( const std::string &  str,
const int  first,
const int  remaining 
)
inline

Definition at line 381 of file string.hpp.

Here is the caller graph for this function:

◆ is_alpha()

bool openvpn::string::is_alpha ( const char  c)
inline

Definition at line 249 of file string.hpp.

◆ is_alphanumeric()

bool openvpn::string::is_alphanumeric ( const char  c)
inline

Definition at line 254 of file string.hpp.

Here is the caller graph for this function:

◆ is_ctrl() [1/2]

bool openvpn::string::is_ctrl ( const char  c)
inline

Definition at line 269 of file string.hpp.

Here is the caller graph for this function:

◆ is_ctrl() [2/2]

bool openvpn::string::is_ctrl ( const unsigned char  c)
inline

Definition at line 274 of file string.hpp.

◆ is_digit()

bool openvpn::string::is_digit ( const char  c)
inline

Definition at line 244 of file string.hpp.

Here is the caller graph for this function:

◆ is_empty() [1/2]

bool openvpn::string::is_empty ( const char *  str)
inline

Definition at line 417 of file string.hpp.

◆ is_empty() [2/2]

bool openvpn::string::is_empty ( const std::string &  str)
inline

Definition at line 408 of file string.hpp.

Here is the caller graph for this function:

◆ is_multiline()

bool openvpn::string::is_multiline ( const std::string &  str)
inline

Definition at line 204 of file string.hpp.

Here is the caller graph for this function:

◆ is_printable() [1/3]

bool openvpn::string::is_printable ( const char  c)
inline

Definition at line 259 of file string.hpp.

Here is the caller graph for this function:

◆ is_printable() [2/3]

bool openvpn::string::is_printable ( const std::string &  str)
inline

Definition at line 289 of file string.hpp.

◆ is_printable() [3/3]

bool openvpn::string::is_printable ( const unsigned char  c)
inline

Definition at line 264 of file string.hpp.

◆ is_space()

bool openvpn::string::is_space ( const char  c)
inline

Define a common interpretation of what constitutes a space character.

According to the Notes section at https://en.cppreference.com/w/cpp/string/byte/isspace.html:

"Like all other functions from <cctype>, the behavior of <tt>std::isspace</tt> is undefined if the argument's value is neither representable as <tt>unsigned char</tt> nor equal to <tt>EOF</tt>. To use these functions safely with plain chars (or signed chars), the argument should first be converted to <tt>unsigned char</tt>"

Returns
true if c is a space char.

Definition at line 239 of file string.hpp.

Here is the caller graph for this function:

◆ is_true()

bool openvpn::string::is_true ( const std::string &  str)
inline

Definition at line 77 of file string.hpp.

Here is the caller graph for this function:

◆ is_word()

bool openvpn::string::is_word ( const std::string &  str)
inline

Definition at line 280 of file string.hpp.

Here is the caller graph for this function:

◆ join()

template<class T >
auto openvpn::string::join ( const T &  strings,
const typename T::value_type &  delim,
const bool  tail = false 
)
inline

Definition at line 481 of file string.hpp.

Here is the caller graph for this function:

◆ len_without_trailing_nulls()

size_t openvpn::string::len_without_trailing_nulls ( const char *  str,
size_t  len 
)
inline

Definition at line 196 of file string.hpp.

◆ reduce_spaces()

std::string openvpn::string::reduce_spaces ( const std::string &  str,
const char  rep 
)
inline

Definition at line 345 of file string.hpp.

Here is the caller graph for this function:

◆ remove_blanks()

std::string openvpn::string::remove_blanks ( const std::string &  str)
inline

Definition at line 580 of file string.hpp.

Here is the caller graph for this function:

◆ remove_char()

std::string openvpn::string::remove_char ( const std::string &  str,
const char  remove 
)
inline

Definition at line 631 of file string.hpp.

◆ remove_spaces()

std::string openvpn::string::remove_spaces ( const std::string &  str)
inline

Definition at line 316 of file string.hpp.

◆ repeat()

std::string openvpn::string::repeat ( const char  c,
size_t  n 
)
inline

Definition at line 365 of file string.hpp.

Here is the caller graph for this function:

◆ replace_copy()

std::string openvpn::string::replace_copy ( const std::string &  str,
const char  from,
const char  to 
)
inline

Definition at line 398 of file string.hpp.

◆ replace_spaces()

std::string openvpn::string::replace_spaces ( const std::string &  str,
const char  rep 
)
inline

Definition at line 329 of file string.hpp.

◆ spaces()

std::string openvpn::string::spaces ( size_t  n)
inline

Definition at line 375 of file string.hpp.

Here is the caller graph for this function:

◆ split()

template<typename T >
std::vector< T > openvpn::string::split ( const T &  str,
const typename T::value_type  sep,
const int  maxsplit = -1 
)
inline

Definition at line 452 of file string.hpp.

Here is the caller graph for this function:

◆ starts_with_delim()

template<typename STRING >
bool openvpn::string::starts_with_delim ( const STRING &  str,
const std::string &  prefix,
const char  delim 
)
inline

Definition at line 84 of file string.hpp.

◆ strcasecmp() [1/4]

int openvpn::string::strcasecmp ( const char *  s1,
const char *  s2 
)
inline

Definition at line 33 of file string.hpp.

Here is the caller graph for this function:

◆ strcasecmp() [2/4]

int openvpn::string::strcasecmp ( const char *  s1,
const std::string &  s2 
)
inline

Definition at line 47 of file string.hpp.

◆ strcasecmp() [3/4]

int openvpn::string::strcasecmp ( const std::string &  s1,
const char *  s2 
)
inline

Definition at line 42 of file string.hpp.

◆ strcasecmp() [4/4]

int openvpn::string::strcasecmp ( const std::string &  s1,
const std::string &  s2 
)
inline

Definition at line 52 of file string.hpp.

◆ strncpynt()

void openvpn::string::strncpynt ( char *  dest,
const char *  src,
size_t  maxlen 
)
inline

Definition at line 58 of file string.hpp.

Here is the caller graph for this function:

◆ to_delim()

std::string openvpn::string::to_delim ( const std::string &  str,
const char  delim 
)
inline

Definition at line 211 of file string.hpp.

Here is the caller graph for this function:

◆ to_lower()

void openvpn::string::to_lower ( std::string &  str)
inline

Definition at line 567 of file string.hpp.

Here is the caller graph for this function:

◆ to_lower_copy()

std::string openvpn::string::to_lower_copy ( const std::string &  str)
inline

Definition at line 547 of file string.hpp.

Here is the caller graph for this function:

◆ to_upper()

void openvpn::string::to_upper ( std::string &  str)
inline

Definition at line 572 of file string.hpp.

◆ to_upper_copy()

std::string openvpn::string::to_upper_copy ( const std::string &  str)
inline

Definition at line 537 of file string.hpp.

Here is the caller graph for this function:

◆ trim()

void openvpn::string::trim ( std::string &  str)
inline

Definition at line 557 of file string.hpp.

Here is the caller graph for this function:

◆ trim_copy()

std::string openvpn::string::trim_copy ( const std::string &  str)
inline

Definition at line 519 of file string.hpp.

Here is the caller graph for this function:

◆ trim_crlf()

template<typename STRING >
void openvpn::string::trim_crlf ( STRING &  str)
inline

Definition at line 173 of file string.hpp.

Here is the caller graph for this function:

◆ trim_crlf_copy()

std::string openvpn::string::trim_crlf_copy ( std::string  str)
inline

Definition at line 180 of file string.hpp.

Here is the caller graph for this function:

◆ trim_left()

void openvpn::string::trim_left ( std::string &  str)
inline

Definition at line 562 of file string.hpp.

◆ trim_left_copy()

std::string openvpn::string::trim_left_copy ( const std::string &  str)
inline

Definition at line 509 of file string.hpp.

Here is the caller graph for this function:

◆ unix2dos()

std::string openvpn::string::unix2dos ( const std::string &  str,
const bool  force_eol = false 
)
inline

Definition at line 429 of file string.hpp.

Here is the caller graph for this function: