mirror of https://github.com/AxioDL/tinyxml2.git
Reuse code with pre-parse adjustments
This commit is contained in:
parent
b4e81b014e
commit
97476b7b9e
34
tinyxml2.cpp
34
tinyxml2.cpp
|
@ -1820,15 +1820,7 @@ XMLError XMLDocument::LoadFile( FILE* fp )
|
||||||
|
|
||||||
_charBuffer[size] = 0;
|
_charBuffer[size] = 0;
|
||||||
|
|
||||||
const char* p = _charBuffer;
|
Parse();
|
||||||
p = XMLUtil::SkipWhiteSpace( p );
|
|
||||||
p = XMLUtil::ReadBOM( p, &_writeBOM );
|
|
||||||
if ( !*p ) {
|
|
||||||
SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );
|
|
||||||
return _errorID;
|
|
||||||
}
|
|
||||||
|
|
||||||
ParseDeep( _charBuffer + (p-_charBuffer), 0 );
|
|
||||||
return _errorID;
|
return _errorID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1869,16 +1861,7 @@ XMLError XMLDocument::Parse( const char* p, size_t len )
|
||||||
memcpy( _charBuffer, p, len );
|
memcpy( _charBuffer, p, len );
|
||||||
_charBuffer[len] = 0;
|
_charBuffer[len] = 0;
|
||||||
|
|
||||||
const char* start = p;
|
Parse();
|
||||||
p = XMLUtil::SkipWhiteSpace( p );
|
|
||||||
p = XMLUtil::ReadBOM( p, &_writeBOM );
|
|
||||||
if ( !*p ) {
|
|
||||||
SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );
|
|
||||||
return _errorID;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptrdiff_t delta = p - start; // skip initial whitespace, BOM, etc.
|
|
||||||
ParseDeep( _charBuffer+delta, 0 );
|
|
||||||
if ( Error() ) {
|
if ( Error() ) {
|
||||||
// clean up now essentially dangling memory.
|
// clean up now essentially dangling memory.
|
||||||
// and the parse fail can put objects in the
|
// and the parse fail can put objects in the
|
||||||
|
@ -1936,6 +1919,19 @@ void XMLDocument::PrintError() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XMLDocument::Parse()
|
||||||
|
{
|
||||||
|
TIXMLASSERT( NoChildren() ); // Clear() must have been called previously
|
||||||
|
TIXMLASSERT( _charBuffer );
|
||||||
|
const char* p = _charBuffer;
|
||||||
|
p = XMLUtil::SkipWhiteSpace( p );
|
||||||
|
p = XMLUtil::ReadBOM( p, &_writeBOM );
|
||||||
|
if ( !*p ) {
|
||||||
|
SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ParseDeep( _charBuffer + (p-_charBuffer), 0 );
|
||||||
|
}
|
||||||
|
|
||||||
XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) :
|
XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) :
|
||||||
_elementJustOpened( false ),
|
_elementJustOpened( false ),
|
||||||
|
|
|
@ -1730,6 +1730,8 @@ private:
|
||||||
MemPoolT< sizeof(XMLComment) > _commentPool;
|
MemPoolT< sizeof(XMLComment) > _commentPool;
|
||||||
|
|
||||||
static const char* _errorNames[XML_ERROR_COUNT];
|
static const char* _errorNames[XML_ERROR_COUNT];
|
||||||
|
|
||||||
|
void Parse();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue