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

make sure we don't call substr(..., 0)

parent f48600e2
No related branches found
No related tags found
No related merge requests found
...@@ -146,8 +146,19 @@ namespace onelab{ ...@@ -146,8 +146,19 @@ namespace onelab{
{ {
if(first == std::string::npos) return ""; if(first == std::string::npos) return "";
std::string::size_type last = msg.find_first_of(separator, first); std::string::size_type last = msg.find_first_of(separator, first);
std::string next = msg.substr(first, last - first); std::string next;
first = (last == std::string::npos) ? last : last + 1; if(last == std::string::npos){
next = msg.substr(first);
first = last;
}
else if(first == last){
next = "";
first = last + 1;
}
else{
next = msg.substr(first, last - first);
first = last + 1;
}
return next; return next;
} }
static std::vector<std::string> split(const std::string &msg, static std::vector<std::string> split(const std::string &msg,
......
...@@ -146,8 +146,19 @@ namespace onelab{ ...@@ -146,8 +146,19 @@ namespace onelab{
{ {
if(first == std::string::npos) return ""; if(first == std::string::npos) return "";
std::string::size_type last = msg.find_first_of(separator, first); std::string::size_type last = msg.find_first_of(separator, first);
std::string next = msg.substr(first, last - first); std::string next;
first = (last == std::string::npos) ? last : last + 1; if(last == std::string::npos){
next = msg.substr(first);
first = last;
}
else if(first == last){
next = "";
first = last + 1;
}
else{
next = msg.substr(first, last - first);
first = last + 1;
}
return next; return next;
} }
static std::vector<std::string> split(const std::string &msg, static std::vector<std::string> split(const std::string &msg,
...@@ -275,8 +286,8 @@ namespace onelab{ ...@@ -275,8 +286,8 @@ namespace onelab{
class number : public parameter{ class number : public parameter{
private: private:
double _value, _min, _max, _step; double _value, _min, _max, _step;
// when in a loop, indicates current index in the vector _choices; is -1 // when in a loop, indicates current index in the vector _choices;
// when not in a loop // is -1 when not in a loop
int _index; int _index;
std::vector<double> _choices; std::vector<double> _choices;
std::map<double, std::string> _valueLabels; std::map<double, std::string> _valueLabels;
...@@ -284,7 +295,7 @@ namespace onelab{ ...@@ -284,7 +295,7 @@ namespace onelab{
number(const std::string &name="", double value=0., number(const std::string &name="", double value=0.,
const std::string &label="", const std::string &help="") const std::string &label="", const std::string &help="")
: parameter(name, label, help), _value(value), : parameter(name, label, help), _value(value),
_min(-maxNumber()), _max(maxNumber()), _step(0.), _index(0) {} _min(-maxNumber()), _max(maxNumber()), _step(0.), _index(-1) {}
void setValue(double value){ _value = value; } void setValue(double value){ _value = value; }
void setMin(double min){ _min = min; } void setMin(double min){ _min = min; }
void setMax(double max){ _max = max; } void setMax(double max){ _max = max; }
...@@ -383,9 +394,10 @@ namespace onelab{ ...@@ -383,9 +394,10 @@ namespace onelab{
// The string class. A string has a mutable "kind": we do not derive // The string class. A string has a mutable "kind": we do not derive
// specialized classes, because the kind should be changeable at runtime // specialized classes, because the kind should be changeable at runtime
// (e.g. from a client-dependent mathematical expression to a table of // (e.g. from a client-dependent mathematical expression to a table of
// values). Kinds currently recognized by Gmsh are: "file". Possible kinds // values). Kinds currently recognized by Gmsh are: "file". Possible
// could be "complex", "matrix m n", "hostname", client-dependent mathematical // kinds could be "complex", "matrix m n", "hostname", client-dependent
// expression, onelab mathematical expression (through mathex?), ... // mathematical expression, onelab mathematical expression (through mathex?),
// ...
class string : public parameter{ class string : public parameter{
private: private:
std::string _value, _kind; std::string _value, _kind;
...@@ -944,7 +956,10 @@ namespace onelab{ ...@@ -944,7 +956,10 @@ namespace onelab{
{ {
server::instance()->registerClient(this); server::instance()->registerClient(this);
} }
virtual ~localClient(){} virtual ~localClient()
{
server::instance()->unregisterClient(this);
}
virtual bool set(const number &p){ return _set(p); } virtual bool set(const number &p){ return _set(p); }
virtual bool set(const string &p){ return _set(p); } virtual bool set(const string &p){ return _set(p); }
virtual bool set(const function &p){ return _set(p); } virtual bool set(const function &p){ return _set(p); }
......
...@@ -28,7 +28,7 @@ int main(int argc, char **argv) ...@@ -28,7 +28,7 @@ int main(int argc, char **argv)
std::vector<onelab::string> strings; std::vector<onelab::string> strings;
// try to get the string variable "My solver/My string" from the server // try to get the string variable "My string" from the server
client->get(strings, "My string"); client->get(strings, "My string");
if(strings.size()){ if(strings.size()){
std::cout << "Got string from server: '" << strings[0].getValue() << "'\n"; std::cout << "Got string from server: '" << strings[0].getValue() << "'\n";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment