35 if (size_str.empty()) {
36 return std::numeric_limits<size_t>::max();
40 std::string str = size_str;
43 char suffix =
static_cast<char>(
std::tolower(
static_cast<unsigned char>(str.back())));
44 size_t multiplier = 1;
50 }
else if (suffix ==
'm') {
51 multiplier = 1024ULL * 1024ULL;
53 }
else if (suffix ==
'g') {
54 multiplier = 1024ULL * 1024ULL * 1024ULL;
56 }
else if (
std::isdigit(
static_cast<unsigned char>(suffix)) == 0) {
58 throw_or_abort(
"Invalid storage size format: '" + size_str +
"'. Use format like '500m', '2g', or '1024k'");
63 throw_or_abort(
"Invalid storage size format: '" + size_str +
"'. No numeric value provided");
68 if (multiplier != 0 &&
value > std::numeric_limits<size_t>::max() / multiplier) {
69 throw_or_abort(
"Invalid storage size format: '" + size_str +
"'. Value out of range");
71 return value * multiplier;
72 }
catch (
const std::invalid_argument&) {
73 throw_or_abort(
"Invalid storage size format: '" + size_str +
"'. Not a valid number");
74 }
catch (
const std::out_of_range&) {
75 throw_or_abort(
"Invalid storage size format: '" + size_str +
"'. Value out of range");