Use case-insensitive strstr to match "stylesheet"

svn path=/trunk/netsurf/; revision=2689
This commit is contained in:
John Mark Bell 2006-07-02 10:26:51 +00:00
parent 467d9679f8
commit 2cb285209e
3 changed files with 24 additions and 2 deletions

View File

@ -593,10 +593,10 @@ bool html_find_stylesheets(struct content *c, xmlNode *head)
/* rel=<space separated list, including 'stylesheet'> */
if ((rel = (char *) xmlGetProp(node, (const xmlChar *) "rel")) == NULL)
continue;
if (strstr(rel, "stylesheet") == 0) {
if (strcasestr(rel, "stylesheet") == 0) {
xmlFree(rel);
continue;
} else if (strstr(rel, "alternate")) {
} else if (strcasestr(rel, "alternate")) {
/* Ignore alternate stylesheets */
xmlFree(rel);
continue;

View File

@ -214,3 +214,24 @@ const char *rfc1123_date(time_t t)
return ret;
}
/**
* Case insensitive strstr implementation
*
* \param haystack String to search in
* \param needle String to look for
* \return Pointer to start of found substring, or NULL if not found
*/
char *strcasestr(const char *haystack, const char *needle)
{
size_t needle_len = strlen(needle);
const char * last_start = haystack + (strlen(haystack) - needle_len);
while (haystack <= last_start) {
if (strncasecmp(haystack, needle, needle_len) == 0)
return (char *)haystack;
haystack++;
}
return NULL;
}

View File

@ -56,6 +56,7 @@ void regcomp_wrapper(regex_t *preg, const char *regex, int cflags);
void unicode_transliterate(unsigned int c, char **r);
char *human_friendly_bytesize(unsigned long bytesize);
const char *rfc1123_date(time_t t);
char *strcasestr(const char *haystack, const char *needle);
/* Platform specific functions */
void die(const char * const error);