The removal of extra |s in interpolated strings is a mistake.

This makes it hard to put a | in a string and don't think removing
them to prevent confusion really has that effect.

I also changed it so that if the variable name is empty that the replacement
string will be a $. This makes it easy to put $s in interpolated strings
and the previous behavior was useless.
This commit is contained in:
Bruno Wolff III 2006-06-21 15:19:11 +00:00
parent 139fab582f
commit 782fc5063b

View file

@ -109,15 +109,18 @@ std::string do_interpolation(const std::string &str, variable_set& set)
}
//The variable is replaced with its value.
//Replace = remove original, and then insert new value, if any.
res.replace(var_begin, var_end, set.get_variable_const(var_name));
if (var_name == "") {
// Allow for a way to have $s in a string.
// $| will be replaced by $.
res.replace(var_begin, var_end, "$");
}
else {
//The variable is replaced with its value.
res.replace(var_begin, var_end,
set.get_variable_const(var_name));
}
}
//Remove any remaining '|', which are used to separate variable names,
//so that the WML writer doesn't need to worry about whether they're really necessary.
//It is also occasionally useful to intentionally put them elsewhere.
res.erase(std::remove(res.begin(), res.end(), '|'), res.end());
return res;
}