Skip to content

Commit 222dceb

Browse files
Added check for partial words in options
1 parent 4ab92d4 commit 222dceb

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

input.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,17 @@ namespace marxan {
750750
for (string line : infile)
751751
{ /* loop through file looking for varname */
752752
// if line contains varname
753-
if (line.find(modifiedVar) != string::npos) {
753+
size_t var_start = line.find(modifiedVar);
754+
size_t var_end = var_start + modifiedVar.size();
755+
if (var_start != string::npos) {
756+
//skip if we found only partial word
757+
if(var_start > 0 && (isalpha(line[var_start-1])))
758+
continue;
759+
if(var_end < line.size() && (isalpha(line[var_end])))
760+
continue;
761+
754762
// try to parse the value next to the variable by erasing first modifiedVar characters of line
755-
string varValue = line.erase(0, modifiedVar.size());
763+
string varValue = line.erase(var_start, modifiedVar.size());
756764
utils::trim(varValue);
757765

758766
if (varValue.empty()) { // variable defined but no value - keep looping.

0 commit comments

Comments
 (0)