FormatSpec

A General handler for printf style format specifiers. Used for building more specific formatting functions.

Constructors

this
this(Char[] fmt)

Construct a new FormatSpec using the format string fmt, no processing is done until needed.

Members

Functions

toString
string toString()
void toString(OutputRange writer)

Gives a string containing all of the member variables on their own line.

writeUpToNextSpec
bool writeUpToNextSpec(OutputRange writer)

Write the format string to an output range until the next format specifier is found and parse that format specifier.

Variables

DYNAMIC
enum int DYNAMIC;

Special value for width and precision. DYNAMIC width or precision means that they were specified with '*' in the format string and are passed at runtime through the varargs.

UNSPECIFIED
enum int UNSPECIFIED;

Special value for precision, meaning the format specifier contained no explicit precision.

flDash
bool flDash;

The format specifier contained a '-' (printf compatibility).

flHash
bool flHash;

The format specifier contained a '#' (printf compatibility).

flPlus
bool flPlus;

The format specifier contained a '+' (printf compatibility).

flSeparator
bool flSeparator;

The format specifier contained a ','

flSpace
bool flSpace;

The format specifier contained a ' ' (printf compatibility).

flZero
bool flZero;

The format specifier contained a '0' (printf compatibility).

indexEnd
ubyte indexEnd;

Index of the last argument for positional parameter range, from 1 to ubyte.max. (0 means not used).

indexStart
ubyte indexStart;

Index of the argument for positional parameters, from 1 to ubyte.max. (0 means not used).

nested
const(Char)[] nested;

In case of a compound format specifier starting with "%$(LPAREN)" and ending with "%$(RPAREN)", _nested contains the string contained within the two separators.

precision
int precision;

Precision. Its semantics depends on the argument type. For floating point numbers, precision dictates the number of decimals printed.

sep
const(Char)[] sep;

In case of a compound format specifier, _sep contains the string positioning after "%|". sep is null means no separator else sep.empty means 0 length separator.

separatorChar
dchar separatorChar;

Character to insert between digits.

separatorCharPos
int separatorCharPos;

Set to DYNAMIC when the separator character is supplied at runtime.

separators
int separators;

Number of digits printed between separators.

spec
char spec;

The actual format specifier, 's' by default.

trailing
const(Char)[] trailing;

_trailing contains the rest of the format string.

width
int width;

Minimum width, default 0.

Examples

1 import std.array;
2 auto a = appender!(string)();
3 auto fmt = "Number: %6.4e\nString: %s";
4 auto f = FormatSpec!char(fmt);
5 
6 assert(f.writeUpToNextSpec(a) == true);
7 
8 assert(a.data == "Number: ");
9 assert(f.trailing == "\nString: %s");
10 assert(f.spec == 'e');
11 assert(f.width == 6);
12 assert(f.precision == 4);
13 
14 assert(f.writeUpToNextSpec(a) == true);
15 
16 assert(a.data == "Number: \nString: ");
17 assert(f.trailing == "");
18 assert(f.spec == 's');
19 
20 assert(f.writeUpToNextSpec(a) == false);
21 assert(a.data == "Number: \nString: ");

Meta

Suggestion Box / Bug Report