View source code
Display the source code in std/format/spec.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.spec.FormatSpec
A general handler for format strings.
struct FormatSpec(Char)
if (is(Unqual!Char == Char));
This handler centers around the function writeUpToNextSpec
,
which parses the format string until the
next format specifier is found. After the call, it provides
information about this format specifier in its numerous variables.
Constructors
Name | Description |
---|---|
this
(fmt)
|
Creates a new FormatSpec .
|
Fields
Name | Type | Description |
---|---|---|
dynamicSeparatorChar
|
bool | The separator charactar is supplied at runtime. |
flDash
|
bool | The format specifier contained a '-' .
|
flEqual
|
bool | The format specifier contained a '=' .
|
flHash
|
bool | The format specifier contained a '#' .
|
flPlus
|
bool | The format specifier contained a '+' .
|
flSeparator
|
bool | The format specifier contained a ',' .
|
flSpace
|
bool | The format specifier contained a space. |
flZero
|
bool | The format specifier contained a '0' .
|
indexEnd
|
ubyte | Index of the last argument for positional parameter ranges. |
indexStart
|
ubyte | Index of the argument for positional parameters. |
nested
|
const(Char)[] | The inner format string of a nested format specifier. |
precision
|
int | Precision. Its semantic depends on the format character. |
sep
|
const(Char)[] | The separator of a nested format specifier. |
separatorChar
|
dchar | Character to use as separator. |
separators
|
int | Number of elements between separators. |
spec
|
char | The format character. |
trailing
|
const(Char)[] | Contains the part of the format string, that has not yet been parsed. |
width
|
int | Minimum width. |
Methods
Name | Description |
---|---|
separatorCharPos
()
|
Set to DYNAMIC when the separator character is supplied at runtime.
|
toString
()
|
Provides a string representation. |
toString
(writer)
|
Writes a string representation to an output range. |
writeUpToNextSpec
(writer)
|
Writes the format string to an output range until the next format specifier is found and parse that format specifier. |
Parameters
Name | Description |
---|---|
Char | the character type of the format string |
Example
import std .array : appender;
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.