mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-19 07:28:43 +00:00
Fixed: Support new ISO units (KiB, MiB, etc...) in humanReadableToBytes
This commit is contained in:
parent
945901ad28
commit
1e2bd4bd11
1 changed files with 24 additions and 5 deletions
|
@ -394,7 +394,8 @@ uint32 humanReadableToBytes (const string &str)
|
|||
if(str[0]<'0' || str[0]>'9')
|
||||
return 0;
|
||||
|
||||
res = atoi (str.c_str());
|
||||
if (!fromString(str, res))
|
||||
return 0;
|
||||
|
||||
if(str[str.size()-1] == 'B')
|
||||
{
|
||||
|
@ -404,10 +405,28 @@ uint32 humanReadableToBytes (const string &str)
|
|||
// there's no break and it's **normal**
|
||||
switch (str[str.size()-2])
|
||||
{
|
||||
case 'G': res *= 1024;
|
||||
case 'M': res *= 1024;
|
||||
case 'K': res *= 1024;
|
||||
default: ;
|
||||
// kB/KB, MB, GB and TB are 1000 multiples
|
||||
case 'T': res *= 1000;
|
||||
case 'G': res *= 1000;
|
||||
case 'M': res *= 1000;
|
||||
case 'k': res *= 1000; break; // kilo symbol should be a lowercase K
|
||||
case 'K': res *= 1000; break;
|
||||
case 'i':
|
||||
{
|
||||
// KiB, MiB, GiB and TiB are 1024 multiples
|
||||
if (str.size()<4)
|
||||
return res;
|
||||
|
||||
switch (str[str.size()-3])
|
||||
{
|
||||
case 'T': res *= 1024;
|
||||
case 'G': res *= 1024;
|
||||
case 'M': res *= 1024;
|
||||
case 'K': res *= 1024;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue