Classes | List of all members
clan::StringFormat Class Reference
clanCore Text

String formatting class. More...

`#include <string_format.h>`

## Public Member Functions
Construction
| StringFormat (const std::string &format_string)
| Constructs a formatted string object. More...
| ~StringFormat ()
Attributes
const std::string & | get_result () const
| Retrieves the formatted string with all argument replacements. More...
Operations
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 unsigned int value, int min_length=0)
| Sets an argument (long 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...

## Detailed Description

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:

clan::StringFormat format("Arg0: %0, Arg1: %1");
format.set_arg(0, 10);
format.set_arg(1, "test");
std::string result = format.get_result();
// result will now contain "Arg0: 10, Arg1: test"

The global function clan::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:

std::string result = clan::string_format("1st arg: %1, 2nd arg: %2", 10, "test");
// result will now contain "1st arg: 10, 2nd arg: test"

The documentation for this class was generated from the following file:

- string_format.h