1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-29 23:13:14 +02:00

Rename two hash constructors to proper functions

This commit is contained in:
Carlo Nucera 2020-07-01 18:34:18 -04:00
parent c8c4bcf90e
commit 263ccdd489
20 changed files with 45 additions and 37 deletions

View file

@ -144,7 +144,10 @@ Hash Hash::fromSRI(std::string_view original) {
return Hash(rest, std::make_pair(parsedType, true));
}
Hash::Hash(std::string_view s) : Hash(s, std::nullopt) {}
Hash Hash::parseAnyPrefixed(std::string_view s)
{
return parseAny(s, std::nullopt);
}
static std::pair<HashType, bool> newFunction(std::string_view & original, std::optional<HashType> optType)
{
@ -181,8 +184,11 @@ static std::pair<HashType, bool> newFunction(std::string_view & original, std::o
}
// mutates the string_view
Hash::Hash(std::string_view original, std::optional<HashType> optType)
: Hash(original, newFunction(original, optType)) {}
Hash Hash::parseAny(std::string_view original, std::optional<HashType> optType)
{
auto typeAndSRI = newFunction(original, optType);
return Hash(original, typeAndSRI);
}
Hash::Hash(std::string_view rest, std::pair<HashType, bool> typeAndSRI)
: Hash(typeAndSRI.first)
@ -249,7 +255,7 @@ Hash newHashAllowEmpty(std::string hashStr, std::optional<HashType> ht)
warn("found empty hash, assuming '%s'", h.to_string(SRI, true));
return h;
} else
return Hash(hashStr, ht);
return Hash::parseAny(hashStr, ht);
}