|
template<typename T , size_t Count> |
constexpr size_t | countof (T(&)[Count]) |
| Like sizeof(), but it returns the number of elements an array consists of instead of the number of bytes. More...
|
|
template<typename... Args> |
void | sprintf (Args...) |
| This is a safeguard against accidentally using sprintf(). More...
|
|
template<size_t Size, typename... Args> |
int | sprintf_safe (char(&dst)[Size], char const *const format, Args const ... args) |
| A wrapper around snprintf() that automatically pulls in the destination buffer size. More...
|
|
template<class ET , typename VT = typename std::underlying_type<ET>::type> |
constexpr VT | to_value (ET const op) |
| Casts an enum to its underlying value. More...
|
|
Underlined | highlight (std::string const &str, ptrdiff_t const offs, ptrdiff_t const len=1) |
| Underline the given number of characters. More...
|
|
A collection of generally useful functions.
utility::Underlined utility::highlight |
( |
std::string const & |
str, |
|
|
ptrdiff_t const |
offs, |
|
|
ptrdiff_t const |
len = 1 |
|
) |
| |
Underline the given number of characters.
The given length and offset use byte-addressing, the resulting text is sanitised for printing, which may affect the actual number of underlining characters:
- Control characters, multi-byte character fragments and invalid code points are substituted by printf-style escapes
- Multi-byte characters are underlined with a single character
Double width characters are not supported (i.e. the resulting underline is too short).
The underlining string is only as long as it needs to be, i.e. it is not right-padded with white space.
- Parameters
-
str | The string to sanitise and underline |
offs,len | The byte-offset and length of the underline |
- Returns
- The sanitised text and the underline