String formatting class. More...
#include <string_format.h>
Public Member Functions | |
StringFormat (const std::string &format_string) | |
Constructs a formatted string object. More... | |
const std::string & | result () const |
Retrieves the formatted string with all argument replacements. More... | |
void | set_arg (int index, const std::string &text) |
Sets an argument (string version) More... | |
void | set_arg (int index, int value, int min_length=0) |
Sets an argument (int version) More... | |
void | set_arg (int index, unsigned int value, int min_length=0) |
Sets an argument (unsigned int version) More... | |
void | set_arg (int index, long long value, int min_length=0) |
Sets an argument (long long version) More... | |
void | set_arg (int index, unsigned long long value, int min_length=0) |
Sets an argument (unsigned long long version) More... | |
void | set_arg (int index, float value) |
Sets an argument (float version) More... | |
void | set_arg (int index, double value) |
Sets an argument (double version) More... | |
String formatting class.
Combines a format string with arbitrary arguments to create a resulting string that contains the inserted arguments.
A format string consists of normal text and placeholders that are replaced by the given arguments. A placeholder is identified by a percentage symbol '%' followed by an integer that represents the argument index.
Example:
The global function uicore::string_format is a shortcut to create formatted strings. Note that the indexing starts at 1 when using this function. Therefore the first argument is automatically referenced by the placeholder %1.
Example:
uicore::StringFormat::StringFormat | ( | const std::string & | format_string | ) |
Constructs a formatted string object.
format_string | = Format string (see detailed description) |
const std::string& uicore::StringFormat::result | ( | ) | const |
Retrieves the formatted string with all argument replacements.
Referenced by uicore::string_format().
void uicore::StringFormat::set_arg | ( | int | index, |
const std::string & | text | ||
) |
Sets an argument (string version)
index | = Argument index |
text | = Argument value as a string |
Referenced by uicore::string_format().
void uicore::StringFormat::set_arg | ( | int | index, |
int | value, | ||
int | min_length = 0 |
||
) |
Sets an argument (int version)
index | = Argument index |
value | = Argument value as an integer |
min_length | = Minimum amount of digits to display |
void uicore::StringFormat::set_arg | ( | int | index, |
unsigned int | value, | ||
int | min_length = 0 |
||
) |
Sets an argument (unsigned int version)
index | = Argument index |
value | = Argument value as an unsigned integer |
min_length | = Minimum amount of digits to display |
void uicore::StringFormat::set_arg | ( | int | index, |
long long | value, | ||
int | min_length = 0 |
||
) |
Sets an argument (long long version)
index | = Argument index |
value | = Argument value as a long long |
min_length | = Minimum amount of digits to display |
void uicore::StringFormat::set_arg | ( | int | index, |
unsigned long long | value, | ||
int | min_length = 0 |
||
) |
Sets an argument (unsigned long long version)
index | = Argument index |
value | = Argument value as an unsigned long long |
min_length | = Minimum amount of digits to display |
void uicore::StringFormat::set_arg | ( | int | index, |
float | value | ||
) |
Sets an argument (float version)
index | = Argument index |
value | = Argument value as a floating point value |
void uicore::StringFormat::set_arg | ( | int | index, |
double | value | ||
) |
Sets an argument (double version)
index | = Argument index |
value | = Argument value as a floating point value with double precision |