Module tanya.format

This module provides format function that can convert different data types to a String according to a specified format.

Format string is a string which can contain placeholders for arguments. Placeholder marker is {}, i.e. all occurrences of {} are replaced by the arguments passed to format. An argument will be first converted to a string, then inserted into the resulting string instead of the corresponding placeholder. The number of the placeholders and arguments must match. The placeholders are replaced with the arguments in the order arguments are passed to format.

To escape { or }, use {{ and }} respectively. {{ will be outputted as a single {, }} - as a single }.

To define the string representation for a custom data type (like class or struct), toString()-function can be implemented for that type. toString() should be const and accept exactly one argument: an output range for const(char)[]. It should return the same output range, advanced after putting the corresponding value into it. That is toString() signature should look like:

OR toString(OR)(OR range) const
if (isOutputRange!(OR, const(char)[]));

String conversions for the most built-in data types a also available.

char, wchar and dchar ranges are outputted as plain strings (without any delimiters between their elements).

All floating point numbers are handled as doubles.

More advanced formatting is currently not implemented.

Functions

NameDescription
format(args) Produces a string according to the specified format.
sformat(output, args) Produces a string according to the specified format and writes it into an output range. sformat writes the final string in chunks, so the output range should be in output range for const(char)[].