summaryrefslogtreecommitdiff
path: root/xml.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2020-09-30 11:42:07 +0100
committerKatolaZ <katolaz@freaknet.org>2020-09-30 11:42:07 +0100
commit60c249ec24ab865c4a55759c7ffde2da99530b1d (patch)
tree38494b9c66d9e915a6de57e89f3720627aaa1f6a /xml.c
parentb416c171bb34297d7f8bc4c027de7136a113d144 (diff)
several improvements and more efficient xml parser
Diffstat (limited to 'xml.c')
-rw-r--r--xml.c36
1 files changed, 3 insertions, 33 deletions
diff --git a/xml.c b/xml.c
index e6c27d7..67ad5a8 100644
--- a/xml.c
+++ b/xml.c
@@ -116,49 +116,19 @@ startvalue:
static void
xml_parsecomment(XMLParser *x)
{
- size_t datalen = 0, i = 0;
+ size_t i = 0;
int c;
- if (x->xmlcommentstart)
- x->xmlcommentstart(x);
while ((c = GETNEXT()) != EOF) {
- if (c == '-' || c == '>') {
- if (x->xmlcomment && datalen) {
- x->data[datalen] = '\0';
- x->xmlcomment(x, x->data, datalen);
- datalen = 0;
- }
- }
-
if (c == '-') {
- if (++i > 2) {
- if (x->xmlcomment)
- for (; i > 2; i--)
- x->xmlcomment(x, "-", 1);
+ if (++i > 2)
i = 2;
- }
continue;
} else if (c == '>' && i == 2) {
- if (x->xmlcommentend)
- x->xmlcommentend(x);
return;
} else if (i) {
- if (x->xmlcomment) {
- for (; i > 0; i--)
- x->xmlcomment(x, "-", 1);
- }
i = 0;
}
-
- if (datalen < sizeof(x->data) - 1) {
- x->data[datalen++] = c;
- } else {
- x->data[datalen] = '\0';
- if (x->xmlcomment)
- x->xmlcomment(x, x->data, datalen);
- x->data[0] = c;
- datalen = 1;
- }
}
}
@@ -286,7 +256,7 @@ numericentitytostr(const char *e, char *buf, size_t bufsiz)
l = strtol(++e, &end, 16);
else
l = strtol(e, &end, 10);
- /* invalid value or not a well-formed entity or invalid codepoint */
+ /* invalid value or not a well-formed entity or invalid code point */
if (errno || e == end || *end != ';' || l < 0 || l > 0x10ffff)
return -1;
len = codepointtoutf8(l, buf);