Read boolean uppercase
Hello, I'm wondering if it would be possible to parse TRUE and FALSE, too.
It's in this function: bool XMLUtil::ToBool( const char* str, bool* value )
I changed it to this:
bool XMLUtil::ToBool( const char* str, bool* value )
{
int ival = 0;
if ( ToInt( str, &ival )) {
*value = (ival==0) ? false : true;
return true;
}
if ( StringEqual( str, "true" ) ) {
*value = true;
return true;
}
else if ( StringEqual( str, "false" ) ) {
*value = false;
return true;
}
else if ( StringEqual( str, "TRUE" ) ) {
*value = true;
return true;
}
else if ( StringEqual( str, "FALSE" ) ) {
*value = false;
return true;
}
return false;
}
Maybe you want to check this code in.
With kind regards
Manuel
There's a function "XMLUtil::SetBoolSerialization(const TCHAR* writeTrue, const TCHAR* writeFalse)". Try it.
I think this affects writing only. I want to read XML and values can be 1, TRUE or true (for example).
I think better way would be:
- set "XMLUtil::SetBoolSerialization(const char* writeTrue, const char* writeFalse)".
- function "XMLUtil::ToBool" should consider "writeBoolTrue" and "writeBoolFalse" that were set above.
I have re-wrote "XMLUtil::ToBool" such way. bool XMLUtil::ToBool( const char* str, bool* value ) { int ival = 0; if ( ToInt( str, &ival )) { *value = (ival==0) ? false : true; return true; } if ( StringEqual( str, writeBoolTrue ) ) { *value = true; return true; } else if ( StringEqual( str, writeBoolFalse ) ) { *value = false; return true; } return false; }
Now if you call "tinyxml2::XMLUtil::SetBoolSerialization("tRuE_1", "fAlSe_0");" before any other calls I think you can image what will happen.