fix config comparison

the previous implementation would result in ["a"] == "1" beeing false if
'c["a"] = "1";' happened previously.
This commit is contained in:
gfgtdf 2014-07-06 17:22:38 +02:00
parent 792b34686e
commit ca8528d3c7
2 changed files with 8 additions and 2 deletions

View File

@ -395,10 +395,17 @@ bool config::attribute_value::operator==(const config::attribute_value &other) c
* Checks for equality of the attribute values when viewed as strings.
* Exception: Boolean synonyms can be equal ("yes" == "true").
* Note: Blanks have no string representation, so do not equal "" (an empty string).
* Also note that translatable string are never equal to non translatable strings.
*/
bool config::attribute_value::equals(const std::string &str) const
{
return boost::apply_visitor(boost::bind( equality_visitor(), _1, boost::cref(str) ), value_);
attribute_value v;
v = str;
return *this == v;
// if c["a"] = "1" then this solution would have resulted in c["a"] == "1" beeing false
// because a["a"] is '1' and not '"1"'.
// return boost::apply_visitor(boost::bind( equality_visitor(), _1, boost::cref(str) ), value_);
// that's why we don't use it.
}
std::ostream &operator<<(std::ostream &os, const config::attribute_value &v)

View File

@ -285,7 +285,6 @@ public:
bool operator!=(const attribute_value &other) const
{ return !operator==(other); }
// returns always false if the underlying type is no string.
bool equals(const std::string& str) const;
// These function prevent t_string creation in case of c["a"] == "b" comparisons.
// The templates are needed to prevent using these function in case of c["a"] == 0 comparisons.