parse

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

s Source

The string to parse

lbracket dchar

the character that starts the array

rbracket dchar

the character that ends the array

comma dchar

the character that separates the elements of the array

doCount

the flag for deciding to report the number of consumed characters

Return Value

Type: auto
  • 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

Examples

import std.typecons : Flag, Yes, No;
auto s1 = `[['h', 'e', 'l', 'l', 'o'], "world"]`;
auto a1 = parse!(string[])(s1);
assert(a1 == ["hello", "world"]);

auto s2 = `["aaa", "bbb", "ccc"]`;
auto a2 = parse!(string[])(s2);
assert(a2 == ["aaa", "bbb", "ccc"]);

auto s3 = `[['h', 'e', 'l', 'l', 'o'], "world"]`;
auto len3 = s3.length;
auto a3 = parse!(string[], string, Yes.doCount)(s3);
assert(a3.data == ["hello", "world"]);
assert(a3.count == len3);

Meta