tanya.format

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

Format string is a $(D_PSYMBOL string) which can contain placeholders for arguments. Placeholder marker is {}, i.e. all occurrences of {} are replaced by the arguments passed to $(D_PSYMBOL 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 $(D_PSYMBOL 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 $(D_KEYWORD class) or $(D_KEYWORD struct)), toString()-function can be implemented for that type. toString() should be $(D_KEYWORD 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.

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

All floating point numbers are handled as $(D_KEYWORD double)s.

More advanced formatting is currently not implemented.

Members

Functions

format
String format(Args args)

Produces a string according to the specified format.

integral2String
char[] integral2String(T number, char[21] buffer)
Undocumented in source. Be warned that the author may not have intended to support it.
sformat
R sformat(R output, Args args)

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

Meta