diff options
-rw-r--r-- | xml.c | 39 |
1 files changed, 22 insertions, 17 deletions
@@ -107,36 +107,41 @@ xml_parseattrs(XMLParser *x) static void xml_parsecomment(XMLParser *x) { - static const char *end = "-->"; size_t datalen = 0, i = 0; - char tmp[4]; int c; if (x->xmlcommentstart) x->xmlcommentstart(x); while ((c = x->getnext()) != EOF) { - if (c == end[i]) { - if (end[++i] == '\0') { /* end */ + if (c == '-' || c == '>') { + if (x->xmlcomment) { x->data[datalen] = '\0'; + x->xmlcomment(x, x->data, datalen); + datalen = 0; + } + } + + if (c == '-') { + if (++i > 2) { if (x->xmlcomment) - x->xmlcomment(x, x->data, datalen); - if (x->xmlcommentend) - x->xmlcommentend(x); - return; + for (; i > 2; i--) + x->xmlcomment(x, "-", 1); + i = 2; } + continue; + } else if (c == '>' && i == 2) { + if (x->xmlcommentend) + x->xmlcommentend(x); + return; } else if (i) { if (x->xmlcomment) { - x->data[datalen] = '\0'; - if (datalen) - x->xmlcomment(x, x->data, datalen); - memcpy(tmp, end, i); - tmp[i] = '\0'; - x->xmlcomment(x, tmp, i); + for (; i > 0; i--) + x->xmlcomment(x, "-", 1); } i = 0; - x->data[0] = c; - datalen = 1; - } else if (datalen < sizeof(x->data) - 1) { + } + + if (datalen < sizeof(x->data) - 1) { x->data[datalen++] = c; } else { x->data[datalen] = '\0'; |