From 52c24ab58006d914ee5640665a23c3c5d34eda0c Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Mon, 30 Oct 2017 19:26:01 +0100 Subject: [PATCH] handle variables with spaces in "Reset" (multiple variables should be separated with a comma) --- Common/onelab.h | 10 ++++++++++ Fltk/onelabGroup.cpp | 9 +++++---- benchmarks/misc/master_slave_variables.geo | 3 +++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Common/onelab.h b/Common/onelab.h index 2fbcdc3ffa..be36d29587 100644 --- a/Common/onelab.h +++ b/Common/onelab.h @@ -235,6 +235,16 @@ namespace onelab{ out.push_back(getNextToken(msg, first, separator)); return out; } + static std::string trim(const std::string &str, + const std::string &whitespace = " \t\n") + { + std::string::size_type strBegin = str.find_first_not_of(whitespace); + if(strBegin == std::string::npos) + return ""; // no content + std::string::size_type strEnd = str.find_last_not_of(whitespace); + std::string::size_type strRange = strEnd - strBegin + 1; + return str.substr(strBegin, strRange); + } std::string sanitize(const std::string &in) const { std::string out(in); diff --git a/Fltk/onelabGroup.cpp b/Fltk/onelabGroup.cpp index 0f117331cd..4fa5be1fe0 100644 --- a/Fltk/onelabGroup.cpp +++ b/Fltk/onelabGroup.cpp @@ -666,10 +666,11 @@ static bool serverAction(const std::string &action) return true; } else if(!action.compare(0, 5, "Reset")){ // reset some variables - std::vector<std::string> what = onelab::parameter::split(action, ' '); - for(unsigned int i = 1; i < what.size(); i++){ - Msg::Debug("Clearing variable '%s'", what[i].c_str()); - onelab::server::instance()->clear(what[i]); + std::vector<std::string> what = onelab::parameter::split(action.substr(5), ','); + for(unsigned int i = 0; i < what.size(); i++){ + std::string var = onelab::parameter::trim(what[i]); + Msg::Debug("Clearing variable '%s'", var.c_str()); + onelab::server::instance()->clear(var); } FlGui::instance()->rebuildTree(false); return true; diff --git a/benchmarks/misc/master_slave_variables.geo b/benchmarks/misc/master_slave_variables.geo index e7a29ffdac..2bbadc7478 100644 --- a/benchmarks/misc/master_slave_variables.geo +++ b/benchmarks/misc/master_slave_variables.geo @@ -3,6 +3,9 @@ DefineConstant[ b = {a*2, Name "var2", Label "Slave (x 2) variable", ReadOnly 1} c = {a*2, Name "var3", Label "Editable slave (x 2) variable"} d = {a*2, Name "var4", Label "Standard (x 2) variable"} + e = {1, Name "var5", Label "Another master", ServerAction "Reset var6, var7 space "} + f = {e, Name "var6", Label "Another slave (copy)"} + g = {e, Name "var7 space", Label "Another slave (copy)"} ]; Printf("a=%g b=%g c=%g d=%g", a, b, c, d); -- GitLab