Updated tinyxml to d211bb13512cf4edb408e2c4badbcf4100ce0fd0

This commit is contained in:
PKEuS 2014-10-18 11:17:29 +02:00
parent c395512ea6
commit ef92bcbc5a
2 changed files with 32 additions and 31 deletions

View File

@ -114,12 +114,12 @@ char* StrPair::ParseText( char* p, const char* endTag, int strFlags )
char* StrPair::ParseName( char* p ) char* StrPair::ParseName( char* p )
{ {
char* start = p; if ( !p || !(*p) ) {
if ( !start || !(*start) ) {
return 0; return 0;
} }
char* const start = p;
while( *p && ( p == start ? XMLUtil::IsNameStartChar( *p ) : XMLUtil::IsNameChar( *p ) )) { while( *p && ( p == start ? XMLUtil::IsNameStartChar( *p ) : XMLUtil::IsNameChar( *p ) )) {
++p; ++p;
} }
@ -212,12 +212,13 @@ const char* StrPair::GetStr()
else { else {
int i=0; int i=0;
for(; i<NUM_ENTITIES; ++i ) { for(; i<NUM_ENTITIES; ++i ) {
if ( strncmp( p+1, entities[i].pattern, entities[i].length ) == 0 const Entity& entity = entities[i];
&& *(p+entities[i].length+1) == ';' ) { if ( strncmp( p + 1, entity.pattern, entity.length ) == 0
// Found an entity convert; && *( p + entity.length + 1 ) == ';' ) {
*q = entities[i].value; // Found an entity - convert.
*q = entity.value;
++q; ++q;
p += entities[i].length + 2; p += entity.length + 2;
break; break;
} }
} }
@ -479,8 +480,7 @@ bool XMLUtil::ToDouble( const char* str, double* value )
char* XMLDocument::Identify( char* p, XMLNode** node ) char* XMLDocument::Identify( char* p, XMLNode** node )
{ {
XMLNode* returnNode = 0; char* const start = p;
char* start = p;
p = XMLUtil::SkipWhiteSpace( p ); p = XMLUtil::SkipWhiteSpace( p );
if( !p || !*p ) { if( !p || !*p ) {
return p; return p;
@ -509,6 +509,7 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning (pop) #pragma warning (pop)
#endif #endif
XMLNode* returnNode = 0;
if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) { if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) {
returnNode = new (_commentPool.Alloc()) XMLDeclaration( this ); returnNode = new (_commentPool.Alloc()) XMLDeclaration( this );
returnNode->_memPool = &_commentPool; returnNode->_memPool = &_commentPool;
@ -823,7 +824,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
// We read the end tag. Return it to the parent. // We read the end tag. Return it to the parent.
if ( ele && ele->ClosingType() == XMLElement::CLOSING ) { if ( ele && ele->ClosingType() == XMLElement::CLOSING ) {
if ( parentEnd ) { if ( parentEnd ) {
*parentEnd = static_cast<XMLElement*>(node)->_value; *parentEnd = ele->_value;
} }
node->_memPool->SetTracked(); // created and then immediately deleted. node->_memPool->SetTracked(); // created and then immediately deleted.
DeleteNode( node ); DeleteNode( node );
@ -833,21 +834,23 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
// Handle an end tag returned to this level. // Handle an end tag returned to this level.
// And handle a bunch of annoying errors. // And handle a bunch of annoying errors.
if ( ele ) { if ( ele ) {
bool mismatch = false;
if ( endTag.Empty() && ele->ClosingType() == XMLElement::OPEN ) { if ( endTag.Empty() && ele->ClosingType() == XMLElement::OPEN ) {
_document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); mismatch = true;
p = 0;
} }
else if ( !endTag.Empty() && ele->ClosingType() != XMLElement::OPEN ) { else if ( !endTag.Empty() && ele->ClosingType() != XMLElement::OPEN ) {
_document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); mismatch = true;
p = 0;
} }
else if ( !endTag.Empty() ) { else if ( !endTag.Empty() ) {
if ( !XMLUtil::StringEqual( endTag.GetStr(), node->Value() )) { if ( !XMLUtil::StringEqual( endTag.GetStr(), node->Value() )) {
mismatch = true;
}
}
if ( mismatch ) {
_document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 );
p = 0; p = 0;
} }
} }
}
if ( p == 0 ) { if ( p == 0 ) {
DeleteNode( node ); DeleteNode( node );
node = 0; node = 0;
@ -911,7 +914,8 @@ XMLNode* XMLText::ShallowClone( XMLDocument* doc ) const
bool XMLText::ShallowEqual( const XMLNode* compare ) const bool XMLText::ShallowEqual( const XMLNode* compare ) const
{ {
return ( compare->ToText() && XMLUtil::StringEqual( compare->ToText()->Value(), Value() )); const XMLText* text = compare->ToText();
return ( text && XMLUtil::StringEqual( text->Value(), Value() ) );
} }
@ -1254,7 +1258,7 @@ const char* XMLElement::Attribute( const char* name, const char* value ) const
const char* XMLElement::GetText() const const char* XMLElement::GetText() const
{ {
if ( FirstChild() && FirstChild()->ToText() ) { if ( FirstChild() && FirstChild()->ToText() ) {
return FirstChild()->ToText()->Value(); return FirstChild()->Value();
} }
return 0; return 0;
} }
@ -1314,7 +1318,7 @@ void XMLElement::SetText( double v )
XMLError XMLElement::QueryIntText( int* ival ) const XMLError XMLElement::QueryIntText( int* ival ) const
{ {
if ( FirstChild() && FirstChild()->ToText() ) { if ( FirstChild() && FirstChild()->ToText() ) {
const char* t = FirstChild()->ToText()->Value(); const char* t = FirstChild()->Value();
if ( XMLUtil::ToInt( t, ival ) ) { if ( XMLUtil::ToInt( t, ival ) ) {
return XML_SUCCESS; return XML_SUCCESS;
} }
@ -1327,7 +1331,7 @@ XMLError XMLElement::QueryIntText( int* ival ) const
XMLError XMLElement::QueryUnsignedText( unsigned* uval ) const XMLError XMLElement::QueryUnsignedText( unsigned* uval ) const
{ {
if ( FirstChild() && FirstChild()->ToText() ) { if ( FirstChild() && FirstChild()->ToText() ) {
const char* t = FirstChild()->ToText()->Value(); const char* t = FirstChild()->Value();
if ( XMLUtil::ToUnsigned( t, uval ) ) { if ( XMLUtil::ToUnsigned( t, uval ) ) {
return XML_SUCCESS; return XML_SUCCESS;
} }
@ -1340,7 +1344,7 @@ XMLError XMLElement::QueryUnsignedText( unsigned* uval ) const
XMLError XMLElement::QueryBoolText( bool* bval ) const XMLError XMLElement::QueryBoolText( bool* bval ) const
{ {
if ( FirstChild() && FirstChild()->ToText() ) { if ( FirstChild() && FirstChild()->ToText() ) {
const char* t = FirstChild()->ToText()->Value(); const char* t = FirstChild()->Value();
if ( XMLUtil::ToBool( t, bval ) ) { if ( XMLUtil::ToBool( t, bval ) ) {
return XML_SUCCESS; return XML_SUCCESS;
} }
@ -1353,7 +1357,7 @@ XMLError XMLElement::QueryBoolText( bool* bval ) const
XMLError XMLElement::QueryDoubleText( double* dval ) const XMLError XMLElement::QueryDoubleText( double* dval ) const
{ {
if ( FirstChild() && FirstChild()->ToText() ) { if ( FirstChild() && FirstChild()->ToText() ) {
const char* t = FirstChild()->ToText()->Value(); const char* t = FirstChild()->Value();
if ( XMLUtil::ToDouble( t, dval ) ) { if ( XMLUtil::ToDouble( t, dval ) ) {
return XML_SUCCESS; return XML_SUCCESS;
} }
@ -1366,7 +1370,7 @@ XMLError XMLElement::QueryDoubleText( double* dval ) const
XMLError XMLElement::QueryFloatText( float* fval ) const XMLError XMLElement::QueryFloatText( float* fval ) const
{ {
if ( FirstChild() && FirstChild()->ToText() ) { if ( FirstChild() && FirstChild()->ToText() ) {
const char* t = FirstChild()->ToText()->Value(); const char* t = FirstChild()->Value();
if ( XMLUtil::ToFloat( t, fval ) ) { if ( XMLUtil::ToFloat( t, fval ) ) {
return XML_SUCCESS; return XML_SUCCESS;
} }

View File

@ -523,10 +523,7 @@ public:
return p; return p;
} }
static char* SkipWhiteSpace( char* p ) { static char* SkipWhiteSpace( char* p ) {
while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast<unsigned char*>(p) ) ) { return const_cast<char*>( SkipWhiteSpace( const_cast<const char*>(p) ) );
++p;
}
return p;
} }
static bool IsWhiteSpace( char p ) { static bool IsWhiteSpace( char p ) {
return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) ); return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );
@ -561,8 +558,8 @@ public:
return false; return false;
} }
inline static int IsUTF8Continuation( const char p ) { inline static bool IsUTF8Continuation( const char p ) {
return p & 0x80; return ( p & 0x80 ) != 0;
} }
static const char* ReadBOM( const char* p, bool* hasBOM ); static const char* ReadBOM( const char* p, bool* hasBOM );