summaryrefslogtreecommitdiff
path: root/xml.c
diff options
context:
space:
mode:
Diffstat (limited to 'xml.c')
-rw-r--r--xml.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/xml.c b/xml.c
index f16cbbb..35b7961 100644
--- a/xml.c
+++ b/xml.c
@@ -1,4 +1,3 @@
-#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -6,6 +5,9 @@
#include "xml.h"
+#define ISALPHA(c) ((((unsigned)c) | 32) - 'a' < 26)
+#define ISSPACE(c) ((c) == ' ' || ((((unsigned)c) - '\t') < 5))
+
static void
xml_parseattrs(XMLParser *x)
{
@@ -13,7 +15,7 @@ xml_parseattrs(XMLParser *x)
int c, endsep, endname = 0, valuestart = 0;
while ((c = GETNEXT()) != EOF) {
- if (isspace(c)) {
+ if (ISSPACE(c)) {
if (namelen)
endname = 1;
continue;
@@ -23,7 +25,7 @@ xml_parseattrs(XMLParser *x)
x->name[namelen] = '\0';
valuestart = 1;
endname = 1;
- } else if (namelen && ((endname && !valuestart && isalpha(c)) || (c == '>' || c == '/'))) {
+ } else if (namelen && ((endname && !valuestart && ISALPHA(c)) || (c == '>' || c == '/'))) {
/* attribute without value */
x->name[namelen] = '\0';
if (x->xmlattrstart)
@@ -44,7 +46,7 @@ xml_parseattrs(XMLParser *x)
if (c == '\'' || c == '"') {
endsep = c;
} else {
- endsep = ' '; /* isspace() */
+ endsep = ' '; /* ISSPACE() */
goto startvalue;
}
@@ -58,7 +60,7 @@ startvalue:
x->data[0] = c;
valuelen = 1;
while ((c = GETNEXT()) != EOF) {
- if (c == endsep || (endsep == ' ' && (c == '>' || isspace(c))))
+ if (c == endsep || (endsep == ' ' && (c == '>' || ISSPACE(c))))
break;
if (valuelen < sizeof(x->data) - 1)
x->data[valuelen++] = c;
@@ -79,7 +81,7 @@ startvalue:
break;
}
}
- } else if (c != endsep && !(endsep == ' ' && (c == '>' || isspace(c)))) {
+ } else if (c != endsep && !(endsep == ' ' && (c == '>' || ISSPACE(c)))) {
if (valuelen < sizeof(x->data) - 1) {
x->data[valuelen++] = c;
} else {
@@ -90,7 +92,7 @@ startvalue:
valuelen = 1;
}
}
- if (c == endsep || (endsep == ' ' && (c == '>' || isspace(c)))) {
+ if (c == endsep || (endsep == ' ' && (c == '>' || ISSPACE(c)))) {
x->data[valuelen] = '\0';
if (x->xmlattr)
x->xmlattr(x, x->tag, x->taglen, x->name, namelen, x->data, valuelen);
@@ -290,7 +292,7 @@ xml_parse(XMLParser *x)
if ((c = GETNEXT()) == EOF)
return;
- if (c == '!') { /* cdata and comments */
+ if (c == '!') { /* CDATA and comments */
for (tagdatalen = 0; (c = GETNEXT()) != EOF;) {
/* NOTE: sizeof(x->data) must be at least sizeof("[CDATA[") */
if (tagdatalen <= sizeof("[CDATA[") - 1)
@@ -315,7 +317,7 @@ xml_parse(XMLParser *x)
x->taglen = 1;
x->isshorttag = isend = 0;
- /* treat processing instruction as shorttag, don't strip "?" prefix. */
+ /* treat processing instruction as short tag, don't strip "?" prefix. */
if (c == '?') {
x->isshorttag = 1;
} else if (c == '/') {
@@ -328,9 +330,11 @@ xml_parse(XMLParser *x)
while ((c = GETNEXT()) != EOF) {
if (c == '/')
x->isshorttag = 1; /* short tag */
- else if (c == '>' || isspace(c)) {
+ else if (c == '>' || ISSPACE(c)) {
x->tag[x->taglen] = '\0';
if (isend) { /* end tag, starts with </ */
+ while (c != '>' && c != EOF) /* skip until > */
+ c = GETNEXT();
if (x->xmltagend)
x->xmltagend(x, x->tag, x->taglen, x->isshorttag);
x->tag[0] = '\0';
@@ -339,12 +343,12 @@ xml_parse(XMLParser *x)
/* start tag */
if (x->xmltagstart)
x->xmltagstart(x, x->tag, x->taglen);
- if (isspace(c))
+ if (ISSPACE(c))
xml_parseattrs(x);
if (x->xmltagstartparsed)
x->xmltagstartparsed(x, x->tag, x->taglen, x->isshorttag);
}
- /* call tagend for shortform or processing instruction */
+ /* call tagend for short tag or processing instruction */
if (x->isshorttag) {
if (x->xmltagend)
x->xmltagend(x, x->tag, x->taglen, x->isshorttag);