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

View File

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