1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

Updated stristr() and stristr_full() to be a bit faster.

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@813 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-11-07 01:25:46 +00:00 committed by cras
parent 4301e04791
commit 6e27475e98

View File

@ -301,19 +301,27 @@ GList *glist_find_icase_string(GList *list, const char *key)
char *stristr(const char *data, const char *key) char *stristr(const char *data, const char *key)
{ {
const char *pos, *max; const char *max;
int keylen, datalen; int keylen, datalen, pos;
keylen = strlen(key); keylen = strlen(key);
datalen = strlen(data); datalen = strlen(data);
if (keylen > datalen) if (keylen > datalen || keylen == 0)
return NULL; return NULL;
max = data+datalen-keylen; max = data+datalen-keylen;
for (pos = data; pos <= max; pos++) { pos = 0;
if (g_strncasecmp(pos, key, keylen) == 0) while (data <= max) {
return (char *) pos; if (key[pos] == '\0')
return (char *) data;
if (toupper(data[pos]) == toupper(key[pos]))
pos++;
else {
data++;
pos = 0;
}
} }
return NULL; return NULL;
@ -325,22 +333,34 @@ char *stristr(const char *data, const char *key)
char *stristr_full(const char *data, const char *key) char *stristr_full(const char *data, const char *key)
{ {
const char *pos, *max; const char *start, *max;
int keylen, datalen; int keylen, datalen, pos;
keylen = strlen(key); keylen = strlen(key);
datalen = strlen(data); datalen = strlen(data);
if (keylen > datalen) if (keylen > datalen || keylen == 0)
return NULL; return NULL;
max = data+datalen-keylen; max = data+datalen-keylen;
for (pos = data; pos <= max; pos++) { start = data; pos = 0;
if (pos > data && !isbound(pos[-1])) continue; while (data <= max) {
if (key[pos] == '\0') {
if (data[pos] != '\0' && !isbound(data[pos])) {
data++;
pos = 0;
continue;
}
return (char *) data;
}
if (g_strncasecmp(pos, key, keylen) == 0 && if (toupper(data[pos]) == toupper(key[pos]) &&
(pos[keylen] == '\0' || isbound(pos[keylen]))) (pos != 0 || data == start || isbound(data[-1])))
return (char *) pos; pos++;
else {
data++;
pos = 0;
}
} }
return NULL; return NULL;