27 size = strtoul(str.c_str(), &endptr, 10);
28 if (!endptr)
return false;
30 while (endptr[0] ==
' ') ++endptr;
33 unsigned int base = 1000;
34 unsigned int power = 0;
36 if (endptr[0] ==
'k' || endptr[0] ==
'K')
38 else if (endptr[0] ==
'm' || endptr[0] ==
'M')
40 else if (endptr[0] ==
'g' || endptr[0] ==
'G')
42 else if (endptr[0] ==
't' || endptr[0] ==
'T')
44 else if (endptr[0] ==
'p' || endptr[0] ==
'P')
48 if ((endptr[0] ==
'i' || endptr[0] ==
'I') && power != 0)
49 base = 1024, ++endptr;
52 if (endptr[0] ==
'b' || endptr[0] ==
'B') {
61 case 'k': power = 1, base = 1000;
63 case 'm': power = 2, base = 1000;
65 case 'g': power = 3, base = 1000;
67 case 't': power = 4, base = 1000;
69 case 'p': power = 5, base = 1000;
71 case 'K': power = 1, base = 1024;
73 case 'M': power = 2, base = 1024;
75 case 'G': power = 3, base = 1024;
77 case 'T': power = 4, base = 1024;
79 case 'P': power = 5, base = 1024;
85 while (endptr[0] ==
' ') ++endptr;
88 for (
unsigned int p = 0; p < power; ++p)
91 return (endptr[0] == 0);
97 double multiplier = 1000.0;
98 static const char* SIendings[] = {
"",
"k",
"M",
"G",
"T",
"P",
"E" };
99 unsigned int scale = 0;
100 double number_d = (double)number;
101 while (number_d >= multiplier) {
102 number_d /= multiplier;
105 std::ostringstream out;
106 out << std::fixed << std::setprecision(3) << number_d
107 <<
' ' << SIendings[scale];
114 double multiplier = 1024.0;
115 static const char* IECendings[] = {
"",
"Ki",
"Mi",
"Gi",
"Ti",
"Pi",
"Ei" };
116 unsigned int scale = 0;
117 double number_d = (double)number;
118 while (number_d >= multiplier) {
119 number_d /= multiplier;
122 std::ostringstream out;
123 out << std::fixed << std::setprecision(3) << number_d
124 <<
' ' << IECendings[scale];
unsigned long long int uint64
std::string format_SI_size(uint64 number)
Format a byte size using SI (K, M, G, T) suffixes (powers of ten). Returns "123 M" or similar...
#define STXXL_BEGIN_NAMESPACE
bool parse_SI_IEC_size(const std::string &str, uint64 &size, char def_unit=0)
Parse a string like "343KB" or "44 GiB" into the corresponding size in bytes. Returns the number of b...
std::string format_IEC_size(uint64 number)
Format a byte size using IEC (Ki, Mi, Gi, Ti) suffixes (powers of two). Returns "123 Ki" or similar...
#define STXXL_END_NAMESPACE