tango.text.convert.Layout

License:
BSD style:

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.

alias Arg;
Platform issues ...

alias ArgList;
Platform issues ...

class Layout(T);
Contains methods for replacing format items in a string with string equivalents of each argument.

Layout instance();
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,...);


T[] vprint(T[] result, const(T)[] formatStr, TypeInfo[] arguments, ArgList args);


T[] convert(const(T)[] formatStr,...);
Replaces the format item in a string with the string equivalent of each argument.

Params:
const(T)[] formatStr A string containing format items.
args A 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,...);


uint convert(OutputStream output, const(T)[] formatStr,...);
Tentative convert using an OutputStream as sink - may still be removed.

Since:
0.99.7

T[] convert(TypeInfo[] arguments, ArgList args, const(T)[] formatStr);


T[] convertOne(T[] result, TypeInfo ti, Arg arg);


uint convert(Sink sink, TypeInfo[] arguments, ArgList args, const(T)[] formatStr);


uint parse(const(T)[] layout, TypeInfo[] ti, Arg[] args, Sink sink);
Parse the format-string, emitting formatted args and text fragments as we go

T[] dispatch(T[] result, const(T)[] format, const(TypeInfo) type, Arg p);


T[] unknown(T[] result, const(T)[] format, const(TypeInfo) type, Arg p);
handle "unknown-type" errors

T[] integer(T[] output, long v, const(T)[] format, ulong mask = (ulong).max, const(T)[] def = "d");
Format an integer value

T[] floater(T[] output, real v, const(T)[] format);
format a floating-point value. Defaults to 2 decimal places

void error(char[] msg);


size_t spaces(Sink sink, int count);


T[] imaginary(T[] result, ireal val, const(T)[] format);
format an imaginary value

T[] complex(T[] result, creal val, const(T)[] format);
format a complex value

T[] floatingTail(T[] result, real val, const(T)[] format, const(T)[] tail);
formats a floating-point value, and appends a tail to it

enum TypeCode;



Page generated by Ddoc. Copyright (c) 2005 Kris. All rights reserved