tango.text.convert.Layout

License:

BSD style: see license.txt

Version:

Initial release: 2005

Author:

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() [@property, 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, const(T)[] formatStr, ...) [public, final]
T[] vprint(T[] result, const(T)[] formatStr, TypeInfo[] arguments, ArgList args) [public, final]
T[] convert(const(T)[] formatStr, ...) [public, final]
Replaces the _format item in a string with the string equivalent of each argument.

Parameters:

formatStrA string containing _format items.
argsA list of arguments.

Returns:

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

Remarks:

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

{index[,alignment][:_format-string]}

  • 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, const(T)[] formatStr, ...) [public, final]
uint convert(OutputStream output, const(T)[] formatStr, ...) [public, final]
Tentative convert using an OutputStream as sink - may still be removed.

Since:

0.99.7
T[] convert(TypeInfo[] arguments, ArgList args, const(T)[] formatStr) [public, final]
uint convert(Sink sink, TypeInfo[] arguments, ArgList args, const(T)[] formatStr) [public, final]
T[] unknown(T[] result, const(T)[] format, const(TypeInfo) type, Arg p) [protected]
handle "unknown-type" errors
T[] integer(T[] output, long v, const(T)[] format, ulong mask = ulong.max, const(T)[] def = "d") [protected]
Format an integer value
T[] floater(T[] output, real v, const(T)[] format) [protected]
format a floating-point value. Defaults to 2 decimal places