Function Tag.getTagValues
Lookup a child tag by name, and retrieve all values from it.
This just like using getTag()
.values
, except if the tag isn't found,
it safely returns null (or an optional array of default values) instead of
a dereferencing null error.
Note that, unlike getValue
, this doesn't discriminate by the value's
type. It simply returns all values of a single tag as a Value[]
.
If you'd prefer an exception thrown when the tag isn't found, use
expectTag
.values
instead.
Prototype
std .variant .VariantN!(32L,bool,string,dchar,int,long,float,double,real,std.datetime.Date,sdlang.token.DateTimeFrac,std.datetime.SysTime,sdlang.token.DateTimeFracUnknownZone,core.time.Duration,ubyte[],)[] getTagValues(
string fullTagName,
std .variant .VariantN!(32L,bool,string,dchar,int,long,float,double,real,std.datetime.Date,sdlang.token.DateTimeFrac,std.datetime.SysTime,sdlang.token.DateTimeFracUnknownZone,core.time.Duration,ubyte[],)[] defaultValues = null
);
Example
import std .exception;
import sdlang .parser;
auto root = parseSource(`
foo 1 "a" 2 "b"
foo 3 "c" 4 "d" // getTagValues considers this to override the first foo
`);
assert( root .getTagValues("foo") == [Value(3), Value("c"), Value(4), Value("d")] );
// Tag not found
// If you'd prefer an exception, use `expectTag.values` instead.
assert( root .getTagValues("doesnt-exist") is null );
assert( root .getTagValues("doesnt-exist", [ Value(999), Value("Not found") ]) ==
[ Value(999), Value("Not found") ] );