aboutsummaryrefslogtreecommitdiff
path: root/src/libmain/shared.hh
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-01-08 12:51:19 +0100
committerEelco Dolstra <edolstra@gmail.com>2021-01-08 12:51:19 +0100
commit17beae299d5e6bb511c453d0b9d0d7ef906b3d14 (patch)
tree318c9a3745c9778dc47b92af67229d8fb2287805 /src/libmain/shared.hh
parent6548b89cc4eb214cb4632fd4332c610f2d1f0a9d (diff)
Support binary unit prefixes in command line arguments
Diffstat (limited to 'src/libmain/shared.hh')
-rw-r--r--src/libmain/shared.hh17
1 files changed, 1 insertions, 16 deletions
diff --git a/src/libmain/shared.hh b/src/libmain/shared.hh
index 38f627b44..edc7b5efa 100644
--- a/src/libmain/shared.hh
+++ b/src/libmain/shared.hh
@@ -57,22 +57,7 @@ template<class N> N getIntArg(const string & opt,
{
++i;
if (i == end) throw UsageError("'%1%' requires an argument", opt);
- string s = *i;
- N multiplier = 1;
- if (allowUnit && !s.empty()) {
- char u = std::toupper(*s.rbegin());
- if (std::isalpha(u)) {
- if (u == 'K') multiplier = 1ULL << 10;
- else if (u == 'M') multiplier = 1ULL << 20;
- else if (u == 'G') multiplier = 1ULL << 30;
- else if (u == 'T') multiplier = 1ULL << 40;
- else throw UsageError("invalid unit specifier '%1%'", u);
- s.resize(s.size() - 1);
- }
- }
- if (auto n = string2Int<N>(s))
- return *n * multiplier;
- throw UsageError("'%1%' requires an integer argument", opt);
+ return string2IntWithUnitPrefix<N>(*i);
}