Keep second 0 in firmware strings

This commit is contained in:
Megamouse 2023-04-18 20:07:02 +02:00
parent e133c8c2c3
commit 5107d1b69b
1 changed files with 11 additions and 2 deletions

View File

@ -414,15 +414,24 @@ std::string utils::get_firmware_version()
version = version.substr(start, end - start);
// Trim version
// Trim version (e.g. '04.8900' becomes '4.89')
const usz trim_start = version.find_first_not_of('0');
const usz trim_end = version.find_last_not_of('0');
if (trim_start == umax)
{
return {};
}
const usz dot_pos = version.find_first_of('.', trim_start);
if (dot_pos == umax)
{
return {};
}
// Try to keep the second 0 in the minor version (e.g. '04.9000' becomes '4.90' instead of '4.9')
const usz trim_end = std::max(version.find_last_not_of('0', dot_pos + 1), std::min(dot_pos + 2, version.size()));
return std::string(version.substr(trim_start, trim_end));
}