avoid strtok() when reading variables from file

This commit is contained in:
Axel Kohlmeyer
2021-03-13 21:00:09 -05:00
parent 3183c4bdb7
commit 11386097c6

View File

@ -5117,8 +5117,10 @@ int VarReader::read_scalar(char *str)
if (n == 0) break; // end of file
str[n-1] = '\0'; // strip newline
if ((ptr = strchr(str,'#'))) *ptr = '\0'; // strip comment
if (strtok(str," \t\n\r\f") == nullptr) continue; // skip if blank
str += strspn(" \t\n\r\f"); // strip whitespace
str[strcspn(str," \t\n\r\f")] = '\0';
n = strlen(str) + 1;
if (n == 1) continue; // skip if blank
break;
}
}
@ -5160,8 +5162,10 @@ int VarReader::read_peratom()
if (n == 0) break; // end of file
str[n-1] = '\0'; // strip newline
if ((ptr = strchr(str,'#'))) *ptr = '\0'; // strip comment
if (strtok(str," \t\n\r\f") == nullptr) continue; // skip if blank
str += strspn(" \t\n\r\f"); // strip whitespace
str[strcspn(str," \t\n\r\f")] = '\0';
n = strlen(str) + 1;
if (n == 1) continue; // skip if blank
break;
}
}