#include <fstream>
#include <sstream>
#include <filesystem>
+#include <regex>
static std::string rm_leading_dashes(const std::string & str) {
size_t pos = 0;
return str.substr(pos);
}
+static std::string canonical_tag(const std::string & tag) {
+ static const std::regex re_tag("[-.]([A-Z0-9_]+)$", std::regex::icase);
+ std::smatch m;
+ if (std::regex_search(tag, m, re_tag)) {
+ std::string canon = m[1].str();
+ for (char & c : canon) {
+ c = (char) std::toupper((unsigned char) c);
+ }
+ return canon;
+ }
+ std::string upper = tag;
+ for (char & c : upper) {
+ c = (char) std::toupper((unsigned char) c);
+ }
+ return upper;
+}
+
std::vector<std::string> common_preset::to_args(const std::string & bin_path) const {
std::vector<std::string> args;
for (auto section : ini_data) {
common_preset preset;
- if (section.first.empty()) {
- preset.name = COMMON_PRESET_DEFAULT_NAME;
- } else {
- preset.name = section.first;
+ std::string section_name = section.first.empty() ? std::string(COMMON_PRESET_DEFAULT_NAME) : section.first;
+ if (section_name != "*" && section_name != COMMON_PRESET_DEFAULT_NAME) {
+ auto colon_idx = section_name.rfind(':');
+ if (colon_idx != std::string::npos) {
+ std::string tag = section_name.substr(colon_idx + 1);
+ std::string canon_tag = canonical_tag(tag);
+ if (canon_tag != tag) {
+ section_name = section_name.substr(0, colon_idx + 1) + canon_tag;
+ }
+ }
}
+ preset.name = section_name;
LOG_DBG("loading preset: %s\n", preset.name.c_str());
for (const auto & [key, value] : section.second) {
if (key == "version") {