aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlo Nucera <carlo.nucera@protonmail.com>2020-06-30 12:49:00 -0400
committerCarlo Nucera <carlo.nucera@protonmail.com>2020-06-30 12:49:00 -0400
commita1f66d1d9e70d4204a3686002b02277465a6b7ab (patch)
tree750a44b3d815dd2e7619b6b3a0d8f9508f20574d
parent77b51f4598763f0b3a435ed0e4ce98178d9e99da (diff)
Factor the prefix splitting in hash
-rw-r--r--src/libutil/hash.cc17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc
index e060700d9..26ab5a110 100644
--- a/src/libutil/hash.cc
+++ b/src/libutil/hash.cc
@@ -7,6 +7,7 @@
#include "args.hh"
#include "hash.hh"
#include "archive.hh"
+#include "parser.hh"
#include "util.hh"
#include "istringstream_nocopy.hh"
@@ -144,17 +145,15 @@ Hash::Hash(std::string_view original, std::optional<HashType> optType)
// Parse the has type before the separater, if there was one.
std::optional<HashType> optParsedType;
{
- auto sep = rest.find(':');
- if (sep == std::string_view::npos) {
- sep = rest.find('-');
- if (sep != std::string_view::npos)
+ auto hashRaw = splitPrefix(rest, ':');
+
+ if (!hashRaw) {
+ hashRaw = splitPrefix(rest, '-');
+ if (hashRaw)
isSRI = true;
}
- if (sep != std::string_view::npos) {
- auto hashRaw = rest.substr(0, sep);
- optParsedType = parseHashType(hashRaw);
- rest = rest.substr(sep + 1);
- }
+ if (hashRaw)
+ optParsedType = parseHashType(*hashRaw);
}
// Either the string or user must provide the type, if they both do they