mirror of
https://github.com/AxioDL/tinyxml2.git
synced 2025-06-22 06:23:35 +00:00
basic structure in place.
This commit is contained in:
parent
560bd47842
commit
4cee61104d
38
tinyxml2.cpp
38
tinyxml2.cpp
@ -3,6 +3,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
using namespace tinyxml2;
|
using namespace tinyxml2;
|
||||||
|
|
||||||
@ -23,14 +24,49 @@ using namespace tinyxml2;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char* XMLNode::SkipWhiteSpace( const char* p )
|
||||||
|
{
|
||||||
|
while( isspace( *p ) ) {
|
||||||
|
++p;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
XMLDocument::XMLDocument() :
|
XMLDocument::XMLDocument() :
|
||||||
charBuffer( 0 )
|
charBuffer( 0 )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool XMLDocument::Parse( const char* str )
|
bool XMLDocument::Parse( const char* p )
|
||||||
{
|
{
|
||||||
|
XMLNode* returnNode = 0;
|
||||||
|
|
||||||
|
p = XMLNode::SkipWhiteSpace( p );
|
||||||
|
if( !p || !*p || *p != '<' )
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// What is this thing?
|
||||||
|
// - Elements start with a letter or underscore, but xml is reserved.
|
||||||
|
// - Comments: <!--
|
||||||
|
// - Decleration: <?xml
|
||||||
|
// - Everthing else is unknown to tinyxml.
|
||||||
|
//
|
||||||
|
|
||||||
|
const char* xmlHeader = { "<?xml" };
|
||||||
|
const char* commentHeader = { "<!--" };
|
||||||
|
const char* dtdHeader = { "<!" };
|
||||||
|
const char* cdataHeader = { "<![CDATA[" };
|
||||||
|
|
||||||
|
if ( XMLNode::StringEqual( p, xmlHeader, 5 ) ) {
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
TIXMLASSERT( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
62
tinyxml2.h
62
tinyxml2.h
@ -1,12 +1,33 @@
|
|||||||
#ifndef TINYXML2_INCLUDED
|
#ifndef TINYXML2_INCLUDED
|
||||||
#define TINYXML2_INCLUDED
|
#define TINYXML2_INCLUDED
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
#if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
|
||||||
|
#ifndef DEBUG
|
||||||
|
#define DEBUG
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(DEBUG)
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#define TIXMLASSERT( x ) if ( !(x)) { _asm { int 3 } } //if ( !(x)) WinDebugBreak()
|
||||||
|
#elif defined (ANDROID_NDK)
|
||||||
|
#include <android/log.h>
|
||||||
|
#define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
|
||||||
|
#else
|
||||||
|
#include <assert.h>
|
||||||
|
#define TIXMLASSERT assert
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define TIXMLASSERT( x ) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace tinyxml2
|
namespace tinyxml2
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// internal - move to separate namespace
|
// internal - move to separate namespace
|
||||||
struct CharBuffer
|
struct CharBuffer
|
||||||
{
|
{
|
||||||
@ -18,14 +39,37 @@ struct CharBuffer
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
class XMLNode
|
||||||
class Element
|
|
||||||
{
|
{
|
||||||
|
friend class XMLDocument;
|
||||||
public:
|
public:
|
||||||
Element
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
static XMLNode* Identify( const char* p );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static const char* SkipWhiteSpace( const char* p );
|
||||||
|
static char* SkipWhiteSpace( char* p ) { return (char*) SkipWhiteSpace( (const char*)p ); }
|
||||||
|
|
||||||
|
inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
|
||||||
|
int n = 0;
|
||||||
|
while( *p && *q && *p == *q && n<nChar ) {
|
||||||
|
++p; ++q; ++n;
|
||||||
|
}
|
||||||
|
if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class XMLComment : public XMLNode
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class XMLDocument
|
class XMLDocument
|
||||||
@ -37,11 +81,15 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
XMLDocument( const XMLDocument& ); // not implemented
|
XMLDocument( const XMLDocument& ); // not implemented
|
||||||
|
|
||||||
CharBuffer* charBuffer;
|
CharBuffer* charBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}; // tinyxml2
|
}; // tinyxml2
|
||||||
|
|
||||||
|
|
||||||
|
BIN
tinyxml2.suo
BIN
tinyxml2.suo
Binary file not shown.
18
xmltest.cpp
18
xmltest.cpp
@ -7,11 +7,21 @@ using namespace tinyxml2;
|
|||||||
|
|
||||||
int main( int argc, const char* argv )
|
int main( int argc, const char* argv )
|
||||||
{
|
{
|
||||||
static const char* test = "<hello></hello>";
|
{
|
||||||
|
static const char* test = "<!--hello world-->";
|
||||||
|
|
||||||
XMLDocument doc;
|
XMLDocument doc;
|
||||||
doc.Parse( test );
|
doc.Parse( test );
|
||||||
doc.Print( stdout );
|
doc.Print( stdout );
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
static const char* test = "<hello></hello>";
|
||||||
|
|
||||||
|
XMLDocument doc;
|
||||||
|
doc.Parse( test );
|
||||||
|
doc.Print( stdout );
|
||||||
|
}
|
||||||
|
*/
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user