parse

fnauto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source source) if (is(immutable Target == immutable bool) && isInputRange!Source && isSomeChar!(ElementType!Source))
The parse family of functions works quite like the to

family, except that:

  1. It only works with character ranges as input.
  2. It takes the input by reference. This means that rvalues (such

    as string literals) are not accepted: use to instead.

  3. It advances the input to the position following the conversion.
  4. It does not throw if it could not convert the entire input.

This overload parses a bool from a character input range.

Parameters

Targetthe boolean type to convert to
sourcethe lvalue of an input range
doCountthe flag for deciding to report the number of consumed characters

Returns

  • A bool if doCount is set to No.doCount
  • A tuple containing a bool and a size_t if doCount is set to Yes.doCount

Throws

A ConvException if the range does not represent a bool.

Note

All character input range conversions using to are forwarded

to parse and do not require lvalues.

fnauto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref scope Source s) if (isIntegral!Target && !is(Target == enum) && isSomeChar!(ElementType!Source))

Parses an integer from a character input range.

Parameters

Targetthe integral type to convert to
sthe lvalue of an input range
doCountthe flag for deciding to report the number of consumed characters

Returns

  • A number of type Target if doCount is set to No.doCount
  • A tuple containing a number of type Target and a size_t if doCount is set to Yes.doCount

Throws

A ConvException If an overflow occurred during conversion or

if no character of the input was meaningfully converted.

fnauto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source source, uint radix) if (isIntegral!Target && !is(Target == enum) && isSomeChar!(ElementType!Source))

ditto

fnauto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s) if (is(Target == enum) && isSomeString!Source && !is(Source == enum))

Parses an enum type from a string representing an enum member name.

Parameters

Targetthe enum type to convert to
sthe lvalue of the range to _parse
doCountthe flag for deciding to report the number of consumed characters

Returns

  • An enum of type Target if doCount is set to No.doCount
  • A tuple containing an enum of type Target and a size_t if doCount is set to Yes.doCount

Throws

A ConvException if type Target does not have a member

represented by s.

fnauto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source source) if (isFloatingPoint!Target && !is(Target == enum) && isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum))

Parses a floating point number from a character range.

Parameters

Targeta floating point type
sourcethe lvalue of the range to _parse
doCountthe flag for deciding to report the number of consumed characters

Returns

  • A floating point number of type Target if doCount is set to No.doCount
  • A tuple containing a floating point number of·type Target and a size_t

    if doCount is set to Yes.doCount

Throws

A ConvException if source is empty, if no number could be

parsed, or if an overflow occurred.

fnauto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s) if (staticIndexOf!(immutable Target, immutable dchar, immutable ElementEncodingType!Source) >= 0 && isSomeString!Source && !is(Source == enum))

Parses one character from a character range.

Parameters

Targetthe type to convert to
sthe lvalue of an input range
doCountthe flag for deciding to report the number of consumed characters

Returns

  • A character of type Target if doCount is set to No.doCount
  • A tuple containing a character of type Target and a size_t if doCount is set to Yes.doCount

Throws

A ConvException if the range is empty.
fnauto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s) if (isSomeChar!Target && Target.sizeof >= ElementType!Source.sizeof && !is(Target == enum) && !isSomeString!Source && isInputRange!Source && isSomeChar!(ElementType!Source))

ditto

fnauto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s) if (is(immutable Target == immutable typeof(null)) && isInputRange!Source && isSomeChar!(ElementType!Source))

Parses typeof(null) from a character range if the range spells "null". This function is case insensitive.

Parameters

Targetthe type to convert to
sthe lvalue of an input range
doCountthe flag for deciding to report the number of consumed characters

Returns

  • null if doCount is set to No.doCount
  • A tuple containing null and a size_t if doCount is set to Yes.doCount

Throws

A ConvException if the range doesn't represent null.
fnauto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s, dchar lbracket = '[', dchar rbracket = ']', dchar comma = ',') if (isDynamicArray!Target && !is(Target == enum) && isSomeString!Source && !is(Source == enum))

Parses an array from a string given the left bracket (default '['), right bracket (default `']'`), and element separator (by default `','`). A trailing separator is allowed.

Parameters

sThe string to parse
lbracketthe character that starts the array
rbracketthe character that ends the array
commathe character that separates the elements of the array
doCountthe flag for deciding to report the number of consumed characters

Returns

  • An array of type Target if doCount is set to No.doCount
  • A tuple containing an array of type Target and a size_t if doCount is set to Yes.doCount
fnauto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s, dchar lbracket = '[', dchar rbracket = ']', dchar comma = ',') if (isStaticArray!Target && !is(Target == enum) && isExactSomeString!Source)

ditto

fnauto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s, dchar lbracket = '[', dchar rbracket = ']', dchar keyval = ':', dchar comma = ',') if (isAssociativeArray!Target && !is(Target == enum) && isSomeString!Source && !is(Source == enum))

Parses an associative array from a string given the left bracket (default '['), right bracket (default `']'`), key-value separator (default ':'), and element seprator (by default `','`).

Parameters

sthe string to parse
lbracketthe character that starts the associative array
rbracketthe character that ends the associative array
keyvalthe character that associates the key with the value
commathe character that separates the elements of the associative array
doCountthe flag for deciding to report the number of consumed characters

Returns

  • An associative array of type Target if doCount is set to No.doCount
  • A tuple containing an associative array of type Target and a size_t

    if doCount is set to Yes.doCount