@@ -114,12 +114,12 @@ char* StrPair::ParseText( char* p, const char* endTag, int strFlags )
114114
115115char * StrPair::ParseName ( char * p )
116116{
117- char * start = p;
118-
119- if ( !start || !(*start) ) {
117+ if ( !p || !(*p) ) {
120118 return 0 ;
121119 }
122120
121+ char * const start = p;
122+
123123 while ( *p && ( p == start ? XMLUtil::IsNameStartChar ( *p ) : XMLUtil::IsNameChar ( *p ) )) {
124124 ++p;
125125 }
@@ -212,12 +212,13 @@ const char* StrPair::GetStr()
212212 else {
213213 int i=0 ;
214214 for (; i<NUM_ENTITIES ; ++i ) {
215- if ( strncmp ( p+1 , entities[i].pattern , entities[i].length ) == 0
216- && *(p+entities[i].length +1 ) == ' ;' ) {
217- // Found an entity convert;
218- *q = entities[i].value ;
215+ const Entity& entity = entities[i];
216+ if ( strncmp ( p + 1 , entity.pattern , entity.length ) == 0
217+ && *( p + entity.length + 1 ) == ' ;' ) {
218+ // Found an entity - convert.
219+ *q = entity.value ;
219220 ++q;
220- p += entities[i] .length + 2 ;
221+ p += entity .length + 2 ;
221222 break ;
222223 }
223224 }
@@ -479,8 +480,7 @@ bool XMLUtil::ToDouble( const char* str, double* value )
479480
480481char * XMLDocument::Identify ( char * p, XMLNode** node )
481482{
482- XMLNode* returnNode = 0 ;
483- char * start = p;
483+ char * const start = p;
484484 p = XMLUtil::SkipWhiteSpace ( p );
485485 if ( !p || !*p ) {
486486 return p;
@@ -509,6 +509,7 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
509509#if defined(_MSC_VER)
510510#pragma warning (pop)
511511#endif
512+ XMLNode* returnNode = 0 ;
512513 if ( XMLUtil::StringEqual ( p, xmlHeader, xmlHeaderLen ) ) {
513514 returnNode = new (_commentPool.Alloc ()) XMLDeclaration ( this );
514515 returnNode->_memPool = &_commentPool;
@@ -693,7 +694,7 @@ XMLNode* XMLNode::InsertFirstChild( XMLNode* addThis )
693694 addThis->_next = 0 ;
694695 }
695696 addThis->_parent = this ;
696- return addThis;
697+ return addThis;
697698}
698699
699700
@@ -823,7 +824,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
823824 // We read the end tag. Return it to the parent.
824825 if ( ele && ele->ClosingType () == XMLElement::CLOSING ) {
825826 if ( parentEnd ) {
826- *parentEnd = static_cast <XMLElement*>(node) ->_value ;
827+ *parentEnd = ele ->_value ;
827828 }
828829 node->_memPool ->SetTracked (); // created and then immediately deleted.
829830 DeleteNode ( node );
@@ -833,20 +834,22 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
833834 // Handle an end tag returned to this level.
834835 // And handle a bunch of annoying errors.
835836 if ( ele ) {
837+ bool mismatch = false ;
836838 if ( endTag.Empty () && ele->ClosingType () == XMLElement::OPEN ) {
837- _document->SetError ( XML_ERROR_MISMATCHED_ELEMENT , node->Value (), 0 );
838- p = 0 ;
839+ mismatch = true ;
839840 }
840841 else if ( !endTag.Empty () && ele->ClosingType () != XMLElement::OPEN ) {
841- _document->SetError ( XML_ERROR_MISMATCHED_ELEMENT , node->Value (), 0 );
842- p = 0 ;
842+ mismatch = true ;
843843 }
844844 else if ( !endTag.Empty () ) {
845845 if ( !XMLUtil::StringEqual ( endTag.GetStr (), node->Value () )) {
846- _document->SetError ( XML_ERROR_MISMATCHED_ELEMENT , node->Value (), 0 );
847- p = 0 ;
846+ mismatch = true ;
848847 }
849848 }
849+ if ( mismatch ) {
850+ _document->SetError ( XML_ERROR_MISMATCHED_ELEMENT , node->Value (), 0 );
851+ p = 0 ;
852+ }
850853 }
851854 if ( p == 0 ) {
852855 DeleteNode ( node );
@@ -911,7 +914,8 @@ XMLNode* XMLText::ShallowClone( XMLDocument* doc ) const
911914
912915bool XMLText::ShallowEqual ( const XMLNode* compare ) const
913916{
914- return ( compare->ToText () && XMLUtil::StringEqual ( compare->ToText ()->Value (), Value () ));
917+ const XMLText* text = compare->ToText ();
918+ return ( text && XMLUtil::StringEqual ( text->Value (), Value () ) );
915919}
916920
917921
@@ -1254,7 +1258,7 @@ const char* XMLElement::Attribute( const char* name, const char* value ) const
12541258const char * XMLElement::GetText () const
12551259{
12561260 if ( FirstChild () && FirstChild ()->ToText () ) {
1257- return FirstChild ()->ToText ()-> Value ();
1261+ return FirstChild ()->Value ();
12581262 }
12591263 return 0 ;
12601264}
@@ -1314,7 +1318,7 @@ void XMLElement::SetText( double v )
13141318XMLError XMLElement::QueryIntText ( int * ival ) const
13151319{
13161320 if ( FirstChild () && FirstChild ()->ToText () ) {
1317- const char * t = FirstChild ()->ToText ()-> Value ();
1321+ const char * t = FirstChild ()->Value ();
13181322 if ( XMLUtil::ToInt ( t, ival ) ) {
13191323 return XML_SUCCESS ;
13201324 }
@@ -1327,7 +1331,7 @@ XMLError XMLElement::QueryIntText( int* ival ) const
13271331XMLError XMLElement::QueryUnsignedText ( unsigned * uval ) const
13281332{
13291333 if ( FirstChild () && FirstChild ()->ToText () ) {
1330- const char * t = FirstChild ()->ToText ()-> Value ();
1334+ const char * t = FirstChild ()->Value ();
13311335 if ( XMLUtil::ToUnsigned ( t, uval ) ) {
13321336 return XML_SUCCESS ;
13331337 }
@@ -1340,7 +1344,7 @@ XMLError XMLElement::QueryUnsignedText( unsigned* uval ) const
13401344XMLError XMLElement::QueryBoolText ( bool * bval ) const
13411345{
13421346 if ( FirstChild () && FirstChild ()->ToText () ) {
1343- const char * t = FirstChild ()->ToText ()-> Value ();
1347+ const char * t = FirstChild ()->Value ();
13441348 if ( XMLUtil::ToBool ( t, bval ) ) {
13451349 return XML_SUCCESS ;
13461350 }
@@ -1353,7 +1357,7 @@ XMLError XMLElement::QueryBoolText( bool* bval ) const
13531357XMLError XMLElement::QueryDoubleText ( double * dval ) const
13541358{
13551359 if ( FirstChild () && FirstChild ()->ToText () ) {
1356- const char * t = FirstChild ()->ToText ()-> Value ();
1360+ const char * t = FirstChild ()->Value ();
13571361 if ( XMLUtil::ToDouble ( t, dval ) ) {
13581362 return XML_SUCCESS ;
13591363 }
@@ -1366,7 +1370,7 @@ XMLError XMLElement::QueryDoubleText( double* dval ) const
13661370XMLError XMLElement::QueryFloatText ( float * fval ) const
13671371{
13681372 if ( FirstChild () && FirstChild ()->ToText () ) {
1369- const char * t = FirstChild ()->ToText ()-> Value ();
1373+ const char * t = FirstChild ()->Value ();
13701374 if ( XMLUtil::ToFloat ( t, fval ) ) {
13711375 return XML_SUCCESS ;
13721376 }
0 commit comments