Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

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 usinga local clone.

std.format.spec

This is a submodule ofstd.format.
It centers around a struct calledFormatSpec, which takes aformat string and provides tools forparsing this string. Additionally this module contains a functionsingleSpec which helps treating a single format specifier.
License:
Boost License 1.0.
Authors:
Walter Bright,Andrei Alexandrescu, and Kenji Hara

Sourcestd/format/spec.d

structFormatSpec(Char) if (is(Unqual!Char == Char));
A general handler for format strings.
This handler centers around the functionwriteUpToNextSpec,which parses theformat string until thenext format specifier is found. After the call, it providesinformation about this format specifier in its numerous variables.
Parameters:
Charthe character type of the format string
Examples:
import std.array : appender;auto a = appender!(string)();auto fmt ="Number: %6.4e\nString: %s";auto f =FormatSpec!char(fmt);assert(f.writeUpToNextSpec(a));writeln(a.data);// "Number: "writeln(f.trailing);// "\nString: %s"writeln(f.spec);// 'e'writeln(f.width);// 6writeln(f.precision);// 4assert(f.writeUpToNextSpec(a));writeln(a.data);// "Number: \nString: "writeln(f.trailing);// ""writeln(f.spec);// 's'assert(!f.writeUpToNextSpec(a));writeln(a.data);// "Number: \nString: "
intwidth;
Minimum width.
Default:0.
intprecision;
Precision. Its semantic depends on the format character.
Seeformat string for more details. Default:UNSPECIFIED.
intseparators;
Number of elements between separators.
Default:UNSPECIFIED.
booldynamicSeparatorChar;
The separator charactar is supplied at runtime.
Default: false.
intseparatorCharPos();

voidseparatorCharPos(intvalue);
Set toDYNAMIC when the separator character is supplied at runtime.
Default:UNSPECIFIED.
Warning:separatorCharPos is deprecated. It will be removed in 2.107.0. Please usedynamicSeparatorChar instead.
dcharseparatorChar;
Character to use as separator.
Default:','.
enum intDYNAMIC;
Special value forwidth,precision andseparators.
It flags that these values will be passed at runtime through variadic arguments.
enum intUNSPECIFIED;
Special value forprecision andseparators.
It flags that these values have not been specified.
charspec;
The format character.
Default:'s'.
ushortindexStart;
Index of the argument for positional parameters.
Counting starts with1. Set to0 if not used. Default:0.
ushortindexEnd;
Index of the last argument for positional parameter ranges.
Counting starts with1. Set to0 if not used. Default:0.
The maximum value of this field is used as a sentinel to indicate the arguments' length.
boolflDash;
The format specifier contained a'-'.
boolflZero;
The format specifier contained a'0'.
boolflSpace;
The format specifier contained a space.
boolflPlus;
The format specifier contained a'+'.
boolflHash;
The format specifier contained a'#'.
boolflEqual;
The format specifier contained a'='.
boolflSeparator;
The format specifier contained a','.
const(Char)[]nested;
The inner format string of a nested format specifier.
const(Char)[]sep;
The separator of a nested format specifier.
null means, there is no separator.empty, but notnull, means zero length separator.
const(Char)[]trailing;
Contains the part of the format string, that has not yet been parsed.
enum immutable(Char)[]seqBefore;
Sequence"[" inserted before each range or range like structure.
enum immutable(Char)[]seqAfter;
Sequence"]" inserted after each range or range like structure.
enum immutable(Char)[]keySeparator;
Sequence":" inserted between element key and element value of an associative array.
enum immutable(Char)[]seqSeparator;
Sequence", " inserted between elements of a range, a range like structure or the elements of an associative array.
pure @safe this(in Char[]fmt);
Creates a newFormatSpec.
The string is lazily evaluated. That means, nothing is done, untilwriteUpToNextSpec is called.
Parameters:
Char[]fmtaformat string
boolwriteUpToNextSpec(OutputRange)(ref OutputRangewriter) scope;
Writes the format string to an output range until the next format specifier is found and parse that format specifier.
See thedescription of format strings for more details about the format specifier.
Parameters:
OutputRangewriteranoutput range, where the format string is written to
OutputRangetype of the output range
Returns:
True, if a format specifier is found and false, if the end of the format string has been reached.
Throws:
AFormatException when parsing the format specifier did not succeed.
pure @safe stringtoString() const;
Provides a string representation.
Returns:
The string representation.
voidtoString(OutputRange)(ref OutputRangewriter) const
if (isOutputRange!(OutputRange, char));
Writes a string representation to an output range.
Parameters:
OutputRangewriteranoutput range, where the representation is written to
OutputRangetype of the output range
FormatSpec!CharsingleSpec(Char)(Char[]fmt);
Helper function that returns aFormatSpec for a single format specifier.
Parameters:
Char[]fmtaformat string containing a single format specifier
Charcharacter type offmt
Returns:
AFormatSpec with the format specifier parsed.
Throws:
AFormatException when the format string contains no format specifier or more than a single format specifier or when the format specifier is malformed.
Examples:
import std.array : appender;import std.format.write : formatValue;auto spec =singleSpec("%10.3e");auto writer = appender!string();writer.formatValue(42.0, spec);writeln(writer.data);// " 4.200e+01"
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Fri Feb 20 06:43:27 2026

[8]ページ先頭

©2009-2026 Movatter.jp