![]() |
General Utility Library for C++17 25.4.1
|
Various string utility functions.
Functions | |
template<typename Integer , std::enable_if_t< std::is_integral< Integer >::value, bool > = true> | |
std::string | gul17::hex_string (Integer v) |
Return the hexadecimal ASCII representation of an integer value. | |
template<typename Iterator > | |
std::string | gul17::hex_string (Iterator begin, Iterator end, std::string_view separator="") |
Return the hexadecimal ASCII representation of a range of integer values. | |
template<typename Integer , size_t num_elements, std::enable_if_t< std::is_integral< Integer >::value, bool > = true> | |
std::string | gul17::hex_string (const Integer(&array)[num_elements], std::string_view separator="") |
Return the hexadecimal ASCII representation of an array with integer values. | |
template<typename Container , std::enable_if_t< IsContainerLike< Container >::value, bool > = true> | |
std::string | gul17::hex_string (const Container &container, std::string_view separator="") |
Return the hexadecimal ASCII representation of a container with integer values. | |
GUL_EXPORT std::string | gul17::null_safe_string (const char *char_ptr) |
Safely construct a std::string from a C string or a null pointer. | |
GUL_EXPORT std::string_view | gul17::null_safe_string_view (const char *char_ptr) |
Safely construct a string_view from a char pointer. | |
GUL_EXPORT std::string | gul17::repeat (std::string_view str, std::size_t n) |
Repeat a string N times. | |
GUL_EXPORT std::string | gul17::safe_string (const char *char_ptr, std::size_t length) |
Safely construct a std::string from a char pointer and a length. | |
GUL_EXPORT std::string_view | gul17::safe_string_view (const char *char_ptr, std::size_t length) |
Safely construct a string_view from a char pointer and a length. | |
Variables | |
GUL_EXPORT const std::string_view | gul17::default_whitespace_characters { " \t\r\n\a\b\f\v" } |
The default characters that are treated as whitespace by GUL. | |
GUL_EXPORT const std::array< char, 16 > | gul17::hex_digits |
The 16 digits for hexadecimal numbers ("0123456789abcdef"). | |
|
inline |
Return the hexadecimal ASCII representation of a container with integer values.
The letters 'a' to 'f' are used in lowercase, and no separators are inserted between individual values.
container | Input container |
separator | A string that is inserted between the elements to separate them visually (empty by default) |
Container | must be a gul17::IsContainerLike class |
References gul17::bit_set(), and gul17::hex_string().
|
inline |
Return the hexadecimal ASCII representation of an array with integer values.
The letters 'a' to 'f' are used in lowercase, and a user-defined separator can be inserted between individual values.
array | Input array |
separator | A string that is inserted between the elements to separate them visually (empty by default) |
Integer | must be an integral type. |
num_elements | is the number of array elements. |
References gul17::bit_set(), and gul17::hex_string().
|
inline |
Return the hexadecimal ASCII representation of an integer value.
The letters 'a' to 'f' are used in lowercase, and the number of hex digits is twice the number of bytes in the input integer type.
v | Input value |
Integer | must be an integral type. |
References gul17::bit_set(), and gul17::hex_digits.
Referenced by gul17::hex_string(), gul17::hex_string(), and gul17::hex_string().
|
inline |
Return the hexadecimal ASCII representation of a range of integer values.
The letters 'a' to 'f' are used in lowercase, and a user-defined separator can be inserted between individual values.
begin | Iterator to the first element of the range |
end | Iterator past the last element of the range |
separator | A string that is inserted between the elements to separate them visually (empty by default) |
Iterator | must be a forward iterator. |
References gul17::bit_set(), and gul17::hex_string().
Safely construct a std::string from a C string or a null pointer.
If the pointer is null, an empty string is constructed. Otherwise, the function assumes to find a zero-terminated C string and constructs a std::string from it.
char_ptr | Pointer to a null-terminated string or a null pointer |
References gul17::bit_set().
Safely construct a string_view from a char pointer.
If the pointer is null, an empty string_view is constructed. Otherwise, the function assumes to find a zero-terminated C string and constructs a std::string_view from it.
char_ptr | Pointer to a null-terminated string or a null pointer |
References gul17::bit_set().
std::string gul17::repeat | ( | std::string_view | str, |
std::size_t | n | ||
) |
Repeat a string N times.
str | String to be repeated |
n | Number of repetitions |
References gul17::bit_set().
Safely construct a std::string from a char pointer and a length.
If the pointer is null, an empty string is constructed. If there are no zero bytes in the input range, a string of length length
is constructed. Otherwise, the input string is treated as a C string and the first zero byte is treated as the end of the string.
char_ptr | Pointer to a string that is either null-terminated or has at least length accessible bytes, or a null pointer |
length | Maximum length of the generated string |
References gul17::bit_set().
Safely construct a string_view from a char pointer and a length.
If the pointer is null, an empty string_view is constructed. If there are no zero bytes in the input range, a string_view of length length
is constructed. Otherwise, the input string is treated as a C string and the first zero byte is treated as the end of the string.
char_ptr | Pointer to a string that is either null-terminated or has at least length accessible bytes, or a null pointer |
length | Maximum length of the generated string_view |
References gul17::bit_set().
const std::string_view gul17::default_whitespace_characters { " \t\r\n\a\b\f\v" } |
The default characters that are treated as whitespace by GUL.
This is a string view that contains the space and the most common control characters, namely (with their ASCII codes):
The 16 digits for hexadecimal numbers ("0123456789abcdef").
Referenced by gul17::hex_string().