Index: HTMLparser.c
@@ -610,7 +610,7 @@
for (i = 0; i < (sizeof(html40ElementTable) /
sizeof(html40ElementTable[0]));i++) {
- if (!xmlStrcmp(tag, BAD_CAST html40ElementTable[i].name))
+ if (!xmlStrcasecmp(tag, BAD_CAST html40ElementTable[i].name))
return(&html40ElementTable[i]);
}
return(NULL);
@@ -2663,19 +2663,11 @@
if ((ctxt == NULL) || (attvalue == NULL))
return;
- encoding = xmlStrstr(attvalue, BAD_CAST"charset=");
- if (encoding == NULL)
- encoding = xmlStrstr(attvalue, BAD_CAST"Charset=");
- if (encoding == NULL)
- encoding = xmlStrstr(attvalue, BAD_CAST"CHARSET=");
+ encoding = xmlStrcasestr(attvalue, BAD_CAST"charset=");
if (encoding != NULL) {
encoding += 8;
} else {
- encoding = xmlStrstr(attvalue, BAD_CAST"charset =");
- if (encoding == NULL)
- encoding = xmlStrstr(attvalue, BAD_CAST"Charset =");
- if (encoding == NULL)
- encoding = xmlStrstr(attvalue, BAD_CAST"CHARSET =");
+ encoding = xmlStrcasestr(attvalue, BAD_CAST"charset =");
if (encoding != NULL)
encoding += 9;
}
@@ -2757,18 +2749,10 @@
att = atts[i++];
while (att != NULL) {
value = atts[i++];
- if ((value != NULL) &&
- ((!xmlStrcmp(att, BAD_CAST"http-equiv")) ||
- (!xmlStrcmp(att, BAD_CAST"Http-Equiv")) ||
- (!xmlStrcmp(att, BAD_CAST"HTTP-EQUIV"))) &&
- ((!xmlStrcmp(value, BAD_CAST"Content-Type")) ||
- (!xmlStrcmp(value, BAD_CAST"content-type")) ||
- (!xmlStrcmp(value, BAD_CAST"CONTENT-TYPE"))))
+ if ((value != NULL) && (!xmlStrcasecmp(att, BAD_CAST"http-equiv"))
+ && (!xmlStrcasecmp(value, BAD_CAST"Content-Type")))
http = 1;
- else if ((value != NULL) &&
- ((!xmlStrcmp(att, BAD_CAST"content")) ||
- (!xmlStrcmp(att, BAD_CAST"Content")) ||
- (!xmlStrcmp(att, BAD_CAST"CONTENT"))))
+ else if ((value != NULL) && (!xmlStrcasecmp(att, BAD_CAST"content")))
content = value;
att = atts[i++];
}
Index: HTMLtree.c
@@ -113,17 +113,11 @@
#else
value = xmlBufferContent(attr->children->content);
#endif
- if (((!xmlStrcmp(attr->name, BAD_CAST"http-equiv")) ||
- (!xmlStrcmp(attr->name, BAD_CAST"Http-Equiv")) ||
- (!xmlStrcmp(attr->name, BAD_CAST"HTTP-EQUIV"))) &&
- ((!xmlStrcmp(value, BAD_CAST"Content-Type")) ||
- (!xmlStrcmp(value, BAD_CAST"content-type")) ||
- (!xmlStrcmp(value, BAD_CAST"CONTENT-TYPE"))))
+ if ((!xmlStrcasecmp(attr->name, BAD_CAST"http-equiv"))
+ && (!xmlStrcasecmp(value, BAD_CAST"Content-Type")))
http = 1;
- else if ((value != NULL) &&
- ((!xmlStrcmp(attr->name, BAD_CAST"content")) ||
- (!xmlStrcmp(attr->name, BAD_CAST"Content")) ||
- (!xmlStrcmp(attr->name, BAD_CAST"CONTENT"))))
+ else if ((value != NULL)
+ && (!xmlStrcasecmp(attr->name, BAD_CAST"content")))
content = value;
if ((http != 0) && (content != NULL))
goto found_content;
@@ -294,17 +288,11 @@
#else
value = xmlBufferContent(attr->children->content);
#endif
- if (((!xmlStrcmp(attr->name, BAD_CAST"http-equiv")) ||
- (!xmlStrcmp(attr->name, BAD_CAST"Http-Equiv")) ||
- (!xmlStrcmp(attr->name, BAD_CAST"HTTP-EQUIV"))) &&
- ((!xmlStrcmp(value, BAD_CAST"Content-Type")) ||
- (!xmlStrcmp(value, BAD_CAST"content-type")) ||
- (!xmlStrcmp(value, BAD_CAST"CONTENT-TYPE"))))
+ if ((!xmlStrcasecmp(attr->name, BAD_CAST"http-equiv"))
+ && (!xmlStrcasecmp(value, BAD_CAST"Content-Type")))
http = 1;
- else if ((value != NULL) &&
- ((!xmlStrcmp(attr->name, BAD_CAST"content")) ||
- (!xmlStrcmp(attr->name, BAD_CAST"Content")) ||
- (!xmlStrcmp(attr->name, BAD_CAST"CONTENT"))))
+ else if ((value != NULL)
+ && (!xmlStrcasecmp(attr->name, BAD_CAST"content")))
content = value;
if ((http != 0) && (content != NULL))
break;
Index: nanohttp.c
@@ -62,6 +62,7 @@
#endif
#include
+#include
#include
#ifdef STANDALONE
@@ -523,37 +524,22 @@
}
if ((*cur != 0) && (*cur != ' ') && (*cur != '\t')) return;
ctxt->returnValue = ret;
- } else if (!strncmp(line, "Content-Type:", 13)) {
+ } else if (!xmlStrncasecmp(line, BAD_CAST"Content-Type:", 13)) {
cur += 13;
while ((*cur == ' ') || (*cur == '\t')) cur++;
if (ctxt->contentType != NULL)
xmlFree(ctxt->contentType);
ctxt->contentType = xmlMemStrdup(cur);
- } else if (!strncmp(line, "ContentType:", 12)) {
+ } else if (!xmlStrncasecmp(line, BAD_CAST"ContentType:", 12)) {
cur += 12;
if (ctxt->contentType != NULL) return;
while ((*cur == ' ') || (*cur == '\t')) cur++;
ctxt->contentType = xmlMemStrdup(cur);
- } else if (!strncmp(line, "content-type:", 13)) {
- cur += 13;
- if (ctxt->contentType != NULL) return;
- while ((*cur == ' ') || (*cur == '\t')) cur++;
- ctxt->contentType = xmlMemStrdup(cur);
- } else if (!strncmp(line, "contenttype:", 12)) {
- cur += 12;
- if (ctxt->contentType != NULL) return;
- while ((*cur == ' ') || (*cur == '\t')) cur++;
- ctxt->contentType = xmlMemStrdup(cur);
- } else if (!strncmp(line, "Location:", 9)) {
+ } else if (!xmlStrncasecmp(line, BAD_CAST"Location:", 9)) {
cur += 9;
while ((*cur == ' ') || (*cur == '\t')) cur++;
if (ctxt->location != NULL)
xmlFree(ctxt->location);
- ctxt->location = xmlMemStrdup(cur);
- } else if (!strncmp(line, "location:", 9)) {
- cur += 9;
- if (ctxt->location != NULL) return;
- while ((*cur == ' ') || (*cur == '\t')) cur++;
ctxt->location = xmlMemStrdup(cur);
}
}
Index: parser.c
@@ -1014,10 +1014,10 @@
if (str1 == NULL) return(-1);
if (str2 == NULL) return(1);
do {
- tmp = *str1++ - *str2++;
+ tmp = *str1++ - *str2;
if (tmp != 0) return(tmp);
- } while ((*str1 != 0) && (*str2 != 0)); /* non input consuming */
- return (*str1 - *str2);
+ } while (*str2++ != 0);
+ return 0;
}
/**
@@ -1036,19 +1036,102 @@
register int tmp;
if (len <= 0) return(0);
- if ((str1 == NULL) && (str2 == NULL)) return(0);
+ if (str1 == str2) return(0);
if (str1 == NULL) return(-1);
if (str2 == NULL) return(1);
do {
- tmp = *str1++ - *str2++;
+ tmp = *str1++ - *str2;
+ if (tmp != 0 || --len == 0) return(tmp);
+ } while (*str2++ != 0);
+ return 0;
+}
+
+static xmlChar casemap[256] = {
+ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
+ 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
+ 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,
+ 0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
+ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
+ 0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
+ 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,
+ 0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
+ 0x40,0x61,0x62,0x63,0x64,0x65,0x66,0x67,
+ 0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
+ 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,
+ 0x78,0x79,0x7A,0x7B,0x5C,0x5D,0x5E,0x5F,
+ 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,
+ 0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
+ 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,
+ 0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
+ 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
+ 0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,
+ 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,
+ 0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F,
+ 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,
+ 0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,
+ 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,
+ 0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF,
+ 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,
+ 0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,
+ 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,
+ 0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF,
+ 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,
+ 0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,
+ 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,
+ 0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF
+};
+
+/**
+ * xmlStrcasecmp:
+ * @str1: the first xmlChar *
+ * @str2: the second xmlChar *
+ *
+ * a strcasecmp for xmlChar's
+ *
+ * Returns the integer result of the comparison
+ */
+
+int
+xmlStrcasecmp(const xmlChar *str1, const xmlChar *str2) {
+ register int tmp;
+
+ if (str1 == str2) return(0);
+ if (str1 == NULL) return(-1);
+ if (str2 == NULL) return(1);
+ do {
+ tmp = casemap[*str1++] - casemap[*str2];
if (tmp != 0) return(tmp);
- len--;
- if (len <= 0) return(0);
- } while ((*str1 != 0) && (*str2 != 0)); /* non input consuming */
- return (*str1 - *str2);
+ } while (*str2++ != 0);
+ return 0;
}
/**
+ * xmlStrncasecmp:
+ * @str1: the first xmlChar *
+ * @str2: the second xmlChar *
+ * @len: the max comparison length
+ *
+ * a strncasecmp for xmlChar's
+ *
+ * Returns the integer result of the comparison
+ */
+
+int
+xmlStrncasecmp(const xmlChar *str1, const xmlChar *str2, int len) {
+ register int tmp;
+
+ if (len <= 0) return(0);
+ if (str1 == str2) return(0);
+ if (str1 == NULL) return(-1);
+ if (str2 == NULL) return(1);
+ do {
+ tmp = casemap[*str1++] - casemap[*str2];
+ if (tmp != 0 || --len == 0) return(tmp);
+ } while (*str2++ != 0);
+ return 0;
+}
+
+/**
* xmlStrchr:
* @str: the xmlChar * array
* @val: the xmlChar to search
@@ -1091,6 +1174,33 @@
if (*str == *val) {
if (!xmlStrncmp(str, val, n)) return((const xmlChar *) str);
}
+ str++;
+ }
+ return(NULL);
+}
+
+/**
+ * xmlStrcasestr:
+ * @str: the xmlChar * array (haystack)
+ * @val: the xmlChar to search (needle)
+ *
+ * a case-ignoring strstr for xmlChar's
+ *
+ * Returns the xmlChar * for the first occurence or NULL.
+ */
+
+const xmlChar *
+xmlStrcasestr(const xmlChar *str, xmlChar *val) {
+ int n;
+
+ if (str == NULL) return(NULL);
+ if (val == NULL) return(NULL);
+ n = xmlStrlen(val);
+
+ if (n == 0) return(str);
+ while (*str != 0) { /* non input consuming */
+ if (casemap[*str] == casemap[*val])
+ if (!xmlStrncasecmp(str, val, n)) return(str);
str++;
}
return(NULL);
Index: parser.h
@@ -335,9 +335,16 @@
xmlChar val);
const xmlChar * xmlStrstr (const xmlChar *str,
xmlChar *val);
+const xmlChar * xmlStrcasestr (const xmlChar *str,
+ xmlChar *val);
int xmlStrcmp (const xmlChar *str1,
const xmlChar *str2);
int xmlStrncmp (const xmlChar *str1,
+ const xmlChar *str2,
+ int len);
+int xmlStrcasecmp (const xmlChar *str1,
+ const xmlChar *str2);
+int xmlStrncasecmp (const xmlChar *str1,
const xmlChar *str2,
int len);
int xmlStrlen (const xmlChar *str);
Index: tree.c
@@ -2770,21 +2770,16 @@
cur = cur->next;
continue;
}
- if ((!xmlStrcmp(cur->name, BAD_CAST "html")) ||
- (!xmlStrcmp(cur->name, BAD_CAST "HTML"))) {
+ if (!xmlStrcasecmp(cur->name, BAD_CAST "html")) {
cur = cur->children;
continue;
}
- if ((!xmlStrcmp(cur->name, BAD_CAST "head")) ||
- (!xmlStrcmp(cur->name, BAD_CAST "HEAD"))) {
+ if (!xmlStrcasecmp(cur->name, BAD_CAST "head")) {
cur = cur->children;
continue;
}
- if ((!xmlStrcmp(cur->name, BAD_CAST "base")) ||
- (!xmlStrcmp(cur->name, BAD_CAST "BASE"))) {
- base = xmlGetProp(cur, BAD_CAST "href");
- if (base != NULL) return(base);
- return(xmlGetProp(cur, BAD_CAST "HREF"));
+ if (!xmlStrcasecmp(cur->name, BAD_CAST "base")) {
+ return(xmlGetProp(cur, BAD_CAST "href"));
}
cur = cur->next;
}
@@ -3581,7 +3576,7 @@
*/
prop = node->properties;
while (prop != NULL) {
- if (!xmlStrcmp(prop->name, name)) {
+ if (!xmlStrcasecmp(prop->name, name)) {
return(prop);
}
prop = prop->next;
@@ -3630,7 +3625,7 @@
*/
prop = node->properties;
while (prop != NULL) {
- if (!xmlStrcmp(prop->name, name)) {
+ if (!xmlStrcasecmp(prop->name, name)) {
xmlChar *ret;
ret = xmlNodeListGetString(node->doc, prop->children, 1);
@@ -3743,7 +3738,7 @@
xmlAttrPtr prop = node->properties;
while (prop != NULL) {
- if (!xmlStrcmp(prop->name, name)) {
+ if (!xmlStrcasecmp(prop->name, name)) {
if (prop->children != NULL)
xmlFreeNodeList(prop->children);
prop->children = NULL;