satdump/src-core/utils/unit_parser.cpp
2025-07-13 17:52:17 +02:00

26 lines
No EOL
746 B
C++

#include "unit_parser.h"
#include "logger.h"
#include "utils/string.h"
#include <algorithm>
namespace satdump
{
bool parseUnitFromString(std::string str, double &out, std::vector<UnitInfo> unit)
{
// To avoid find() matching on smaller strings first
std::sort(unit.begin(), unit.end(), [](const auto &lhs, const auto &rhs) { return lhs.name.size() > rhs.name.size(); });
for (auto &u : unit)
{
if (str.find(u.name) != std::string::npos)
{
replaceAllStr(str, u.name, "");
logger->critical(str);
out = (std::stod(str) * u.scale);
return true;
}
}
return false;
}
} // namespace satdump