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
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ jobs:

- name: Download jeromq
run: |
curl -fsSL -o jeromq.jar https://repo1.maven.org/maven2/org/zeromq/jeromq/0.6.0/jeromq-0.6.0.jar
curl -fsSL --retry 5 --retry-connrefused -A "Mozilla/5.0" -o jeromq.jar https://repo1.maven.org/maven2/org/zeromq/jeromq/0.6.0/jeromq-0.6.0.jar || \
curl -fsSL --retry 5 --retry-connrefused -A "Mozilla/5.0" -o jeromq.jar https://repo.maven.apache.org/maven2/org/zeromq/jeromq/0.6.0/jeromq-0.6.0.jar

- name: Compile Java tests
run: |
Expand Down
15 changes: 15 additions & 0 deletions TestConcoreHpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,20 @@ static void test_load_params_semicolon_format() {
rm("in/1/concore.params");
}

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

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

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");
}

// ------------- main -------------------------------------------------------

int main() {
Expand Down Expand Up @@ -337,6 +351,7 @@ int main() {
test_tryparam_found();
test_tryparam_missing_key_uses_default();
test_load_params_semicolon_format();
test_tryparam_comma_in_value();

std::cout << "\n=== Results: " << passed << " passed, " << failed
<< " failed out of " << (passed + failed) << " tests ===\n";
Expand Down
66 changes: 44 additions & 22 deletions concore_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,7 @@ inline std::string stripquotes(const std::string& str) {
// Parsing Utilities
// ===================================================================

/**
* Parses a Python-style dict string into a string→string map.
* Format: {'key1': val1, 'key2': val2}
* Handles both quoted and unquoted keys/values.
*/
inline std::map<std::string, std::string> parsedict(const std::string& str) {
std::map<std::string, std::string> result;
std::string trimmed = stripstr(str);
if (trimmed.size() < 2 || trimmed.front() != '{' || trimmed.back() != '}')
return result;
std::string inner = trimmed.substr(1, trimmed.size() - 2);
std::stringstream ss(inner);
std::string token;
while (std::getline(ss, token, ',')) {
size_t colon = token.find(':');
if (colon == std::string::npos) continue;
std::string key = stripquotes(stripstr(token.substr(0, colon)));
std::string val = stripquotes(stripstr(token.substr(colon + 1)));
if (!key.empty()) result[key] = val;
}
return result;
}
inline std::map<std::string, std::string> parsedict(const std::string& str);

/**
* Parses a Python-style list string into a vector of strings.
Expand Down Expand Up @@ -254,6 +233,49 @@ inline ConcoreValue parse_literal(const std::string& s) {
return v;
}

/**
* Parses a Python-style dict string into a string→string map.
* Format: {'key1': val1, 'key2': val2}
* Handles both quoted and unquoted keys/values.
*/
inline std::map<std::string, std::string> parsedict(const std::string& str) {
std::map<std::string, std::string> result;
std::string trimmed = stripstr(str);
if (trimmed.size() < 2 || trimmed.front() != '{' || trimmed.back() != '}')
return result;

size_t pos = 1;
while (pos < trimmed.size()) {
skip_ws(trimmed, pos);
if (pos >= trimmed.size() || trimmed[pos] == '}') break;

std::string key;
if (trimmed[pos] == '\'' || trimmed[pos] == '"') {
key = parse_literal_string(trimmed, pos).str;
} else {
size_t key_start = pos;
while (pos < trimmed.size() && trimmed[pos] != ':' && !std::isspace(static_cast<unsigned char>(trimmed[pos])))
++pos;
key = trimmed.substr(key_start, pos - key_start);
}

skip_ws(trimmed, pos);
if (pos >= trimmed.size() || trimmed[pos] != ':') break;
++pos;

skip_ws(trimmed, pos);
size_t val_start = pos;
parse_literal_value(trimmed, pos);
std::string val = stripquotes(stripstr(trimmed.substr(val_start, pos - val_start)));

if (!key.empty()) result[key] = val;

skip_ws(trimmed, pos);
if (pos < trimmed.size() && trimmed[pos] == ',') ++pos;
}
return result;
}

inline void flatten_numeric_impl(const ConcoreValue& v, std::vector<double>& out) {
switch (v.type) {
case ConcoreValueType::NUMBER:
Expand Down
Loading