diff options
author | Carlo Nucera <carlo.nucera@protonmail.com> | 2020-07-02 10:58:29 -0400 |
---|---|---|
committer | Carlo Nucera <carlo.nucera@protonmail.com> | 2020-07-02 11:01:10 -0400 |
commit | 27c8029573ab49ad11c069ef547e3c087c73939f (patch) | |
tree | 5b4a9a4d8bd419e30df626fbfc5266e24d3ded14 /src/libutil/hash.cc | |
parent | 343d1569b193e4456e2e5365921371bfd6e37205 (diff) |
Inline newFunction
Diffstat (limited to 'src/libutil/hash.cc')
-rw-r--r-- | src/libutil/hash.cc | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc index 084d24170..2908a3445 100644 --- a/src/libutil/hash.cc +++ b/src/libutil/hash.cc @@ -149,11 +149,12 @@ Hash Hash::parseAnyPrefixed(std::string_view s) 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; + HashType hashType; // Parse the has type before the separater, if there was one. 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 // 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); - } else { - if (optParsedType && optType && *optParsedType != *optType) - throw BadHash("hash '%s' should have type '%s'", original, printHashType(*optType)); - return { - optParsedType ? *optParsedType : *optType, - isSRI, - }; - } -} + else if (optParsedType && optType && *optParsedType != *optType) + throw BadHash("hash '%s' should have type '%s'", original, printHashType(*optType)); -// mutates the string_view -Hash Hash::parseAny(std::string_view original, std::optional<HashType> optType) -{ - auto typeAndSRI = newFunction(original, optType); - return Hash(original, typeAndSRI); + hashType = optParsedType ? *optParsedType : *optType; + return Hash(rest, std::make_pair(hashType, isSRI)); } Hash::Hash(std::string_view rest, std::pair<HashType, bool> typeAndSRI) |