1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-13 22:12:43 +01:00

Abstract common parsing functionality

This commit is contained in:
Carlo Nucera 2020-07-02 11:29:33 -04:00
parent 36cbc74689
commit ea48e3a5b5
2 changed files with 25 additions and 34 deletions

View file

@ -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);
}
}