Util
#include <tpau-cpp-kernal/Util.h>
This header file collects various utility functions.
function default_output_filename
Get a default output file name based on input file name and extension.
It discards the directory part of the input file name and replaces the extension.
| std::filesystem::path default_output_filename | ( | const std::filesystem::path & input_filename, | |
| std::string_view extension | ); |
| PARAMETER | DESCRIPTION |
|---|---|
input_filename |
The input file name. |
extension |
The extension to use for the output file name. |
| RETURNS | DESCRIPTION |
|---|---|
std::filesystem::path |
The default output file name. |
function get_with_fallback
Get the value associated with a key in an unordered map, or return a fallback value if the key is not found.
| V get_with_fallback | ( | const std::unordered_map< K, V > & map, | |
| const K & key, | |||
| V fallback | ); |
| PARAMETER | DESCRIPTION |
|---|---|
map |
The unordered map to search. |
key |
The key to look for. |
fallback |
The fallback value to return if the key is not found. |
| RETURNS | DESCRIPTION |
|---|---|
V |
The value associated with the key, or the fallback value if the key is not found. |
function join
Join a vector of symbols into a string with a separator between the symbols.
| std::string join | ( | const std::vector< Symbol > & symbols, | |
| std::string_view separator = ", " | ); |
| PARAMETER | DESCRIPTION |
|---|---|
symbols |
The symbols to join. |
separator |
The separator to use between the symbols. |
| RETURNS | DESCRIPTION |
|---|---|
std::string |
The joined string. |
function join
Join a range of strings into a string with a separator between the strings.
| std::string join | ( | const R & strings, | |
| std::string_view separator | ); |
| PARAMETER | DESCRIPTION |
|---|---|
strings |
The range of strings to join. |
separator |
The separator to use between the strings. |
| RETURNS | DESCRIPTION |
|---|---|
std::string |
The joined string. |
function replace_extension
Replace the extension of a file name with a new extension.
| std::filesystem::path replace_extension | ( | const std::filesystem::path & file_name, | |
| std::string_view extension | ); |
| PARAMETER | DESCRIPTION |
|---|---|
file_name |
The file name to replace the extension of. |
extension |
The new extension to use. |
| RETURNS | DESCRIPTION |
|---|---|
std::filesystem::path |
The file name with the replaced extension. |
function sorted
Sort a range of elements and return the sorted collection.
| std::vector< T > sorted | ( | const R & collection, | |
| Comp comp = {} | ); |
| PARAMETER | DESCRIPTION |
|---|---|
collection |
The range of elements to sort. |
comp |
The comparison function to use for sorting. If not provided, the default comparison operator will be used. |
| RETURNS | DESCRIPTION |
|---|---|
std::vector< T > |
The sorted collection. |
function split
Split a string into a vector of strings based on a set of delimiters.
| std::vector< std::string > split | ( | std::string_view str, | |
| std::string_view delimiters = " \t\n\r\f\v", | |||
| bool keep_empty = false | ); |
| PARAMETER | DESCRIPTION |
|---|---|
str |
The string to split. |
delimiters |
The set of delimiters to use for splitting. |
keep_empty |
If |
| RETURNS | DESCRIPTION |
|---|---|
std::vector< std::string > |
The vector of split strings. |
function strerror_string
Get a string representation of a system error code.
| std::string strerror_string | ( | std::optional< int > errnum = {} | ); |
| PARAMETER | DESCRIPTION |
|---|---|
errnum |
The error code to get the string representation of. If not provided, the current value of |
| RETURNS | DESCRIPTION |
|---|---|
std::string |
The string representation of the error code. |
function trim
Trim characters from the beginning and end of a string.
| std::string_view trim | ( | std::string_view str, | |
| std::string_view characters = " \t\n\r\f\v" | ); |
| PARAMETER | DESCRIPTION |
|---|---|
str |
The string to trim. |
characters |
The set of characters to trim. |
| RETURNS | DESCRIPTION |
|---|---|
std::string_view |
The trimmed string. |