View source code
Display the source code in std/format.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Struct std.format.FormatSpec

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

struct FormatSpec(Char)
  
if (is(Unqual!Char == Char));

Constructors

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

Fields

NameTypeDescription
flDash boolThe format specifier contained a '-' (printf compatibility).
flDash boolThe format specifier contained a '-' (printf compatibility).
flHash boolThe format specifier contained a '#' (printf compatibility).
flHash boolThe format specifier contained a '#' (printf compatibility).
flPlus boolThe format specifier contained a '+' (printf compatibility).
flPlus boolThe format specifier contained a '+' (printf compatibility).
flSeparator boolThe format specifier contained a ','
flSeparator boolThe format specifier contained a ','
flSpace boolThe format specifier contained a ' ' (printf compatibility).
flSpace boolThe format specifier contained a ' ' (printf compatibility).
flZero boolThe format specifier contained a '0' (printf compatibility).
flZero boolThe format specifier contained a '0' (printf compatibility).
indexEnd ubyteIndex of the last argument for positional parameter range, from 1 to ubyte.max. (0 means not used).
indexStart ubyteIndex of the argument for positional parameters, from 1 to ubyte.max. (0 means not used).
nested const(Char)[]In case of a compound format specifier starting with "%(" and ending with "%)", nested contains the string contained within the two separators.
precision intPrecision. Its semantics depends on the argument type. For floating point numbers, precision dictates the number of decimals printed.
sep const(Char)[]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 dcharCharacter to insert between digits.
separatorCharPos intSet to DYNAMIC when the separator character is supplied at runtime.
separators intNumber of digits printed between separators.
spec charThe actual format specifier, 's' by default.
trailing const(Char)[]trailing contains the rest of the format string.
width intMinimum width, default 0.

Methods

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

Example

import std.array;
auto a = appender!(string)();
auto fmt = "Number: %2.4e\nString: %s";
auto f = FormatSpec!char(fmt);

f.writeUpToNextSpec(a);

writeln(a.data); // "Number: "
writeln(f.trailing); // "\nString: %s"
writeln(f.spec); // 'e'
writeln(f.width); // 2
writeln(f.precision); // 4

f.writeUpToNextSpec(a);

writeln(a.data); // "Number: \nString: "
writeln(f.trailing); // ""
writeln(f.spec); // 's'

Authors

Walter Bright, Andrei Alexandrescu, and Kenji Hara

License

Boost License 1.0.