Patch .bin filename to .yml

This commit is contained in:
Raphael Coeffic
2021-12-31 10:53:11 +01:00
parent 7e8e5bf554
commit e56e769d27
4 changed files with 23 additions and 4 deletions
@@ -158,3 +158,18 @@ bool writeRadioSettingsToYaml(const GeneralSettings& settings, QByteArray& data)
writeYamlToByteArray(node, data);
return true;
}
std::string patchFilenameToYaml(const std::string& str)
{
constexpr const char MODELS_EXT[] = ".bin";
constexpr const char YAML_EXT[] = ".yml";
constexpr unsigned bin_len = sizeof(MODELS_EXT) - 1;
// patch file extension
auto const dot_pos = str.find_last_of('.');
if ((dot_pos != std::string::npos) && (str.substr(dot_pos) == MODELS_EXT)) {
std::string tmp = str;
return tmp.replace(dot_pos, bin_len, YAML_EXT);
}
return str;
}