in prod/native/libcommon/code/CommonUtils.cpp [73:98]
std::size_t parseByteUnits(std::string bytesWithUnit) {
auto endWithoutSpaces = std::remove_if(bytesWithUnit.begin(), bytesWithUnit.end(), [](unsigned char c) { return std::isspace(c); });
bytesWithUnit.erase(endWithoutSpaces, bytesWithUnit.end());
std::size_t value = std::stoul(bytesWithUnit.data());
auto unitPos = bytesWithUnit.find_first_not_of("0123456789"sv);
if (unitPos == std::string_view::npos) {
return value;
}
auto unitBuf = bytesWithUnit.substr(unitPos);
istring_view unit{unitBuf.data(), unitBuf.length()};
if (unit == "b"_cisv) {
return value;
} else if (unit == "kb"_cisv) {
return value * 1024;
} else if (unit == "mb"_cisv) {
return value * 1024 * 1024;
} else if (unit == "gb"_cisv) {
return value * 1024 * 1024 * 1024;
}
throw std::invalid_argument("Invalid byte unit.");
}