18 const char* str, uint64_t* out_size,
char default_unit) {
21 *out_size = strtoul(str, &endptr, 10);
22 if (endptr ==
nullptr)
return false;
24 while (*endptr ==
' ') ++endptr;
27 unsigned int base = 1000;
28 unsigned int power = 0;
30 if (*endptr ==
'k' || *endptr ==
'K')
32 else if (*endptr ==
'm' || *endptr ==
'M')
34 else if (*endptr ==
'g' || *endptr ==
'G')
36 else if (*endptr ==
't' || *endptr ==
'T')
38 else if (*endptr ==
'p' || *endptr ==
'P')
42 if ((*endptr ==
'i' || *endptr ==
'I') && power != 0)
43 base = 1024, ++endptr;
46 if (*endptr ==
'b' || *endptr ==
'B') {
55 case 'k': power = 1, base = 1000;
57 case 'm': power = 2, base = 1000;
59 case 'g': power = 3, base = 1000;
61 case 't': power = 4, base = 1000;
63 case 'p': power = 5, base = 1000;
65 case 'K': power = 1, base = 1024;
67 case 'M': power = 2, base = 1024;
69 case 'G': power = 3, base = 1024;
71 case 'T': power = 4, base = 1024;
73 case 'P': power = 5, base = 1024;
79 while (*endptr ==
' ') ++endptr;
82 for (
unsigned int p = 0; p < power; ++p)
85 return (*endptr == 0);
89 const std::string& str, uint64_t* out_size,
char default_unit) {
bool parse_si_iec_units(const char *str, uint64_t *out_size, char default_unit)
Parse a string like "343KB" or "44 GiB" into the corresponding size in bytes.