View source code Display the source code in std/conv.d from which this page was generated on github. 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. Page wiki View or edit the community-maintained wiki page associated with this page.

std.conv.parse - multiple declarations

Function parse

The parse family of functions works quite like the to family, except that (1) it only works with character ranges as input, (2) takes the input by reference and advances it to the position following the conversion, and (3) does not throw if it could not convert the entire input. It still throws if an overflow occurred during conversion or if no character of the input was meaningfully converted.

Prototypes

Target parse(Target, Source)(
  Source s
)
if (isInputRange!Source && isSomeChar!(ElementType!Source) && is(Unqual!Target == bool));

Target parse(Target, Source)(
  Source s,
  uint radix
)
if (isSomeChar!(ElementType!Source) && isIntegral!Target && !is(Target == enum));

Example

import std.string : munch;
string test = "123 \t  76.14";
auto a = parse!uint(test);
assert(a == 123);
assert(test == " \t  76.14"); // parse bumps string
munch(test, " \t\n\r"); // skip ws
assert(test == "76.14");
auto b = parse!double(test);
assert(b == 76.14);
assert(test == "");

Function parse

Parsing one character off a string returns the character and bumps the string up one position.

Prototype

Target parse(Target, Source)(
  Source s
)
if (isExactSomeString!Source && staticIndexOf!(Unqual!Target, dchar, Unqual!(ElementEncodingType!Source)) >= 0);

Function parse

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

Prototypes

Target parse(Target, Source)(
  Source s,
  dchar lbracket = '[',
  dchar rbracket = ']',
  dchar comma = ','
)
if (isExactSomeString!Source && isDynamicArray!Target && !is(Target == enum));

Target parse(Target, Source)(
  Source s,
  dchar lbracket = '[',
  dchar rbracket = ']',
  dchar comma = ','
)
if (isExactSomeString!Source && isStaticArray!Target && !is(Target == enum));

Function parse

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

Prototype

Target parse(Target, Source)(
  Source s,
  dchar lbracket = '[',
  dchar rbracket = ']',
  dchar keyval = ':',
  dchar comma = ','
)
if (isExactSomeString!Source && isAssociativeArray!Target && !is(Target == enum));

Authors

Walter Bright, Andrei Alexandrescu, Shin Fujishiro, Adam D. Ruppe, Kenji Hara

License

Boost License 1.0.

Comments