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;
|
||||||
|
}
|
||||||
//Get the first char of the value.
|
|
||||||
size_t dummy;
|
final switch (kind)
|
||||||
const dchar first = value.length == 0 ? '\0' : decode(value, dummy);
|
{
|
||||||
|
case NodeID.scalar:
|
||||||
auto resolvers = (first in yamlImplicitResolvers_) is null ?
|
if(!implicit)
|
||||||
[] : yamlImplicitResolvers_[first];
|
{
|
||||||
|
return defaultScalarTag_;
|
||||||
//If regexp matches, return tag.
|
}
|
||||||
foreach(resolver; resolvers) if(!(match(value, resolver[1]).empty))
|
|
||||||
{
|
//Get the first char of the value.
|
||||||
return resolver[0];
|
const dchar first = value.empty ? '\0' : value.front;
|
||||||
}
|
|
||||||
return defaultScalarTag_;
|
auto resolvers = (first in yamlImplicitResolvers_) is null ?
|
||||||
|
[] : yamlImplicitResolvers_[first];
|
||||||
|
|
||||||
|
//If regexp matches, return tag.
|
||||||
|
foreach(resolver; resolvers)
|
||||||
|
{
|
||||||
|
if(!(match(value, resolver[1]).empty))
|
||||||
|
{
|
||||||
|
return resolver[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultScalarTag_;
|
||||||
|
case NodeID.sequence:
|
||||||
|
return defaultSequenceTag_;
|
||||||
|
case NodeID.mapping:
|
||||||
|
return defaultMappingTag_;
|
||||||
|
case NodeID.invalid:
|
||||||
|
assert(false, "Cannot resolve an invalid node");
|
||||||
}
|
}
|
||||||
else if(kind == NodeID.sequence){return defaultSequenceTag_;}
|
|
||||||
else if(kind == NodeID.mapping) {return defaultMappingTag_;}
|
|
||||||
assert(false, "This line of code should never be reached");
|
|
||||||
}
|
}
|
||||||
@safe unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue