Skip to content

ST::format

Michael Hansen edited this page Nov 22, 2019 · 5 revisions

ST::format

Headers

#include <string_theory/format>

Public Functions

Name Summary
ST::format Format a UTF-8 ST::string from type-safe parameters
ST::format_latin_1 Format a Latin-1 ST::string from type-safe parameters

Function Documentation

ST::format

Signature
template <typename... args_T>
ST::string ST::format(const char *fmt_str, args_T ...args)

template <typename... args_T>
ST::string ST::format(const char *fmt_str, args_T &&...args)
(1)
template <typename... args_T>
ST::string ST::format(ST::utf_validation_t validation, const char *fmt_str, args_T ...args)

template <typename... args_T>
ST::string ST::format(ST::utf_validation_t validation, const char *fmt_str, args_T &&...args)
(2)

Creates a formatted ST::string object with the specified formatting and data.

  1. This function assumes UTF-8 and uses the default verification (specified by ST_DEFAULT_VALIDATION) to check the resulting string data.
  2. This function assumes UTF-8 and uses the validation parameter to control how the resulting string data is validated.

Changed in 3.0: The arguments in args are now forwarded to reduce copying.


ST::format_latin_1

Signature
template <typename... args_T>
ST::string ST::format_latin_1(const char *fmt_str, args_T ...args)

template <typename... args_T>
ST::string ST::format_latin_1(const char *fmt_str, args_T &&...args)

Creates a formatted ST::string object with the specified formatting and data. This function assumes Latin-1 data, which means that no validation is done on the input.

Changed in 3.0: The arguments in args are now forwarded to reduce copying.


ST::literals::operator"" _stfmt

using namespace ST::literals;
Signature
opaque-type operator"" _stfmt(const char *fmt_str, size_t size)

User-defined literal operator to invoke ST::format on a literal string. The returned object is opaque, but provides an operator() overload to conveniently invoke ST::format.

auto str = "The answer is {}"_stfmt(42);

// Equivalent to:
auto str = ST::format("The answer is {}", 42);

Since: string_theory 3.0.

Clone this wiki locally