The OpenD Programming Language

FormatSpec

A general handler for format strings.

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

this
this(Char[] fmt)

Creates a new FormatSpec.

Members

Functions

separatorCharPos
deprecated int separatorCharPos()
deprecated void separatorCharPos(int value)

Set to DYNAMIC when the separator character is supplied at runtime.

toString
string toString()

Provides a string representation.

toString
void toString(OutputRange writer)

Writes a string representation to an output range.

writeUpToNextSpec
bool writeUpToNextSpec(OutputRange writer)

Writes the format string to an output range until the next format specifier is found and parse that format specifier.

Variables

DYNAMIC
enum int DYNAMIC;

Special value for width, precision and separators.

UNSPECIFIED
enum int UNSPECIFIED;

Special value for precision and separators.

dynamicSeparatorChar
bool dynamicSeparatorChar;

The separator charactar is supplied at runtime.

flDash
bool flDash;

The format specifier contained a '-'.

flEqual
bool flEqual;

The format specifier contained a '='.

flHash
bool flHash;

The format specifier contained a '#'.

flPlus
bool flPlus;

The format specifier contained a '+'.

flSeparator
bool flSeparator;

The format specifier contained a ','.

flSpace
bool flSpace;

The format specifier contained a space.

flZero
bool flZero;

The format specifier contained a '0'.

indexEnd
ubyte indexEnd;

Index of the last argument for positional parameter ranges.

indexStart
ubyte indexStart;

Index of the argument for positional parameters.

keySeparator
enum immutable(Char)[] keySeparator;

Sequence ":" inserted between element key and element value of an associative array.

nested
const(Char)[] nested;

The inner format string of a nested format specifier.

precision
int precision;

Precision. Its semantic depends on the format character.

sep
const(Char)[] sep;

The separator of a nested format specifier.

separatorChar
dchar separatorChar;

Character to use as separator.

separators
int separators;

Number of elements between separators.

seqAfter
enum immutable(Char)[] seqAfter;

Sequence "]" inserted after each range or range like structure.

seqBefore
enum immutable(Char)[] seqBefore;

Sequence "[" inserted before each range or range like structure.

seqSeparator
enum immutable(Char)[] seqSeparator;

Sequence ", " inserted between elements of a range, a range like structure or the elements of an associative array.

spec
char spec;

The format character.

trailing
const(Char)[] trailing;

Contains the part of the format string, that has not yet been parsed.

width
int width;

Minimum width.

Parameters

Char

the 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) == true);

assert(a.data == "Number: ");
assert(f.trailing == "\nString: %s");
assert(f.spec == 'e');
assert(f.width == 6);
assert(f.precision == 4);

assert(f.writeUpToNextSpec(a) == true);

assert(a.data == "Number: \nString: ");
assert(f.trailing == "");
assert(f.spec == 's');

assert(f.writeUpToNextSpec(a) == false);

assert(a.data == "Number: \nString: ");

Meta