Further to the previous fix, don't clear the content buffer afetr an open/close tag

callback -- clear it before. This stops included content from being lost.
This commit is contained in:
Laurence Withers 2006-10-04 10:47:19 +01:00
parent a24d2caad2
commit 9a33766c62
2 changed files with 12 additions and 13 deletions

View File

@ -110,7 +110,7 @@ int csxml_feedChar(struct csxml* ctx, char ch)
int try; int try;
#ifdef DEBUG_STATE_MACHINE #ifdef DEBUG_STATE_MACHINE
printf("Character '%c' (%02X), state %d\n", ch, ch, ctx->state); printf("%p: Character '%c' (%02X), state %d, buffer %s\n", ctx, ch, ch, ctx->state, ctx->buffer.data);
#endif #endif
#define ERROR(_reason) do { \ #define ERROR(_reason) do { \
@ -398,11 +398,11 @@ int csxml_feedChar(struct csxml* ctx, char ch)
default: default:
switch(ch) { switch(ch) {
case L'>': case L'>':
CLEAR_BUFFER(buffer);
TRY(list_push(ctx, &ctx->elemStack, &ctx->elemName)); TRY(list_push(ctx, &ctx->elemStack, &ctx->elemName));
ctx->state = StateNone; ctx->state = StateNone;
TRY(ctx->element(ctx, ctx->elemName.data, 0)); TRY(ctx->element(ctx, ctx->elemName.data, 0));
++ctx->elementDepth; ++ctx->elementDepth;
CLEAR_BUFFER(buffer);
break; break;
case L'/': case L'/':
@ -489,9 +489,9 @@ int csxml_feedChar(struct csxml* ctx, char ch)
ctx->state = StateNeedClose; ctx->state = StateNeedClose;
} else if(ch == '>') { } else if(ch == '>') {
ctx->state = StateNone; ctx->state = StateNone;
CLEAR_BUFFER(buffer);
TRY(ctx->element(ctx, ctx->elemName.data, ctx->elemAttrVals.len)); TRY(ctx->element(ctx, ctx->elemName.data, ctx->elemAttrVals.len));
TRY(list_push(ctx, &ctx->elemStack, &ctx->elemName)); TRY(list_push(ctx, &ctx->elemStack, &ctx->elemName));
CLEAR_BUFFER(buffer);
++ctx->elementDepth; ++ctx->elementDepth;
} else ERROR("Invalid character after attribute."); } else ERROR("Invalid character after attribute.");
break; break;
@ -501,9 +501,9 @@ int csxml_feedChar(struct csxml* ctx, char ch)
case StateNeedClose: case StateNeedClose:
if(ch != '>') ERROR("Stray `/' in open tag."); if(ch != '>') ERROR("Stray `/' in open tag.");
ctx->state = StateNone; ctx->state = StateNone;
CLEAR_BUFFER(buffer);
TRY(ctx->element(ctx, ctx->elemName.data, ctx->elemAttrVals.len)); TRY(ctx->element(ctx, ctx->elemName.data, ctx->elemAttrVals.len));
TRY(ctx->closeTag(ctx, ctx->elemName.data)); TRY(ctx->closeTag(ctx, ctx->elemName.data));
CLEAR_BUFFER(buffer);
break; break;
case StateClose: case StateClose:
@ -528,10 +528,9 @@ int csxml_feedChar(struct csxml* ctx, char ch)
TRY(buffer_copy(ctx, &ctx->elemName, list_pop(&ctx->elemStack))); TRY(buffer_copy(ctx, &ctx->elemName, list_pop(&ctx->elemStack)));
if(strcmp(ctx->elemName.data, ctx->buffer.data)) ERROR("Mismatched close tag."); if(strcmp(ctx->elemName.data, ctx->buffer.data)) ERROR("Mismatched close tag.");
ctx->state = StateNone; ctx->state = StateNone;
CLEAR_BUFFER(buffer);
TRY(ctx->closeTag(ctx, ctx->elemName.data)); TRY(ctx->closeTag(ctx, ctx->elemName.data));
--ctx->elementDepth; --ctx->elementDepth;
CLEAR_BUFFER(buffer);
} }
break; break;
@ -541,9 +540,9 @@ int csxml_feedChar(struct csxml* ctx, char ch)
TRY(buffer_copy(ctx, &ctx->elemName, list_pop(&ctx->elemStack))); TRY(buffer_copy(ctx, &ctx->elemName, list_pop(&ctx->elemStack)));
if(strcmp(ctx->elemName.data, ctx->buffer.data)) ERROR("Mismatched close tag."); if(strcmp(ctx->elemName.data, ctx->buffer.data)) ERROR("Mismatched close tag.");
ctx->state = StateNone; ctx->state = StateNone;
CLEAR_BUFFER(buffer);
TRY(ctx->closeTag(ctx, ctx->elemName.data)); TRY(ctx->closeTag(ctx, ctx->elemName.data));
--ctx->elementDepth; --ctx->elementDepth;
CLEAR_BUFFER(buffer);
break; break;
case StateEntity: case StateEntity:

View File

@ -383,9 +383,9 @@ doBuffer:
case L'>': case L'>':
elemStack.push_back(buffer); elemStack.push_back(buffer);
state = StateNone; state = StateNone;
buffer.clear();
callback->element(buffer, elemAttrs); callback->element(buffer, elemAttrs);
++elementDepth; ++elementDepth;
buffer.clear();
break; break;
case L'/': case L'/':
@ -413,8 +413,8 @@ doBuffer:
case L'>': case L'>':
elemStack.push_back(elemName); elemStack.push_back(elemName);
state = StateNone; state = StateNone;
callback->element(elemName, elemAttrs);
buffer.clear(); buffer.clear();
callback->element(elemName, elemAttrs);
++elementDepth; ++elementDepth;
break; break;
@ -475,9 +475,9 @@ doBuffer:
state = StateNeedClose; state = StateNeedClose;
} else if(ch == L'>') { } else if(ch == L'>') {
state = StateNone; state = StateNone;
buffer.clear();
callback->element(elemName, elemAttrs); callback->element(elemName, elemAttrs);
elemStack.push_back(elemName); elemStack.push_back(elemName);
buffer.clear();
++elementDepth; ++elementDepth;
} else ERROR(L"Invalid character after attribute."); } else ERROR(L"Invalid character after attribute.");
break; break;
@ -487,9 +487,9 @@ doBuffer:
case StateNeedClose: case StateNeedClose:
if(ch != L'>') ERROR(L"Stray `/' in open tag."); if(ch != L'>') ERROR(L"Stray `/' in open tag.");
state = StateNone; state = StateNone;
buffer.clear();
callback->element(elemName, elemAttrs); callback->element(elemName, elemAttrs);
callback->closeTag(elemName); callback->closeTag(elemName);
buffer.clear();
break; break;
case StateClose: case StateClose:
@ -514,8 +514,8 @@ doBuffer:
if(elemStack.back() != buffer) ERROR(L"Mismatched close tag."); if(elemStack.back() != buffer) ERROR(L"Mismatched close tag.");
elemStack.pop_back(); elemStack.pop_back();
state = StateNone; state = StateNone;
callback->closeTag(buffer);
buffer.clear(); buffer.clear();
callback->closeTag(buffer);
--elementDepth; --elementDepth;
} }
break; break;
@ -526,8 +526,8 @@ doBuffer:
if(elemStack.back() != elemName) ERROR(L"Mismatched close tag."); if(elemStack.back() != elemName) ERROR(L"Mismatched close tag.");
elemStack.pop_back(); elemStack.pop_back();
state = StateNone; state = StateNone;
callback->closeTag(elemName);
buffer.clear(); buffer.clear();
callback->closeTag(elemName);
--elementDepth; --elementDepth;
break; break;