Various string utility functions.
|
template<typename Integer , std::enable_if_t< std::is_integral< Integer >::value, bool > = true> |
std::string | gul14::hex_string (Integer v) |
| Return the hexadecimal ASCII representation of an integer value. More...
|
|
template<typename Iterator > |
std::string | gul14::hex_string (Iterator begin, Iterator end, string_view separator="") |
| Return the hexadecimal ASCII representation of a range of integer values. More...
|
|
template<typename Integer , size_t num_elements, std::enable_if_t< std::is_integral< Integer >::value, bool > = true> |
std::string | gul14::hex_string (const Integer(&array)[num_elements], string_view separator="") |
| Return the hexadecimal ASCII representation of an array with integer values. More...
|
|
template<typename Container , std::enable_if_t< IsContainerLike< Container >::value, bool > = true> |
std::string | gul14::hex_string (const Container &container, string_view separator="") |
| Return the hexadecimal ASCII representation of a container with integer values. More...
|
|
GUL_EXPORT std::string | gul14::repeat (gul14::string_view str, std::size_t n) |
| Repeat a string N times. More...
|
|
GUL_EXPORT std::string | gul14::safe_string (const char *char_ptr, std::size_t length) |
| Safely construct a std::string from a char pointer and a length. More...
|
|
◆ hex_string() [1/4]
template<typename Container , std::enable_if_t< IsContainerLike< Container >::value, bool > = true>
std::string gul14::hex_string |
( |
const Container & |
container, |
|
|
string_view |
separator = "" |
|
) |
| |
|
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.
std::array<unsigned char, 4> values = { 0, 15, 16, 255 };
std::string hex_string(Integer v)
Return the hexadecimal ASCII representation of an integer value.
Definition: string_util.h:113
- Parameters
-
container | Input container |
separator | A string that is inserted between the elements to separate them visually (empty by default) |
- Template Parameters
-
- Since
- GUL version 2.6
References gul14::hex_string().
◆ hex_string() [2/4]
template<typename Integer , size_t num_elements, std::enable_if_t< std::is_integral< Integer >::value, bool > = true>
std::string gul14::hex_string |
( |
const Integer(&) |
array[num_elements], |
|
|
string_view |
separator = "" |
|
) |
| |
|
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.
uint16_t values[] = { 256, 255 };
- Parameters
-
array | Input array |
separator | A string that is inserted between the elements to separate them visually (empty by default) |
- Template Parameters
-
Integer | must be an integral type. |
num_elements | is the number of array elements. |
- Since
- GUL version 2.6
References gul14::hex_string().
◆ hex_string() [3/4]
template<typename Integer , std::enable_if_t< std::is_integral< Integer >::value, bool > = true>
std::string gul14::hex_string |
( |
Integer |
v | ) |
|
|
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.
hex_string(
static_cast<unsigned char>(255)) ==
"ff";
- Parameters
-
- Template Parameters
-
Integer | must be an integral type. |
- Since
- GUL version 2.6
References gul14::hex_digits.
Referenced by gul14::hex_string().
◆ hex_string() [4/4]
template<typename Iterator >
std::string gul14::hex_string |
( |
Iterator |
begin, |
|
|
Iterator |
end, |
|
|
string_view |
separator = "" |
|
) |
| |
|
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.
std::array<unsigned char, 4> values = { 0, 15, 16, 255 };
assert(
hex_string(values.begin(), values.end()) ==
"000f10ff");
assert(
hex_string(values.begin(), values.end(),
"-") ==
"00-0f-10-ff");
- Parameters
-
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) |
- Template Parameters
-
Iterator | must be a forward iterator. |
- Since
- GUL version 2.6
References gul14::hex_string().
◆ repeat()
Repeat a string N times.
std::string str =
repeat(
"du", 3);
GUL_EXPORT std::string repeat(gul14::string_view str, std::size_t n)
Repeat a string N times.
Definition: string_util.cc:33
- Parameters
-
str | String to be repeated |
n | Number of repetitions |
- Returns
- the N-fold concatenation of the input string.
- Since
- GUL version 2.7
◆ safe_string()
std::string gul14::safe_string |
( |
const char * |
char_ptr, |
|
|
std::size_t |
length |
|
) |
| |
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.
GUL_EXPORT std::string safe_string(const char *char_ptr, std::size_t length)
Safely construct a std::string from a char pointer and a length.
Definition: string_util.cc:44
- Parameters
-
char_ptr | Pointer to a C string, an unterminated string of at least the specified length, or null. |
length | Maximum length of the generated string. |
- Since
- GUL version 2.6
◆ default_whitespace_characters
const string_view gul14::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):
- Bell/alert (7)
- Backspace (8)
- Horizontal tabulator (9)
- Newline/line feed (10)
- Vertical Tab (11)
- Form feed (12)
- Carriage return (13)
- Space (32)
- Note
- The null character is not treated as whitespace by default.
◆ hex_digits
const std::array< char, 16 > gul14::hex_digits |
Initial value:{
{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'} }
The 16 digits for hexadecimal numbers ("0123456789abcdef").
Referenced by gul14::hex_string().