aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/parser.hh
diff options
context:
space:
mode:
authorCarlo Nucera <carlo.nucera@protonmail.com>2020-07-02 11:29:33 -0400
committerCarlo Nucera <carlo.nucera@protonmail.com>2020-07-02 11:29:33 -0400
commitea48e3a5b5f1051c251184792417326c513bf00f (patch)
tree0fa4fda4a27175aa7fb8250ed88fc160ac6157fd /src/libutil/parser.hh
parent36cbc74689321399aeae26ff506809b8d9b24674 (diff)
Abstract common parsing functionality
Diffstat (limited to 'src/libutil/parser.hh')
-rw-r--r--src/libutil/parser.hh22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libutil/parser.hh b/src/libutil/parser.hh
index d3bfafe75..d20e4dfc6 100644
--- a/src/libutil/parser.hh
+++ b/src/libutil/parser.hh
@@ -21,4 +21,26 @@ static inline std::optional<std::string_view> splitPrefix(std::string_view & str
return std::nullopt;
}
+// Mutates the string to eliminate the prefixes when found
+std::pair<std::optional<HashType>, bool> getParsedTypeAndSRI(std::string_view & rest) {
+ bool isSRI = false;
+
+ // Parse the has type before the separater, if there was one.
+ std::optional<HashType> optParsedType;
+ {
+ auto hashRaw = splitPrefix(rest, ':');
+
+ if (!hashRaw) {
+ hashRaw = splitPrefix(rest, '-');
+ if (hashRaw)
+ isSRI = true;
+ }
+ if (hashRaw)
+ optParsedType = parseHashType(*hashRaw);
+ }
+
+ return std::make_pair(optParsedType, isSRI);
+}
+
+
}