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

NameDescription
this (fmt) Creates a new FormatSpec.

Fields

NameTypeDescription
dynamicSeparatorChar boolThe separator charactar is supplied at runtime.
flDash boolThe format specifier contained a '-'.
flEqual boolThe format specifier contained a '='.
flHash boolThe format specifier contained a '#'.
flPlus boolThe format specifier contained a '+'.
flSeparator boolThe format specifier contained a ','.
flSpace boolThe format specifier contained a space.
flZero boolThe format specifier contained a '0'.
indexEnd ubyteIndex of the last argument for positional parameter ranges.
indexStart ubyteIndex of the argument for positional parameters.
nested const(Char)[]The inner format string of a nested format specifier.
precision intPrecision. Its semantic depends on the format character.
sep const(Char)[]The separator of a nested format specifier.
separatorChar dcharCharacter to use as separator.
separators intNumber of elements between separators.
spec charThe format character.
trailing const(Char)[]Contains the part of the format string, that has not yet been parsed.
width intMinimum width.

Methods

NameDescription
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

NameDescription
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

Boost License 1.0.