mirror of
https://github.com/irssi/irssi.git
synced 2024-10-27 05:20:20 -04: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:
parent
4301e04791
commit
6e27475e98
@ -301,19 +301,27 @@ GList *glist_find_icase_string(GList *list, const char *key)
|
||||
|
||||
char *stristr(const char *data, const char *key)
|
||||
{
|
||||
const char *pos, *max;
|
||||
int keylen, datalen;
|
||||
const char *max;
|
||||
int keylen, datalen, pos;
|
||||
|
||||
keylen = strlen(key);
|
||||
datalen = strlen(data);
|
||||
|
||||
if (keylen > datalen)
|
||||
if (keylen > datalen || keylen == 0)
|
||||
return NULL;
|
||||
|
||||
max = data+datalen-keylen;
|
||||
for (pos = data; pos <= max; pos++) {
|
||||
if (g_strncasecmp(pos, key, keylen) == 0)
|
||||
return (char *) pos;
|
||||
pos = 0;
|
||||
while (data <= max) {
|
||||
if (key[pos] == '\0')
|
||||
return (char *) data;
|
||||
|
||||
if (toupper(data[pos]) == toupper(key[pos]))
|
||||
pos++;
|
||||
else {
|
||||
data++;
|
||||
pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -325,22 +333,34 @@ char *stristr(const char *data, const char *key)
|
||||
|
||||
char *stristr_full(const char *data, const char *key)
|
||||
{
|
||||
const char *pos, *max;
|
||||
int keylen, datalen;
|
||||
const char *start, *max;
|
||||
int keylen, datalen, pos;
|
||||
|
||||
keylen = strlen(key);
|
||||
datalen = strlen(data);
|
||||
|
||||
if (keylen > datalen)
|
||||
if (keylen > datalen || keylen == 0)
|
||||
return NULL;
|
||||
|
||||
max = data+datalen-keylen;
|
||||
for (pos = data; pos <= max; pos++) {
|
||||
if (pos > data && !isbound(pos[-1])) continue;
|
||||
start = data; pos = 0;
|
||||
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 &&
|
||||
(pos[keylen] == '\0' || isbound(pos[keylen])))
|
||||
return (char *) pos;
|
||||
if (toupper(data[pos]) == toupper(key[pos]) &&
|
||||
(pos != 0 || data == start || isbound(data[-1])))
|
||||
pos++;
|
||||
else {
|
||||
data++;
|
||||
pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user