refactor handling of partition arguments so it does not modify the string passed
This commit is contained in:
@ -158,7 +158,6 @@ void Universe::reorder(char *style, char *arg)
|
||||
void Universe::add_world(char *str)
|
||||
{
|
||||
int n,nper;
|
||||
char *ptr;
|
||||
|
||||
n = 1;
|
||||
nper = 0;
|
||||
@ -171,28 +170,23 @@ void Universe::add_world(char *str)
|
||||
|
||||
// str may not be empty and may only consist of digits or 'x'
|
||||
|
||||
size_t len = strlen(str);
|
||||
if (len < 1) valid = false;
|
||||
for (size_t i=0; i < len; ++i)
|
||||
if (isdigit(str[i]) || str[i] == 'x') continue;
|
||||
else valid = false;
|
||||
std::string part(str);
|
||||
if (part.size() == 0) valid = false;
|
||||
if (part.find_first_not_of("0123456789x") != std::string::npos) valid = false;
|
||||
|
||||
if (valid) {
|
||||
if ((ptr = strchr(str,'x')) != nullptr) {
|
||||
std::size_t found = part.find_first_of("x");
|
||||
|
||||
// 'x' may not be the first or last character
|
||||
|
||||
if (ptr == str) {
|
||||
valid = false;
|
||||
} else if (strlen(str) == len-1) {
|
||||
if ((found == 0) || (found == (part.size() - 1))) {
|
||||
valid = false;
|
||||
} else if (found == std::string::npos) {
|
||||
nper = atoi(part.c_str());
|
||||
} else {
|
||||
*ptr = '\0';
|
||||
n = atoi(str);
|
||||
nper = atoi(ptr+1);
|
||||
*ptr = 'x';
|
||||
n = atoi(part.substr(0,found).c_str());
|
||||
nper = atoi(part.substr(found-1).c_str());\
|
||||
}
|
||||
} else nper = atoi(str);
|
||||
}
|
||||
|
||||
// require minimum of 1 partition with 1 processor
|
||||
|
||||
Reference in New Issue
Block a user