Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: ruff check . --output-format=github

test:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
Expand Down
21 changes: 19 additions & 2 deletions TestConcoreHpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,25 @@ static void test_load_params_semicolon_format() {
rm("in1/concore.params");
}

static void test_load_params_semicolon_bare_words() {
setup_dirs();
write_file("in1/concore.params", "n=3;mode=fast;name=hello world;url=http://x.org/a?b=c");

Concore c;
c.delay = 0;
c.load_params();

check("bare word keeps numeric param", c.tryparam("n", "") == "3");
check("bare word value", c.tryparam("mode", "") == "fast");
check("bare word keeps spaces", c.tryparam("name", "") == "hello world");
check("bare word keeps '=' in value", c.tryparam("url", "") == "http://x.org/a?b=c");

rm("in1/concore.params");
}

static void test_tryparam_comma_in_value() {
setup_dirs();
write_file("in/1/concore.params", "{'channels': [1, 2], 'gain': '0.5'}");
write_file("in1/concore.params", "{'channels': [1, 2], 'gain': '0.5'}");

Concore c;
c.delay = 0;
Expand All @@ -342,7 +358,7 @@ static void test_tryparam_comma_in_value() {
check("tryparam preserves list with comma", c.tryparam("channels", "") == "[1, 2]");
check("tryparam preserves subsequent key", c.tryparam("gain", "") == "0.5");

rm("in/1/concore.params");
rm("in1/concore.params");
}

// ------------- main -------------------------------------------------------
Expand Down Expand Up @@ -382,6 +398,7 @@ int main() {
test_tryparam_found();
test_tryparam_missing_key_uses_default();
test_load_params_semicolon_format();
test_load_params_semicolon_bare_words();
test_tryparam_comma_in_value();

std::cout << "\n=== Results: " << passed << " passed, " << failed
Expand Down
25 changes: 12 additions & 13 deletions concore_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,19 +365,18 @@ inline std::map<std::string, std::string> load_params(const std::string& params_
try { return parsedict(sparams); } catch (...) {}
}

// Otherwise convert semicolon-separated key=value to dict format
// e.g. "a=1;b=2" -> {"a":"1","b":"2"}
std::string normalized = std::regex_replace(sparams, std::regex(";"), ",");
std::string converted = "{\"" +
std::regex_replace(
std::regex_replace(
std::regex_replace(normalized, std::regex(","), ",\""),
std::regex("="), "\":"),
std::regex(" "), "") +
"}";
try { return parsedict(converted); } catch (...) {}

return {};
// Otherwise split semicolon-separated key=value, keeping bare words as strings
std::map<std::string, std::string> result;
std::stringstream items(sparams);
std::string item;
while (std::getline(items, item, ';')) {
size_t eq = item.find('=');
if (eq == std::string::npos) continue;
std::string key = stripstr(item.substr(0, eq));
if (key.empty()) continue;
result[key] = stripquotes(stripstr(item.substr(eq + 1)));
}
return result;
}

/**
Expand Down
Loading