Inline newFunction

This commit is contained in:
Carlo Nucera 2020-07-02 10:58:29 -04:00
parent 343d1569b1
commit 27c8029573

View file

@ -149,11 +149,12 @@ Hash Hash::parseAnyPrefixed(std::string_view s)
return parseAny(s, std::nullopt); return parseAny(s, std::nullopt);
} }
static std::pair<HashType, bool> newFunction(std::string_view & rest, std::optional<HashType> optType) Hash Hash::parseAny(std::string_view original, std::optional<HashType> optType)
{ {
auto original = rest; auto rest = original;
bool isSRI = false; bool isSRI = false;
HashType hashType;
// Parse the has type before the separater, if there was one. // Parse the has type before the separater, if there was one.
std::optional<HashType> optParsedType; std::optional<HashType> optParsedType;
@ -171,23 +172,13 @@ static std::pair<HashType, bool> newFunction(std::string_view & rest, std::optio
// Either the string or user must provide the type, if they both do they // Either the string or user must provide the type, if they both do they
// must agree. // must agree.
if (!optParsedType && !optType) { if (!optParsedType && !optType)
throw BadHash("hash '%s' does not include a type, nor is the type otherwise known from context.", rest); throw BadHash("hash '%s' does not include a type, nor is the type otherwise known from context.", rest);
} else { else if (optParsedType && optType && *optParsedType != *optType)
if (optParsedType && optType && *optParsedType != *optType) throw BadHash("hash '%s' should have type '%s'", original, printHashType(*optType));
throw BadHash("hash '%s' should have type '%s'", original, printHashType(*optType));
return {
optParsedType ? *optParsedType : *optType,
isSRI,
};
}
}
// mutates the string_view hashType = optParsedType ? *optParsedType : *optType;
Hash Hash::parseAny(std::string_view original, std::optional<HashType> optType) return Hash(rest, std::make_pair(hashType, isSRI));
{
auto typeAndSRI = newFunction(original, optType);
return Hash(original, typeAndSRI);
} }
Hash::Hash(std::string_view rest, std::pair<HashType, bool> typeAndSRI) Hash::Hash(std::string_view rest, std::pair<HashType, bool> typeAndSRI)