std.format.read

This is a submodule of std.format.

It provides two functions for reading formatted input: unformatValue and formattedRead. The former reads a single value. The latter reads several values at once and matches the characters found between format specifiers.

Parameters are ignored, except for the ones consisting of a single '*'. See formattedRead for more information.

A space outside of a format specifier has a special meaning: it matches any sequence of whitespace characters, not just a single space.

The following combinations of format characters and types are available:

s c d, u, b, o, x, X e, E, f, g, G r compound
bool yes yes
null yes
integer yes yes yes
floating point yes yes yes
character yes yes yes
string yes yes
array yes yes
associative array yes yes

Below are highlighted examples on how these combinations are used with unformatValue, however, they apply for formattedRead also

Functions 3

fnuint formattedRead(Range, Char, Args...)(auto ref Range r, const(Char)[] fmt, auto ref Args args)Reads an input range according to a format string and stores the read values into its arguments.
fnuint formattedRead(alias fmt, Range, Args...)(auto ref Range r, auto ref Args args) if (!isType!fmt && isSomeString!(typeof(fmt)))ditto
fnT unformatValue(T, Range, Char)(ref Range input, scope const ref FormatSpec!Char spec)Reads a value from the given input range and converts it according to a format specifier.

Templates 2

tmplformattedRead(Args...) if (Args.length && allSatisfy!(isType, Args))

Reads an input range according to a format string and returns a tuple of Args with the read values.

Format specifiers with format character 'd', 'u' and 'c' can take a '*' parameter for skipping values.

The second version of formattedRead takes the format string as template argument. In this case, it is checked for consistency at compile-time.

Parameters

Argsa variadic list of types of the arguments
Functions
Tuple!Args formattedRead(Range, Char)(auto ref Range r, const(Char)[] fmt)

Parameters

ran input range, where the formatted input is read from
fmta format string
Rangethe type of the input range r
Charthe character type used for fmt

Returns

A Tuple!Args with the elements filled.

Throws

A FormatException

if reading did not succeed.

tmplformattedRead(alias fmt, Args...) if (!isType!fmt && isSomeString!(typeof(fmt)) && Args.length && allSatisfy!(isType, Args))

ditto

Functions
Tuple!Args formattedRead(Range)(auto ref Range r)