Skip to content
Snippets Groups Projects
Commit 52c24ab5 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

handle variables with spaces in "Reset" (multiple variables should be separated with a comma)

parent 73a24ea6
No related branches found
No related tags found
No related merge requests found
...@@ -235,6 +235,16 @@ namespace onelab{ ...@@ -235,6 +235,16 @@ namespace onelab{
out.push_back(getNextToken(msg, first, separator)); out.push_back(getNextToken(msg, first, separator));
return out; 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 sanitize(const std::string &in) const
{ {
std::string out(in); std::string out(in);
......
...@@ -666,10 +666,11 @@ static bool serverAction(const std::string &action) ...@@ -666,10 +666,11 @@ static bool serverAction(const std::string &action)
return true; return true;
} }
else if(!action.compare(0, 5, "Reset")){ // reset some variables else if(!action.compare(0, 5, "Reset")){ // reset some variables
std::vector<std::string> what = onelab::parameter::split(action, ' '); std::vector<std::string> what = onelab::parameter::split(action.substr(5), ',');
for(unsigned int i = 1; i < what.size(); i++){ for(unsigned int i = 0; i < what.size(); i++){
Msg::Debug("Clearing variable '%s'", what[i].c_str()); std::string var = onelab::parameter::trim(what[i]);
onelab::server::instance()->clear(what[i]); Msg::Debug("Clearing variable '%s'", var.c_str());
onelab::server::instance()->clear(var);
} }
FlGui::instance()->rebuildTree(false); FlGui::instance()->rebuildTree(false);
return true; return true;
......
...@@ -3,6 +3,9 @@ DefineConstant[ ...@@ -3,6 +3,9 @@ DefineConstant[
b = {a*2, Name "var2", Label "Slave (x 2) variable", ReadOnly 1} b = {a*2, Name "var2", Label "Slave (x 2) variable", ReadOnly 1}
c = {a*2, Name "var3", Label "Editable slave (x 2) variable"} c = {a*2, Name "var3", Label "Editable slave (x 2) variable"}
d = {a*2, Name "var4", Label "Standard (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); Printf("a=%g b=%g c=%g d=%g", a, b, c, d);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment