iterate on parsing.

This commit is contained in:
Lee Thomason 2012-01-23 11:42:06 -08:00
parent d923c670fc
commit ec975cede8
3 changed files with 19 additions and 10 deletions

View File

@ -67,6 +67,7 @@ const char* StrPair::GetStr()
else { else {
*q = *p; *q = *p;
++p; ++p;
++q;
} }
} }
} }
@ -89,8 +90,9 @@ char* XMLBase::ParseText( char* p, StrPair* pair, const char* endTag )
while ( *p ) { while ( *p ) {
if ( *p == endChar && strncmp( p, endTag, length ) == 0 ) { if ( *p == endChar && strncmp( p, endTag, length ) == 0 ) {
pair->Set( start, p, StrPair::NEEDS_ENTITY_PROCESSING | StrPair::NEEDS_NEWLINE_NORMALIZATION ); pair->Set( start, p, StrPair::NEEDS_ENTITY_PROCESSING | StrPair::NEEDS_NEWLINE_NORMALIZATION );
break; return p + length;
} }
++p;
} }
return p; return p;
} }
@ -99,7 +101,6 @@ char* XMLBase::ParseText( char* p, StrPair* pair, const char* endTag )
char* XMLBase::ParseName( char* p, StrPair* pair ) char* XMLBase::ParseName( char* p, StrPair* pair )
{ {
char* start = p; char* start = p;
char* nextTag = 0;
start = p; start = p;
if ( !start || !(*start) ) { if ( !start || !(*start) ) {
@ -273,7 +274,7 @@ XMLComment::~XMLComment()
void XMLComment::Print( FILE* fp, int depth ) void XMLComment::Print( FILE* fp, int depth )
{ {
XMLNode::Print( fp, depth ); XMLNode::Print( fp, depth );
fprintf( fp, "<!--%s-->\n", value ); fprintf( fp, "<!--%s-->\n", value.GetStr() );
} }
@ -425,11 +426,11 @@ void XMLElement::Print( FILE* cfile, int depth )
} }
if ( firstChild ) { if ( firstChild ) {
fprintf( cfile, ">/n" ); fprintf( cfile, ">\n" );
for( XMLNode* node=firstChild; node; node=node->next ) { for( XMLNode* node=firstChild; node; node=node->next ) {
node->Print( cfile, depth+1 ); node->Print( cfile, depth+1 );
} }
fprintf( cfile, "</%s>", Name() ); fprintf( cfile, "</%s>\n", Name() );
} }
else { else {
fprintf( cfile, "/>\n" ); fprintf( cfile, "/>\n" );
@ -459,10 +460,13 @@ bool XMLDocument::Parse( const char* p )
XMLNode* node = 0; XMLNode* node = 0;
char* q = Identify( this, charBuffer->mem, &node ); char* q = Identify( this, charBuffer->mem, &node );
if ( node ) { while ( node ) {
root->InsertEndChild( node ); root->InsertEndChild( node );
node->ParseDeep( q ); q = node->ParseDeep( q );
return true; node = 0;
if ( q && *q ) {
q = Identify( this, q, &node );
}
} }
return false; return false;
} }

Binary file not shown.

View File

@ -28,15 +28,20 @@ int main( int argc, const char* argv )
} }
#endif #endif
{ {
static const char* test[] = { //"<element />", static const char* test[] = { "<!--single element-->",
// "<element></element>", "<element />",
"<element></element>",
"<!--single sub-element-->",
"<element><subelement/></element>", "<element><subelement/></element>",
"<element><subelement></subelement></element>",
"<!--comment beside elements--><element><subelement></subelement></element>",
0 0
}; };
for( int i=0; test[i]; ++i ) { for( int i=0; test[i]; ++i ) {
XMLDocument doc; XMLDocument doc;
doc.Parse( test[i] ); doc.Parse( test[i] );
doc.Print( stdout ); doc.Print( stdout );
printf( "----------------------------------------------\n" );
} }
} }
return 0; return 0;