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,
|
||||
const bool implicit) @safe
|
||||
{
|
||||
if((tag !is null) && tag != "!"){return tag;}
|
||||
|
||||
if(kind == NodeID.scalar)
|
||||
import std.array : empty, front;
|
||||
if((tag !is null) && (tag != "!"))
|
||||
{
|
||||
if(!implicit){return defaultScalarTag_;}
|
||||
|
||||
//Get the first char of the value.
|
||||
size_t dummy;
|
||||
const dchar first = value.length == 0 ? '\0' : decode(value, dummy);
|
||||
|
||||
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_;
|
||||
return tag;
|
||||
}
|
||||
|
||||
final switch (kind)
|
||||
{
|
||||
case NodeID.scalar:
|
||||
if(!implicit)
|
||||
{
|
||||
return defaultScalarTag_;
|
||||
}
|
||||
|
||||
//Get the first char of the value.
|
||||
const dchar first = value.empty ? '\0' : value.front;
|
||||
|
||||
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
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue