1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-06 21:41:48 +02:00

Merge pull request #10668 from edolstra/unit-prefixes

Support unit prefixes in configuration settings
This commit is contained in:
Eelco Dolstra 2024-05-09 19:29:36 +02:00 committed by GitHub
commit de8c3c034c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 20 additions and 7 deletions

View file

@ -116,10 +116,11 @@ T BaseSetting<T>::parse(const std::string & str) const
{
static_assert(std::is_integral<T>::value, "Integer required.");
if (auto n = string2Int<T>(str))
return *n;
else
try {
return string2IntWithUnitPrefix<T>(str);
} catch (...) {
throw UsageError("setting '%s' has invalid value '%s'", name, str);
}
}
template<typename T>

View file

@ -120,7 +120,7 @@ std::optional<N> string2Int(const std::string_view s)
template<class N>
N string2IntWithUnitPrefix(std::string_view s)
{
N multiplier = 1;
uint64_t multiplier = 1;
if (!s.empty()) {
char u = std::toupper(*s.rbegin());
if (std::isalpha(u)) {