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
Name | Description |
---|---|
this
|
Construct a new FormatSpec using the format string fmt , no
processing is done until needed.
|
Fields
Name | Type | Description |
---|---|---|
flDash
|
bool | The format specifier contained a '-' (printf
compatibility).
|
flDash
|
bool | The format specifier contained a '-' (printf
compatibility).
|
flHash
|
bool | The format specifier contained a '#' (printf
compatibility).
|
flHash
|
bool | The format specifier contained a '#' (printf
compatibility).
|
flPlus
|
bool | The format specifier contained a '+' (printf
compatibility).
|
flPlus
|
bool | The format specifier contained a '+' (printf
compatibility).
|
flSeparator
|
bool | The format specifier contained a ','
|
flSeparator
|
bool | The format specifier contained a ','
|
flSpace
|
bool | The format specifier contained a ' ' (printf
compatibility).
|
flSpace
|
bool | The format specifier contained a ' ' (printf
compatibility).
|
flZero
|
bool | The format specifier contained a '0' (printf
compatibility).
|
flZero
|
bool | The format specifier contained a '0' (printf
compatibility).
|
indexEnd
|
ubyte | Index of the last argument for positional parameter range, from
1 to ubyte . (0 means not used).
|
indexStart
|
ubyte | Index of the argument for positional parameters, from 1 to
ubyte . (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
|
int | Precision. 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 means 0 length
separator.
|
separatorChar
|
dchar | Character to insert between digits. |
separatorCharPos
|
int | Set to DYNAMIC when the separator character is supplied at runtime.
|
separators
|
int | Number of digits printed between separators. |
spec
|
char | The actual format specifier, 's' by default.
|
trailing
|
const(Char)[] | _trailing contains the rest of the format string.
|
width
|
int | Minimum width, default 0 .
|
Methods
Name | Description |
---|---|
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
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.