arg_router  1.4.0
C++ command line argument parsing and routing
arg_router::utility::exception_formatter< S > Class Template Reference

#include <arg_router/utility/exception_formatter.hpp>

Static Public Member Functions

static string format (const vector< parsing::token_type > &tokens)
 

Detailed Description

template<typename S>
class arg_router::utility::exception_formatter< S >

An incredibly simple and dumb formatter specifically for translated exception messages.

Only two placeholders are supported:

const auto str = exception_formatter<str<"Hello {}!">>::format({
{prefix_type::long_, "world"}
});
// str == "Hello --world!"
static string format(const vector< parsing::token_type > &tokens)

An empty bracket pair in the placeholder for a single token type.

const auto str1 = exception_formatter<str<"Hello {}, {, }, d">>::format({
{prefix_type::short_, "a"},
{prefix_type::long_, "b"},
{prefix_type::none, "c"}
});
// str1 == "Hello -a, --b, c, d"
const auto str2 = exception_formatter<str<"Hello {/}">>::format({
{prefix_type::short_, "a"},
{prefix_type::long_, "b"},
{prefix_type::none, "c"}
});
// str2 == "Hello -a/--b/c"

Whilst a bracket pair with at least one character in will greedily consume all remaining tokens, usng the string in the brace pair as the joining string for the remaining tokens. The brackets are checked at compile-time so that there is a maximum of only one greedy placeholder per string, and that it comes after the single token placeholders (if any).

If there are more tokens than placeholders, and none of the placeholders are greedy, then the remaining tokens are ignored. If there are less tokens, then the placeholders are replaced with empty strings.

Template Parameters
SCompile-time string type

Definition at line 53 of file exception_formatter.hpp.

Member Function Documentation

◆ format()

template<typename S >
static string arg_router::utility::exception_formatter< S >::format ( const vector< parsing::token_type > &  tokens)
inlinestatic

Format the string using tokens and rules in the description.

Parameters
tokensTokens to use
Returns
Formatted string

Definition at line 96 of file exception_formatter.hpp.


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