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
(fmt)
|
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).
|
flHash
|
bool | The format specifier contained a '#' (printf
compatibility).
|
flPlus
|
bool | The format specifier contained a '+' (printf
compatibility).
|
flSeparator
|
bool | The format specifier contained a ','
|
flSpace
|
bool | The format specifier contained a ' ' (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
(writer)
|
Gives a string containing all of the member variables on their own line. |
writeUpToNextSpec
(writer)
|
Write the format string to an output range until the next format specifier is found and parse that format specifier. |
Example
import std .array;
auto a = appender!(string)();
auto fmt = "Number: %6.4e\nString: %s";
auto f = FormatSpec!char(fmt);
writeln(f .writeUpToNextSpec(a)); // true
writeln(a .data); // "Number: "
writeln(f .trailing); // "\nString: %s"
writeln(f .spec); // 'e'
writeln(f .width); // 6
writeln(f .precision); // 4
writeln(f .writeUpToNextSpec(a)); // true
writeln(a .data); // "Number: \nString: "
writeln(f .trailing); // ""
writeln(f .spec); // 's'
writeln(f .writeUpToNextSpec(a)); // false
writeln(a .data); // "Number: \nString: "
Authors
Walter Bright, Andrei Alexandrescu, and Kenji Hara
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.