BSD style: see license.txt


Initial release: 2005


Kris, Keinfarbton

This module provides a general-purpose formatting system to convert values to text suitable for display. There is support for alignment, justification, and common format specifiers for numbers.

Layout can be customized via configuring various handlers and associated meta-data. This is utilized to plug in text.locale for handling custom formats, date/time and culture-specific conversions.

The format notation is influenced by that used by the .NET and ICU frameworks, rather than C-style printf or D-style writef notation.

class Layout(T) #
Contains methods for replacing format items in a string with string equivalents of each argument.
Layout instance() [static] #
Return shared instance
Note that this is not threadsafe, and that static-ctor usage doesn't get invoked appropriately (compiler bug)
T[] sprint(T[] result, T[] formatStr, ...) [public, final] #
T[] vprint(T[] result, T[] formatStr, TypeInfo[] arguments, ArgList args) [public, final] #
T[] convert(T[] formatStr, ...) [public, final] #
Replaces the _format item in a string with the string equivalent of each argument.


formatStrA string containing _format items.
argsA list of arguments.


A copy of formatStr in which the items have been replaced by the string equivalent of the arguments.


The formatStr parameter is embedded with _format items of the form:


  • index
    An integer indicating the element in a list to _format.
  • alignment
    An optional integer indicating the minimum width. The result is padded with spaces if the length of the value is less than alignment.
  • _format-string
    An optional string of formatting codes.

The leading and trailing braces are required. To include a literal brace character, use two leading or trailing brace characters.

If formatStr is "{0} bottles of beer on the wall" and the argument is an int with the value of 99, the return value will be:
"99 bottles of beer on the wall".

uint convert(Sink sink, T[] formatStr, ...) [public, final] #
uint convert(OutputStream output, T[] formatStr, ...) [public, final] #
Tentative convert using an OutputStream as sink - may still be removed.


T[] convert(TypeInfo[] arguments, ArgList args, T[] formatStr) [public, final] #
uint convert(Sink sink, TypeInfo[] arguments, ArgList args, T[] formatStr) [public, final] #
uint parse(T[] layout, TypeInfo[] ti, Arg[] args, Sink sink) [private] #
Parse the format-string, emitting formatted args and text fragments as we go
T[] dispatch(T[] result, T[] format, TypeInfo type, Arg p) [private] #
T[] unknown(T[] result, T[] format, TypeInfo type, Arg p) [protected] #
handle "unknown-type" errors
T[] integer(T[] output, long v, T[] format, ulong mask = ulong.max, T[] def = "d") [protected] #
Format an integer value
T[] floater(T[] output, real v, T[] format) [protected] #
format a floating-point value. Defaults to 2 decimal places
void error(char[] msg) [private] #
uint spaces(Sink sink, int count) [private] #
T[] imaginary(T[] result, ireal val, T[] format) [private] #
format an imaginary value
T[] complex(T[] result, creal val, T[] format) [private] #
format a complex value
T[] floatingTail(T[] result, real val, T[] format, T[] tail) [private] #
formats a floating-point value, and appends a tail to it
enum TypeCode [private] #