xml.c: sync some of the improvements to this modified version - grabtitle - stu… | |
git clone git://git.codemadness.org/grabtitle | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit e0263471557e79c3a178e6da41b5f7e2f4234625 | |
parent 29e4807c53d136de19f775b7d08b3c1c3a14d76d | |
Author: Hiltjo Posthuma <[email protected]> | |
Date: Sun, 30 Jun 2024 10:19:01 +0200 | |
xml.c: sync some of the improvements to this modified version | |
Diffstat: | |
M xml.c | 20 +++++++++++--------- | |
M xml.h | 8 ++++---- | |
2 files changed, 15 insertions(+), 13 deletions(-) | |
--- | |
diff --git 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; | |
@@ -22,7 +24,7 @@ xml_parseattrs(XMLParser *x) | |
else if (c == '=') { | |
valuestart = 1; | |
endname = 1; | |
- } else if (namelen && ((endname && !valuestart && isalpha(c)) … | |
+ } else if (namelen && ((endname && !valuestart && ISALPHA(c)) … | |
endname = 0; | |
namelen = 1; | |
} else if (namelen && valuestart) { | |
@@ -35,7 +37,7 @@ xml_parseattrs(XMLParser *x) | |
} | |
} else { | |
while ((c = GETNEXT()) != EOF) { | |
- if (c == '>' || isspace(c)) | |
+ if (c == '>' || ISSPACE(c)) | |
break; | |
} | |
} | |
@@ -238,7 +240,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 le… | |
if (tagdatalen <= sizeof("[CDATA[") - … | |
@@ -263,7 +265,7 @@ xml_parse(XMLParser *x) | |
x->taglen = 1; | |
x->isshorttag = isend = 0; | |
- /* treat processing instruction as shorttag, d… | |
+ /* treat processing instruction as short tag, … | |
if (c == '?') { | |
x->isshorttag = 1; | |
} else if (c == '/') { | |
@@ -276,7 +278,7 @@ xml_parse(XMLParser *x) | |
while ((c = GETNEXT()) != EOF) { | |
if (c == '/') | |
x->isshorttag = 1; /* short ta… | |
- else if (c == '>' || isspace(c)) { | |
+ else if (c == '>' || ISSPACE(c)) { | |
x->tag[x->taglen] = '\0'; | |
if (isend) { /* end tag, start… | |
while (c != '>' && c !… | |
@@ -289,10 +291,10 @@ xml_parse(XMLParser *x) | |
/* start tag */ | |
if (x->xmltagstart) | |
x->xmltagstart… | |
- if (isspace(c)) | |
+ if (ISSPACE(c)) | |
xml_parseattrs… | |
} | |
- /* call tagend for shortform o… | |
+ /* call tagend for short tag o… | |
if (x->isshorttag) { | |
if (x->xmltagend) | |
x->xmltagend(x… | |
diff --git a/xml.h b/xml.h | |
@@ -1,5 +1,5 @@ | |
-#ifndef _XML_H_ | |
-#define _XML_H_ | |
+#ifndef XML_H | |
+#define XML_H | |
#include <stdio.h> | |
@@ -17,9 +17,9 @@ typedef struct xmlparser { | |
/* current tag */ | |
char tag[1024]; | |
size_t taglen; | |
- /* current tag is in short form ? <tag /> */ | |
+ /* current tag is a short tag ? <tag /> */ | |
int isshorttag; | |
- /* data buffer used for tag data, cdata and attribute data */ | |
+ /* data buffer used for tag data, CDATA and attribute data */ | |
char data[BUFSIZ]; | |
} XMLParser; | |