Compare commits
38 Commits
firewave-e
...
vimproved-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d59aaf0da | ||
|
|
e0302bfd44 | ||
|
|
bfc4ac4f58 | ||
|
|
8d3cdf50db | ||
|
|
941e2d9018 | ||
|
|
428cd1be42 | ||
|
|
9d026527a4 | ||
|
|
8158ba05ac | ||
|
|
4c27b08f62 | ||
|
|
ac23537e06 | ||
|
|
52035717a3 | ||
|
|
cc4c1df7ec | ||
|
|
f439598036 | ||
|
|
98303bbda3 | ||
|
|
904ad04bea | ||
|
|
5926ec938a | ||
|
|
e05956094c | ||
|
|
9a89766acc | ||
|
|
9706d2cdc0 | ||
|
|
94f52b5cbe | ||
|
|
9ad3f2745b | ||
|
|
2555efa919 | ||
|
|
8fd6cc6d2d | ||
|
|
beb2b2f82d | ||
|
|
07f497d6d8 | ||
|
|
0691cf72b4 | ||
|
|
736659015c | ||
|
|
3e94e4a047 | ||
|
|
e45d9d16d4 | ||
|
|
7e310468f3 | ||
|
|
953018ab93 | ||
|
|
a2d675139b | ||
|
|
a1ea80ba74 | ||
|
|
435c0a1199 | ||
|
|
4cc4145d7f | ||
|
|
6cc405853b | ||
|
|
f6c991658b | ||
|
|
9efb6b0b66 |
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@@ -6,7 +6,7 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ windows-2019, macos-10.15, ubuntu-20.04 ]
|
||||
os: [ windows-2019, macos-latest, ubuntu-20.04 ]
|
||||
cmake: [ 3.15, 3.x ]
|
||||
include:
|
||||
- os: windows-2019
|
||||
@@ -17,7 +17,7 @@ jobs:
|
||||
- os: ubuntu-20.04
|
||||
tree: tree
|
||||
|
||||
- os: macos-10.15
|
||||
- os: macos-latest
|
||||
tree: find
|
||||
|
||||
- cmake: 3.15
|
||||
|
||||
@@ -31,6 +31,7 @@ target_compile_definitions(
|
||||
PUBLIC $<$<CONFIG:Debug>:TINYXML2_DEBUG>
|
||||
INTERFACE $<$<BOOL:${BUILD_SHARED_LIBS}>:TINYXML2_IMPORT>
|
||||
PRIVATE $<$<CXX_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS>
|
||||
PUBLIC _FILE_OFFSET_BITS=64
|
||||
)
|
||||
|
||||
set_target_properties(
|
||||
|
||||
2
Makefile
2
Makefile
@@ -10,7 +10,7 @@ ARFLAGS = cr
|
||||
RM = rm -f
|
||||
RANLIB = ranlib
|
||||
MKDIR = mkdir -p
|
||||
CXXFLAGS = -fPIC
|
||||
CXXFLAGS = -D_FILE_OFFSET_BITS=64 -fPIC
|
||||
|
||||
INSTALL = install
|
||||
INSTALL_PROGRAM = $(INSTALL)
|
||||
|
||||
22
meson.build
22
meson.build
@@ -62,26 +62,6 @@ if meson.version().version_compare('>= 0.54.0')
|
||||
endif
|
||||
|
||||
if get_option('tests')
|
||||
# Try to find a copy command. If this is windows we probably don't have cp,
|
||||
# but if this is msys then we do, so make cp not required in that case, and
|
||||
# try Xcopy if cp isn't found
|
||||
prog_cp = find_program('cp', required : build_machine.system() != 'windows')
|
||||
command = ['-r']
|
||||
if not prog_cp.found()
|
||||
prog_cp = find_program('Xcopy')
|
||||
command = ['/E', '/I']
|
||||
endif
|
||||
|
||||
# Copy the test resources into the build dir
|
||||
run_command(
|
||||
prog_cp,
|
||||
[
|
||||
command,
|
||||
meson.current_source_dir() / 'resources',
|
||||
meson.current_build_dir(),
|
||||
],
|
||||
)
|
||||
|
||||
test(
|
||||
'xmltest',
|
||||
executable(
|
||||
@@ -89,7 +69,7 @@ if get_option('tests')
|
||||
['xmltest.cpp'],
|
||||
link_with : [lib_tinyxml2],
|
||||
),
|
||||
workdir : meson.current_build_dir(),
|
||||
workdir : meson.current_source_dir(),
|
||||
)
|
||||
endif
|
||||
|
||||
|
||||
18
readme.md
18
readme.md
@@ -1,9 +1,7 @@
|
||||
TinyXML-2
|
||||
=========
|
||||
|
||||

|
||||
|
||||

|
||||
[](https://github.com/leethomason/tinyxml2/actions/workflows/test.yml)
|
||||
|
||||
TinyXML-2 is a simple, small, efficient, C++ XML parser that can be
|
||||
easily integrated into other programs.
|
||||
@@ -93,7 +91,7 @@ by the Document. When the Document is deleted, so are all the nodes it contains.
|
||||
|
||||
### White Space
|
||||
|
||||
#### Whitespace Preservation (default)
|
||||
#### Whitespace Preservation (default, PRESERVE_WHITESPACE)
|
||||
|
||||
Microsoft has an excellent article on white space: http://msdn.microsoft.com/en-us/library/ms256097.aspx
|
||||
|
||||
@@ -125,7 +123,7 @@ valuable. TinyXML-2 sees these as the same XML:
|
||||
|
||||
<document><data>1</data><data>2</data><data>3</data></document>
|
||||
|
||||
#### Whitespace Collapse
|
||||
#### Whitespace Collapse (COLLAPSE_WHITESPACE)
|
||||
|
||||
For some applications, it is preferable to collapse whitespace. Collapsing
|
||||
whitespace gives you "HTML-like" behavior, which is sometimes more suitable
|
||||
@@ -143,7 +141,15 @@ However, you may also use COLLAPSE_WHITESPACE, which will:
|
||||
Note that (currently) there is a performance impact for using COLLAPSE_WHITESPACE.
|
||||
It essentially causes the XML to be parsed twice.
|
||||
|
||||
#### Error Reporting
|
||||
#### Pedantic Whitespace (PEDANTIC_WHITESPACE)
|
||||
|
||||
For applications that need to know about text nodes that are composed entirely of
|
||||
whitespace, PEDANTIC_WHITESPACE is available. PEDANTIC_WHITESPACE maintains all the
|
||||
whilespace between elements.
|
||||
|
||||
PEDANTIC_WHITESPACE is a new mode and not as tested as the other whitespace modes.
|
||||
|
||||
### Error Reporting
|
||||
|
||||
TinyXML-2 reports the line number of any errors in an XML document that
|
||||
cannot be parsed correctly. In addition, all nodes (elements, declarations,
|
||||
|
||||
78
tinyxml2.cpp
78
tinyxml2.cpp
@@ -103,13 +103,17 @@ distribution.
|
||||
#if defined(_WIN64)
|
||||
#define TIXML_FSEEK _fseeki64
|
||||
#define TIXML_FTELL _ftelli64
|
||||
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) \
|
||||
|| defined(__NetBSD__) || defined(__DragonFly__) || defined(__ANDROID__)
|
||||
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || (__CYGWIN__)
|
||||
#define TIXML_FSEEK fseeko
|
||||
#define TIXML_FTELL ftello
|
||||
#elif defined(__unix__) && defined(__x86_64__)
|
||||
#elif defined(__ANDROID__)
|
||||
#if __ANDROID_API__ > 24
|
||||
#define TIXML_FSEEK fseeko64
|
||||
#define TIXML_FTELL ftello64
|
||||
#else
|
||||
#define TIXML_FSEEK fseeko
|
||||
#define TIXML_FTELL ftello
|
||||
#endif
|
||||
#else
|
||||
#define TIXML_FSEEK fseek
|
||||
#define TIXML_FTELL ftell
|
||||
@@ -708,7 +712,7 @@ bool XMLUtil::ToUnsigned64(const char* str, uint64_t* value) {
|
||||
}
|
||||
|
||||
|
||||
char* XMLDocument::Identify( char* p, XMLNode** node )
|
||||
char* XMLDocument::Identify( char* p, XMLNode** node, bool first )
|
||||
{
|
||||
TIXMLASSERT( node );
|
||||
TIXMLASSERT( p );
|
||||
@@ -760,10 +764,20 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
|
||||
p += dtdHeaderLen;
|
||||
}
|
||||
else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) {
|
||||
|
||||
// Preserve whitespace pedantically before closing tag, when it's immediately after opening tag
|
||||
if (WhitespaceMode() == PEDANTIC_WHITESPACE && first && p != start && *(p + elementHeaderLen) == '/') {
|
||||
returnNode = CreateUnlinkedNode<XMLText>(_textPool);
|
||||
returnNode->_parseLineNum = startLine;
|
||||
p = start; // Back it up, all the text counts.
|
||||
_parseCurLineNum = startLine;
|
||||
}
|
||||
else {
|
||||
returnNode = CreateUnlinkedNode<XMLElement>(_elementPool);
|
||||
returnNode->_parseLineNum = _parseCurLineNum;
|
||||
p += elementHeaderLen;
|
||||
}
|
||||
}
|
||||
else {
|
||||
returnNode = CreateUnlinkedNode<XMLText>( _textPool );
|
||||
returnNode->_parseLineNum = _parseCurLineNum; // Report line of first non-whitespace character
|
||||
@@ -815,6 +829,34 @@ XMLNode::~XMLNode()
|
||||
}
|
||||
}
|
||||
|
||||
// ChildElementCount was originally suggested by msteiger on the sourceforge page for TinyXML and modified by KB1SPH for TinyXML-2.
|
||||
|
||||
int XMLNode::ChildElementCount(const char *value) const {
|
||||
int count = 0;
|
||||
|
||||
const XMLElement *e = FirstChildElement(value);
|
||||
|
||||
while (e) {
|
||||
e = e->NextSiblingElement(value);
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int XMLNode::ChildElementCount() const {
|
||||
int count = 0;
|
||||
|
||||
const XMLElement *e = FirstChildElement();
|
||||
|
||||
while (e) {
|
||||
e = e->NextSiblingElement();
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
const char* XMLNode::Value() const
|
||||
{
|
||||
// Edge case: XMLDocuments don't have a Value. Return null.
|
||||
@@ -1063,21 +1105,23 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
|
||||
if (_document->Error())
|
||||
return 0;
|
||||
|
||||
bool first = true;
|
||||
while( p && *p ) {
|
||||
XMLNode* node = 0;
|
||||
|
||||
p = _document->Identify( p, &node );
|
||||
p = _document->Identify( p, &node, first );
|
||||
TIXMLASSERT( p );
|
||||
if ( node == 0 ) {
|
||||
break;
|
||||
}
|
||||
first = false;
|
||||
|
||||
const int initialLineNum = node->_parseLineNum;
|
||||
|
||||
StrPair endTag;
|
||||
p = node->ParseDeep( p, &endTag, curLineNumPtr );
|
||||
if ( !p ) {
|
||||
DeleteNode( node );
|
||||
_document->DeleteNode( node );
|
||||
if ( !_document->Error() ) {
|
||||
_document->SetError( XML_ERROR_PARSING, initialLineNum, 0);
|
||||
}
|
||||
@@ -1110,7 +1154,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
|
||||
}
|
||||
if ( !wellLocated ) {
|
||||
_document->SetError( XML_ERROR_PARSING_DECLARATION, initialLineNum, "XMLDeclaration value=%s", decl->Value());
|
||||
DeleteNode( node );
|
||||
_document->DeleteNode( node );
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1145,7 +1189,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
|
||||
}
|
||||
if ( mismatch ) {
|
||||
_document->SetError( XML_ERROR_MISMATCHED_ELEMENT, initialLineNum, "XMLElement name=%s", ele->Name());
|
||||
DeleteNode( node );
|
||||
_document->DeleteNode( node );
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1777,11 +1821,11 @@ XMLError XMLElement::QueryInt64Text(int64_t* ival) const
|
||||
}
|
||||
|
||||
|
||||
XMLError XMLElement::QueryUnsigned64Text(uint64_t* ival) const
|
||||
XMLError XMLElement::QueryUnsigned64Text(uint64_t* uval) const
|
||||
{
|
||||
if(FirstChild() && FirstChild()->ToText()) {
|
||||
const char* t = FirstChild()->Value();
|
||||
if(XMLUtil::ToUnsigned64(t, ival)) {
|
||||
if(XMLUtil::ToUnsigned64(t, uval)) {
|
||||
return XML_SUCCESS;
|
||||
}
|
||||
return XML_CAN_NOT_CONVERT_TEXT;
|
||||
@@ -2413,21 +2457,21 @@ XMLError XMLDocument::SaveFile( FILE* fp, bool compact )
|
||||
}
|
||||
|
||||
|
||||
XMLError XMLDocument::Parse( const char* p, size_t len )
|
||||
XMLError XMLDocument::Parse( const char* xml, size_t nBytes )
|
||||
{
|
||||
Clear();
|
||||
|
||||
if ( len == 0 || !p || !*p ) {
|
||||
if ( nBytes == 0 || !xml || !*xml ) {
|
||||
SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );
|
||||
return _errorID;
|
||||
}
|
||||
if ( len == static_cast<size_t>(-1) ) {
|
||||
len = strlen( p );
|
||||
if ( nBytes == static_cast<size_t>(-1) ) {
|
||||
nBytes = strlen( xml );
|
||||
}
|
||||
TIXMLASSERT( _charBuffer == 0 );
|
||||
_charBuffer = new char[ len+1 ];
|
||||
memcpy( _charBuffer, p, len );
|
||||
_charBuffer[len] = 0;
|
||||
_charBuffer = new char[ nBytes+1 ];
|
||||
memcpy( _charBuffer, xml, nBytes );
|
||||
_charBuffer[nBytes] = 0;
|
||||
|
||||
Parse();
|
||||
if ( Error() ) {
|
||||
|
||||
121
tinyxml2.h
121
tinyxml2.h
@@ -64,7 +64,7 @@ distribution.
|
||||
# pragma warning(disable: 4251)
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef _MSC_VER
|
||||
# ifdef TINYXML2_EXPORT
|
||||
# define TINYXML2_LIB __declspec(dllexport)
|
||||
# elif defined(TINYXML2_IMPORT)
|
||||
@@ -112,7 +112,7 @@ static const int TIXML2_PATCH_VERSION = 0;
|
||||
// system, and the capacity of the stack. On the other hand, it's a trivial
|
||||
// attack that can result from ill, malicious, or even correctly formed XML,
|
||||
// so there needs to be a limit in place.
|
||||
static const int TINYXML2_MAX_ELEMENT_DEPTH = 100;
|
||||
static const int TINYXML2_MAX_ELEMENT_DEPTH = 500;
|
||||
|
||||
namespace tinyxml2
|
||||
{
|
||||
@@ -305,9 +305,9 @@ private:
|
||||
if ( cap > _allocated ) {
|
||||
TIXMLASSERT( cap <= INT_MAX / 2 );
|
||||
const int newAllocated = cap * 2;
|
||||
T* newMem = new T[newAllocated];
|
||||
T* newMem = new T[static_cast<unsigned int>(newAllocated)];
|
||||
TIXMLASSERT( newAllocated >= _size );
|
||||
memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs
|
||||
memcpy( newMem, _mem, sizeof(T)*static_cast<size_t>(_size) ); // warning: not using constructors, only works for PODs
|
||||
if ( _mem != _pool ) {
|
||||
delete [] _mem;
|
||||
}
|
||||
@@ -317,7 +317,7 @@ private:
|
||||
}
|
||||
|
||||
T* _mem;
|
||||
T _pool[INITIAL_SIZE];
|
||||
T _pool[static_cast<size_t>(INITIAL_SIZE)];
|
||||
int _allocated; // objects allocated
|
||||
int _size; // number objects in use
|
||||
};
|
||||
@@ -365,17 +365,17 @@ public:
|
||||
_nUntracked = 0;
|
||||
}
|
||||
|
||||
virtual int ItemSize() const {
|
||||
virtual int ItemSize() const override{
|
||||
return ITEM_SIZE;
|
||||
}
|
||||
int CurrentAllocs() const {
|
||||
return _currentAllocs;
|
||||
}
|
||||
|
||||
virtual void* Alloc() {
|
||||
virtual void* Alloc() override{
|
||||
if ( !_root ) {
|
||||
// Need a new block.
|
||||
Block* block = new Block();
|
||||
Block* block = new Block;
|
||||
_blockPtrs.Push( block );
|
||||
|
||||
Item* blockItems = block->items;
|
||||
@@ -398,7 +398,7 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual void Free( void* mem ) {
|
||||
virtual void Free( void* mem ) override {
|
||||
if ( !mem ) {
|
||||
return;
|
||||
}
|
||||
@@ -416,7 +416,7 @@ public:
|
||||
ITEM_SIZE, _nAllocs, _blockPtrs.Size() );
|
||||
}
|
||||
|
||||
void SetTracked() {
|
||||
void SetTracked() override {
|
||||
--_nUntracked;
|
||||
}
|
||||
|
||||
@@ -443,7 +443,7 @@ private:
|
||||
|
||||
union Item {
|
||||
Item* next;
|
||||
char itemData[ITEM_SIZE];
|
||||
char itemData[static_cast<size_t>(ITEM_SIZE)];
|
||||
};
|
||||
struct Block {
|
||||
Item items[ITEMS_PER_BLOCK];
|
||||
@@ -603,7 +603,7 @@ public:
|
||||
TIXMLASSERT( p );
|
||||
TIXMLASSERT( q );
|
||||
TIXMLASSERT( nChar >= 0 );
|
||||
return strncmp( p, q, nChar ) == 0;
|
||||
return strncmp( p, q, static_cast<size_t>(nChar) ) == 0;
|
||||
}
|
||||
|
||||
inline static bool IsUTF8Continuation( const char p ) {
|
||||
@@ -732,6 +732,12 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ChildElementCount was originally suggested by msteiger on the sourceforge page for TinyXML and modified by KB1SPH for TinyXML-2.
|
||||
|
||||
int ChildElementCount(const char *value) const;
|
||||
|
||||
int ChildElementCount() const;
|
||||
|
||||
/** The meaning of 'value' changes for the specific type.
|
||||
@verbatim
|
||||
Document: empty (NULL is returned, not an empty string)
|
||||
@@ -992,12 +998,12 @@ class TINYXML2_LIB XMLText : public XMLNode
|
||||
{
|
||||
friend class XMLDocument;
|
||||
public:
|
||||
virtual bool Accept( XMLVisitor* visitor ) const;
|
||||
virtual bool Accept( XMLVisitor* visitor ) const override;
|
||||
|
||||
virtual XMLText* ToText() {
|
||||
virtual XMLText* ToText() override {
|
||||
return this;
|
||||
}
|
||||
virtual const XMLText* ToText() const {
|
||||
virtual const XMLText* ToText() const override {
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1010,14 +1016,14 @@ public:
|
||||
return _isCData;
|
||||
}
|
||||
|
||||
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
|
||||
virtual bool ShallowEqual( const XMLNode* compare ) const;
|
||||
virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
|
||||
virtual bool ShallowEqual( const XMLNode* compare ) const override;
|
||||
|
||||
protected:
|
||||
explicit XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
|
||||
virtual ~XMLText() {}
|
||||
|
||||
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
|
||||
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override;
|
||||
|
||||
private:
|
||||
bool _isCData;
|
||||
@@ -1032,23 +1038,23 @@ class TINYXML2_LIB XMLComment : public XMLNode
|
||||
{
|
||||
friend class XMLDocument;
|
||||
public:
|
||||
virtual XMLComment* ToComment() {
|
||||
virtual XMLComment* ToComment() override {
|
||||
return this;
|
||||
}
|
||||
virtual const XMLComment* ToComment() const {
|
||||
virtual const XMLComment* ToComment() const override {
|
||||
return this;
|
||||
}
|
||||
|
||||
virtual bool Accept( XMLVisitor* visitor ) const;
|
||||
virtual bool Accept( XMLVisitor* visitor ) const override;
|
||||
|
||||
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
|
||||
virtual bool ShallowEqual( const XMLNode* compare ) const;
|
||||
virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
|
||||
virtual bool ShallowEqual( const XMLNode* compare ) const override;
|
||||
|
||||
protected:
|
||||
explicit XMLComment( XMLDocument* doc );
|
||||
virtual ~XMLComment();
|
||||
|
||||
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr);
|
||||
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr) override;
|
||||
|
||||
private:
|
||||
XMLComment( const XMLComment& ); // not supported
|
||||
@@ -1071,23 +1077,23 @@ class TINYXML2_LIB XMLDeclaration : public XMLNode
|
||||
{
|
||||
friend class XMLDocument;
|
||||
public:
|
||||
virtual XMLDeclaration* ToDeclaration() {
|
||||
virtual XMLDeclaration* ToDeclaration() override {
|
||||
return this;
|
||||
}
|
||||
virtual const XMLDeclaration* ToDeclaration() const {
|
||||
virtual const XMLDeclaration* ToDeclaration() const override {
|
||||
return this;
|
||||
}
|
||||
|
||||
virtual bool Accept( XMLVisitor* visitor ) const;
|
||||
virtual bool Accept( XMLVisitor* visitor ) const override;
|
||||
|
||||
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
|
||||
virtual bool ShallowEqual( const XMLNode* compare ) const;
|
||||
virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
|
||||
virtual bool ShallowEqual( const XMLNode* compare ) const override;
|
||||
|
||||
protected:
|
||||
explicit XMLDeclaration( XMLDocument* doc );
|
||||
virtual ~XMLDeclaration();
|
||||
|
||||
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
|
||||
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override;
|
||||
|
||||
private:
|
||||
XMLDeclaration( const XMLDeclaration& ); // not supported
|
||||
@@ -1106,23 +1112,23 @@ class TINYXML2_LIB XMLUnknown : public XMLNode
|
||||
{
|
||||
friend class XMLDocument;
|
||||
public:
|
||||
virtual XMLUnknown* ToUnknown() {
|
||||
virtual XMLUnknown* ToUnknown() override {
|
||||
return this;
|
||||
}
|
||||
virtual const XMLUnknown* ToUnknown() const {
|
||||
virtual const XMLUnknown* ToUnknown() const override {
|
||||
return this;
|
||||
}
|
||||
|
||||
virtual bool Accept( XMLVisitor* visitor ) const;
|
||||
virtual bool Accept( XMLVisitor* visitor ) const override;
|
||||
|
||||
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
|
||||
virtual bool ShallowEqual( const XMLNode* compare ) const;
|
||||
virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
|
||||
virtual bool ShallowEqual( const XMLNode* compare ) const override;
|
||||
|
||||
protected:
|
||||
explicit XMLUnknown( XMLDocument* doc );
|
||||
virtual ~XMLUnknown();
|
||||
|
||||
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
|
||||
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override;
|
||||
|
||||
private:
|
||||
XMLUnknown( const XMLUnknown& ); // not supported
|
||||
@@ -1274,13 +1280,13 @@ public:
|
||||
SetValue( str, staticMem );
|
||||
}
|
||||
|
||||
virtual XMLElement* ToElement() {
|
||||
virtual XMLElement* ToElement() override {
|
||||
return this;
|
||||
}
|
||||
virtual const XMLElement* ToElement() const {
|
||||
virtual const XMLElement* ToElement() const override {
|
||||
return this;
|
||||
}
|
||||
virtual bool Accept( XMLVisitor* visitor ) const;
|
||||
virtual bool Accept( XMLVisitor* visitor ) const override;
|
||||
|
||||
/** Given an attribute name, Attribute() returns the value
|
||||
for the attribute of that name, or null if none
|
||||
@@ -1676,11 +1682,11 @@ public:
|
||||
ElementClosingType ClosingType() const {
|
||||
return _closingType;
|
||||
}
|
||||
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
|
||||
virtual bool ShallowEqual( const XMLNode* compare ) const;
|
||||
virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
|
||||
virtual bool ShallowEqual( const XMLNode* compare ) const override;
|
||||
|
||||
protected:
|
||||
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
|
||||
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override;
|
||||
|
||||
private:
|
||||
XMLElement( XMLDocument* doc );
|
||||
@@ -1704,7 +1710,8 @@ private:
|
||||
|
||||
enum Whitespace {
|
||||
PRESERVE_WHITESPACE,
|
||||
COLLAPSE_WHITESPACE
|
||||
COLLAPSE_WHITESPACE,
|
||||
PEDANTIC_WHITESPACE
|
||||
};
|
||||
|
||||
|
||||
@@ -1728,11 +1735,11 @@ public:
|
||||
XMLDocument( bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE );
|
||||
~XMLDocument();
|
||||
|
||||
virtual XMLDocument* ToDocument() {
|
||||
virtual XMLDocument* ToDocument() override {
|
||||
TIXMLASSERT( this == _document );
|
||||
return this;
|
||||
}
|
||||
virtual const XMLDocument* ToDocument() const {
|
||||
virtual const XMLDocument* ToDocument() const override {
|
||||
TIXMLASSERT( this == _document );
|
||||
return this;
|
||||
}
|
||||
@@ -1829,7 +1836,7 @@ public:
|
||||
@endverbatim
|
||||
*/
|
||||
void Print( XMLPrinter* streamer=0 ) const;
|
||||
virtual bool Accept( XMLVisitor* visitor ) const;
|
||||
virtual bool Accept( XMLVisitor* visitor ) const override;
|
||||
|
||||
/**
|
||||
Create a new Element associated with
|
||||
@@ -1915,15 +1922,15 @@ public:
|
||||
void DeepCopy(XMLDocument* target) const;
|
||||
|
||||
// internal
|
||||
char* Identify( char* p, XMLNode** node );
|
||||
char* Identify( char* p, XMLNode** node, bool first );
|
||||
|
||||
// internal
|
||||
void MarkInUse(const XMLNode* const);
|
||||
|
||||
virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const {
|
||||
virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const override{
|
||||
return 0;
|
||||
}
|
||||
virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const {
|
||||
virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const override{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2286,18 +2293,18 @@ public:
|
||||
void PushDeclaration( const char* value );
|
||||
void PushUnknown( const char* value );
|
||||
|
||||
virtual bool VisitEnter( const XMLDocument& /*doc*/ );
|
||||
virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
|
||||
virtual bool VisitEnter( const XMLDocument& /*doc*/ ) override;
|
||||
virtual bool VisitExit( const XMLDocument& /*doc*/ ) override {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute );
|
||||
virtual bool VisitExit( const XMLElement& element );
|
||||
virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute ) override;
|
||||
virtual bool VisitExit( const XMLElement& element ) override;
|
||||
|
||||
virtual bool Visit( const XMLText& text );
|
||||
virtual bool Visit( const XMLComment& comment );
|
||||
virtual bool Visit( const XMLDeclaration& declaration );
|
||||
virtual bool Visit( const XMLUnknown& unknown );
|
||||
virtual bool Visit( const XMLText& text ) override;
|
||||
virtual bool Visit( const XMLComment& comment ) override;
|
||||
virtual bool Visit( const XMLDeclaration& declaration ) override;
|
||||
virtual bool Visit( const XMLUnknown& unknown ) override;
|
||||
|
||||
/**
|
||||
If in print to memory mode, return a pointer to
|
||||
|
||||
@@ -29,26 +29,26 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
|
||||
178
xmltest.cpp
178
xmltest.cpp
@@ -1869,6 +1869,178 @@ int main( int argc, const char ** argv )
|
||||
XMLTest( "Whitespace all space", true, 0 == doc.FirstChildElement()->FirstChild() );
|
||||
}
|
||||
|
||||
// ----------- Preserve Whitespace ------------
|
||||
{
|
||||
const char* xml = "<element>This is ' \n\n text '</element>";
|
||||
XMLDocument doc(true, PRESERVE_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse with whitespace preserved", false, doc.Error());
|
||||
XMLTest("Whitespace preserved", "This is ' \n\n text '", doc.FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
{
|
||||
const char* xml = "<element> This \nis ' text ' </element>";
|
||||
XMLDocument doc(true, PRESERVE_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse with whitespace preserved", false, doc.Error());
|
||||
XMLTest("Whitespace preserved", " This \nis ' text ' ", doc.FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
{
|
||||
const char* xml = "<element> \n This is ' text ' \n</element>";
|
||||
XMLDocument doc(true, PRESERVE_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse with whitespace preserved", false, doc.Error());
|
||||
XMLTest("Whitespace preserved", " \n This is ' text ' \n", doc.FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
// Following cases are for text that is all whitespace which are not preserved intentionally
|
||||
{
|
||||
const char* xml = "<element> </element>";
|
||||
XMLDocument doc(true, PRESERVE_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse with whitespace preserved", false, doc.Error());
|
||||
XMLTest("Whitespace preserved", true, 0 == doc.FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
{
|
||||
const char* xml = "<element> </element>";
|
||||
XMLDocument doc(true, PRESERVE_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse with whitespace preserved", false, doc.Error());
|
||||
XMLTest("Whitespace preserved", true, 0 == doc.FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
{
|
||||
const char* xml = "<element>\n\n</element>";
|
||||
XMLDocument doc(true, PRESERVE_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse with whitespace preserved", false, doc.Error());
|
||||
XMLTest("Whitespace preserved", true, 0 == doc.FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
{
|
||||
const char* xml = "<element> \n</element>";
|
||||
XMLDocument doc(true, PRESERVE_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse with whitespace preserved", false, doc.Error());
|
||||
XMLTest("Whitespace preserved", true, 0 == doc.FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
{
|
||||
const char* xml = "<element> \n \n </element>";
|
||||
XMLDocument doc(true, PRESERVE_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse with whitespace preserved", false, doc.Error());
|
||||
XMLTest("Whitespace preserved", true, 0 == doc.FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
// ----------- Pedantic Whitespace ------------
|
||||
{
|
||||
const char* xml = "<element>This is ' \n\n text '</element>";
|
||||
XMLDocument doc(true, PEDANTIC_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse with pedantic whitespace", false, doc.Error());
|
||||
XMLTest("Pedantic whitespace", "This is ' \n\n text '", doc.FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
{
|
||||
const char* xml = "<element> This \nis ' text ' </element>";
|
||||
XMLDocument doc(true, PEDANTIC_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse with pedantic whitespace", false, doc.Error());
|
||||
XMLTest("Pedantic whitespace", " This \nis ' text ' ", doc.FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
{
|
||||
const char* xml = "<element> \n This is ' text ' \n</element>";
|
||||
XMLDocument doc(true, PEDANTIC_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse with pedantic whitespace", false, doc.Error());
|
||||
XMLTest("Pedantic whitespace", " \n This is ' text ' \n", doc.FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
// Following cases are for text that is all whitespace which is preserved with pedantic mode
|
||||
{
|
||||
const char* xml = "<element> </element>";
|
||||
XMLDocument doc(true, PEDANTIC_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse with pedantic whitespace", false, doc.Error());
|
||||
XMLTest("Pedantic whitespace", " ", doc.FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
{
|
||||
const char* xml = "<element> </element>";
|
||||
XMLDocument doc(true, PEDANTIC_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse with pedantic whitespace", false, doc.Error());
|
||||
XMLTest("Pedantic whitespace", " ", doc.FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
{
|
||||
const char* xml = "<element>\n\n</element>\n";
|
||||
XMLDocument doc(true, PEDANTIC_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse with pedantic whitespace", false, doc.Error());
|
||||
XMLTest("Pedantic whitespace", "\n\n", doc.FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
{
|
||||
const char* xml = "<element> \n</element> \n ";
|
||||
XMLDocument doc(true, PEDANTIC_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse with pedantic whitespace", false, doc.Error());
|
||||
XMLTest("Pedantic whitespace", " \n", doc.FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
{
|
||||
const char* xml = "<element> \n \n </element> ";
|
||||
XMLDocument doc(true, PEDANTIC_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse with pedantic whitespace", false, doc.Error());
|
||||
XMLTest("Pedantic whitespace", " \n \n ", doc.FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
// Following cases are for checking nested elements are still parsed with pedantic whitespace
|
||||
{
|
||||
const char* xml = "<element>\n\t<a> This is nested text </a>\n</element> ";
|
||||
XMLDocument doc(true, PEDANTIC_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse nested elements with pedantic whitespace", false, doc.Error());
|
||||
XMLTest("Pedantic whitespace", " This is nested text ", doc.RootElement()->FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
{
|
||||
const char* xml = "<element> <b> </b> </element>\n";
|
||||
XMLDocument doc(true, PEDANTIC_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse nested elements with pedantic whitespace", false, doc.Error());
|
||||
XMLTest("Pedantic whitespace", " ", doc.RootElement()->FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
{
|
||||
const char* xml = "<element> <c attribute=\"test\"/> </element>\n ";
|
||||
XMLDocument doc(true, PEDANTIC_WHITESPACE);
|
||||
doc.Parse(xml);
|
||||
XMLTest("Parse nested elements with pedantic whitespace", false, doc.Error());
|
||||
XMLTest("Pedantic whitespace", true, 0 == doc.RootElement()->FirstChildElement()->GetText());
|
||||
}
|
||||
|
||||
// Check sample xml can be parsed with pedantic mode
|
||||
{
|
||||
XMLDocument doc(true, PEDANTIC_WHITESPACE);
|
||||
doc.LoadFile("resources/dream.xml");
|
||||
XMLTest("Load dream.xml with pedantic whitespace mode", false, doc.Error());
|
||||
|
||||
XMLTest("Dream", "xml version=\"1.0\"",
|
||||
doc.FirstChild()->ToDeclaration()->Value());
|
||||
XMLTest("Dream", true, doc.FirstChild()->NextSibling()->ToUnknown() != 0);
|
||||
XMLTest("Dream", "DOCTYPE PLAY SYSTEM \"play.dtd\"",
|
||||
doc.FirstChild()->NextSibling()->ToUnknown()->Value());
|
||||
XMLTest("Dream", "And Robin shall restore amends.",
|
||||
doc.LastChild()->LastChild()->LastChild()->LastChild()->LastChildElement()->GetText());
|
||||
}
|
||||
|
||||
{
|
||||
// An assert should not fire.
|
||||
const char* xml = "<element/>";
|
||||
@@ -2152,6 +2324,12 @@ int main( int argc, const char ** argv )
|
||||
|
||||
doc.LoadFile("resources/dream.xml");
|
||||
XMLTest("Error should be cleared", false, doc.Error());
|
||||
|
||||
doc.LoadFile( "resources/xmltest-5330.xml" );
|
||||
XMLTest( "parse errors occur - should fail", true, doc.Error() );
|
||||
|
||||
doc.LoadFile( "resources/dream.xml" );
|
||||
XMLTest( "Error should be cleared", false, doc.Error() );
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user