the string to parse
the character that starts the associative array
the character that ends the associative array
the character that associates the key with the value
the character that separates the elements of the associative array
the flag for deciding to report the number of consumed characters
import std.typecons : Flag, Yes, No, tuple; import std.range.primitives : save; import std.array : assocArray; auto s1 = "[1:10, 2:20, 3:30]"; auto copyS1 = s1.save; auto aa1 = parse!(int[int])(s1); assert(aa1 == [1:10, 2:20, 3:30]); assert(tuple([1:10, 2:20, 3:30], copyS1.length) == parse!(int[int], string, Yes.doCount)(copyS1)); auto s2 = `["aaa":10, "bbb":20, "ccc":30]`; auto copyS2 = s2.save; auto aa2 = parse!(int[string])(s2); assert(aa2 == ["aaa":10, "bbb":20, "ccc":30]); assert(tuple(["aaa":10, "bbb":20, "ccc":30], copyS2.length) == parse!(int[string], string, Yes.doCount)(copyS2)); auto s3 = `["aaa":[1], "bbb":[2,3], "ccc":[4,5,6]]`; auto copyS3 = s3.save; auto aa3 = parse!(int[][string])(s3); assert(aa3 == ["aaa":[1], "bbb":[2,3], "ccc":[4,5,6]]); assert(tuple(["aaa":[1], "bbb":[2,3], "ccc":[4,5,6]], copyS3.length) == parse!(int[][string], string, Yes.doCount)(copyS3)); auto s4 = `[]`; int[int] emptyAA; assert(tuple(emptyAA, s4.length) == parse!(int[int], string, Yes.doCount)(s4));
Parses an associative array from a string given the left bracket (default '['), right bracket (default ']'), key-value separator (default ':'), and element seprator (by default ',').