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:
commit
de8c3c034c
5 changed files with 20 additions and 7 deletions
|
@ -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>
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue