SF 1969276 DynamicAny("") should be false; added operator!

This commit is contained in:
Aleksandar Fabijanic 2008-05-22 01:29:32 +00:00
parent 1de922e8c3
commit 532672c027
3 changed files with 22 additions and 7 deletions

View File

@ -66,8 +66,8 @@ class Foundation_API DynamicAny
///
/// Boolean conversion is performed as follows:
///
/// A string value "false" (not case sensitive) or "0" can be converted to a boolean value false, any other string
/// not being false by the above criteria evaluates to true (e.g: "hi" -> true).
/// A string value "false" (not case sensitive), "0" or "" (empty string) can be converted to a boolean value false,
/// any other string not being false by the above criteria evaluates to true (e.g: "hi" -> true).
/// Integer 0 values are false, everything else is true.
/// Floating point values equal to the minimal FP representation on a given platform are false, everything else is true.
///
@ -186,10 +186,15 @@ public:
return *this;
}
bool operator ! ()
{
return !convert<bool>();
}
DynamicAny& operator = (const DynamicAny& other);
/// Assignment operator specialization for DynamicAny
template <typename T>
template <typename T>
const DynamicAny operator + (const T& other) const
/// Addition operator for adding POD to DynamicAny
{

View File

@ -2214,12 +2214,15 @@ public:
void convert(bool& val) const
{
static const std::string VAL_FALSE("false");
static const std::string VAL_INTFALSE("0");
static const std::string VAL_INT_FALSE("0");
if (_val == VAL_INTFALSE || (icompare(_val, VAL_FALSE) == 0))
if (_val.empty() ||
_val == VAL_INT_FALSE ||
(icompare(_val, VAL_FALSE) == 0))
{
val = false;
else
val = true;
}
else val = true;
}
void convert(float& val) const

View File

@ -1154,6 +1154,13 @@ void DynamicAnyTest::testString()
assert (a6 == "123456789");
a4 += "789";
assert (a4 == "123456789");
a4 = "";
assert(!a4);
a4 = "0";
assert(!a4);
a4 = "FaLsE";
assert(!a4);
}