replace if/else chain with final switch in Resolver.resolve() (#232)
This commit is contained in:
parent
b63ea1aaae
commit
dc5ee1a6ac
|
@ -130,29 +130,42 @@ final class Resolver
|
||||||
string resolve(const NodeID kind, const string tag, const string value,
|
string resolve(const NodeID kind, const string tag, const string value,
|
||||||
const bool implicit) @safe
|
const bool implicit) @safe
|
||||||
{
|
{
|
||||||
if((tag !is null) && tag != "!"){return tag;}
|
import std.array : empty, front;
|
||||||
|
if((tag !is null) && (tag != "!"))
|
||||||
if(kind == NodeID.scalar)
|
|
||||||
{
|
{
|
||||||
if(!implicit){return defaultScalarTag_;}
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
final switch (kind)
|
||||||
|
{
|
||||||
|
case NodeID.scalar:
|
||||||
|
if(!implicit)
|
||||||
|
{
|
||||||
|
return defaultScalarTag_;
|
||||||
|
}
|
||||||
|
|
||||||
//Get the first char of the value.
|
//Get the first char of the value.
|
||||||
size_t dummy;
|
const dchar first = value.empty ? '\0' : value.front;
|
||||||
const dchar first = value.length == 0 ? '\0' : decode(value, dummy);
|
|
||||||
|
|
||||||
auto resolvers = (first in yamlImplicitResolvers_) is null ?
|
auto resolvers = (first in yamlImplicitResolvers_) is null ?
|
||||||
[] : yamlImplicitResolvers_[first];
|
[] : yamlImplicitResolvers_[first];
|
||||||
|
|
||||||
//If regexp matches, return tag.
|
//If regexp matches, return tag.
|
||||||
foreach(resolver; resolvers) if(!(match(value, resolver[1]).empty))
|
foreach(resolver; resolvers)
|
||||||
|
{
|
||||||
|
if(!(match(value, resolver[1]).empty))
|
||||||
{
|
{
|
||||||
return resolver[0];
|
return resolver[0];
|
||||||
}
|
}
|
||||||
return defaultScalarTag_;
|
|
||||||
}
|
}
|
||||||
else if(kind == NodeID.sequence){return defaultSequenceTag_;}
|
return defaultScalarTag_;
|
||||||
else if(kind == NodeID.mapping) {return defaultMappingTag_;}
|
case NodeID.sequence:
|
||||||
assert(false, "This line of code should never be reached");
|
return defaultSequenceTag_;
|
||||||
|
case NodeID.mapping:
|
||||||
|
return defaultMappingTag_;
|
||||||
|
case NodeID.invalid:
|
||||||
|
assert(false, "Cannot resolve an invalid node");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@safe unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue