mirror of https://github.com/AxioDL/tinyxml2.git
Merge pull request #249 from Dmitry-Me/unifySkipWhiteSpaceCallsAddAsserts
Unify SkipWhiteSpace()/ReadBOM() calls, add asserts
This commit is contained in:
commit
78120c2a1e
20
tinyxml2.cpp
20
tinyxml2.cpp
|
@ -162,7 +162,7 @@ void StrPair::CollapseWhitespace()
|
|||
// Trim leading space.
|
||||
_start = XMLUtil::SkipWhiteSpace( _start );
|
||||
|
||||
if ( _start && *_start ) {
|
||||
if ( *_start ) {
|
||||
char* p = _start; // the read pointer
|
||||
char* q = _start; // the write pointer
|
||||
|
||||
|
@ -277,6 +277,8 @@ const char* StrPair::GetStr()
|
|||
|
||||
const char* XMLUtil::ReadBOM( const char* p, bool* bom )
|
||||
{
|
||||
TIXMLASSERT( p );
|
||||
TIXMLASSERT( bom );
|
||||
*bom = false;
|
||||
const unsigned char* pu = reinterpret_cast<const unsigned char*>(p);
|
||||
// Check for BOM:
|
||||
|
@ -286,6 +288,7 @@ const char* XMLUtil::ReadBOM( const char* p, bool* bom )
|
|||
*bom = true;
|
||||
p += 3;
|
||||
}
|
||||
TIXMLASSERT( p );
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -505,7 +508,7 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
|
|||
{
|
||||
char* const start = p;
|
||||
p = XMLUtil::SkipWhiteSpace( p );
|
||||
if( !p || !*p ) {
|
||||
if( !*p ) {
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -641,6 +644,7 @@ void XMLNode::DeleteChildren()
|
|||
|
||||
void XMLNode::Unlink( XMLNode* child )
|
||||
{
|
||||
TIXMLASSERT( child );
|
||||
TIXMLASSERT( child->_document == _document );
|
||||
if ( child == _firstChild ) {
|
||||
_firstChild = _firstChild->_next;
|
||||
|
@ -661,6 +665,7 @@ void XMLNode::Unlink( XMLNode* child )
|
|||
|
||||
void XMLNode::DeleteChild( XMLNode* node )
|
||||
{
|
||||
TIXMLASSERT( node );
|
||||
TIXMLASSERT( node->_document == _document );
|
||||
TIXMLASSERT( node->_parent == this );
|
||||
DeleteNode( node );
|
||||
|
@ -1132,7 +1137,7 @@ char* XMLAttribute::ParseDeep( char* p, bool processEntities )
|
|||
|
||||
// Skip white space before =
|
||||
p = XMLUtil::SkipWhiteSpace( p );
|
||||
if ( !p || *p != '=' ) {
|
||||
if ( *p != '=' ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1468,7 +1473,7 @@ char* XMLElement::ParseAttributes( char* p )
|
|||
// Read the attributes.
|
||||
while( p ) {
|
||||
p = XMLUtil::SkipWhiteSpace( p );
|
||||
if ( !p || !(*p) ) {
|
||||
if ( !(*p) ) {
|
||||
_document->SetError( XML_ERROR_PARSING_ELEMENT, start, Name() );
|
||||
return 0;
|
||||
}
|
||||
|
@ -1535,9 +1540,6 @@ char* XMLElement::ParseDeep( char* p, StrPair* strPair )
|
|||
{
|
||||
// Read the element name.
|
||||
p = XMLUtil::SkipWhiteSpace( p );
|
||||
if ( !p ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The closing element is the </element> form. It is
|
||||
// parsed just like a regular element then deleted from
|
||||
|
@ -1828,7 +1830,7 @@ XMLError XMLDocument::LoadFile( FILE* fp )
|
|||
const char* p = _charBuffer;
|
||||
p = XMLUtil::SkipWhiteSpace( p );
|
||||
p = XMLUtil::ReadBOM( p, &_writeBOM );
|
||||
if ( !p || !*p ) {
|
||||
if ( !*p ) {
|
||||
SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );
|
||||
return _errorID;
|
||||
}
|
||||
|
@ -1877,7 +1879,7 @@ XMLError XMLDocument::Parse( const char* p, size_t len )
|
|||
const char* start = p;
|
||||
p = XMLUtil::SkipWhiteSpace( p );
|
||||
p = XMLUtil::ReadBOM( p, &_writeBOM );
|
||||
if ( !p || !*p ) {
|
||||
if ( !*p ) {
|
||||
SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );
|
||||
return _errorID;
|
||||
}
|
||||
|
|
|
@ -533,9 +533,11 @@ class XMLUtil
|
|||
{
|
||||
public:
|
||||
static const char* SkipWhiteSpace( const char* p ) {
|
||||
TIXMLASSERT( p );
|
||||
while( IsWhiteSpace(*p) ) {
|
||||
++p;
|
||||
}
|
||||
TIXMLASSERT( p );
|
||||
return p;
|
||||
}
|
||||
static char* SkipWhiteSpace( char* p ) {
|
||||
|
|
Loading…
Reference in New Issue