summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2000-11-07 01:25:46 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2000-11-07 01:25:46 +0000
commit6e27475e9884f4fb91d4359ca8a8cffab48f10f9 (patch)
tree458db359efe1bba2bd6d2a60da63cbd34c482cc3 /src/core
parent4301e0479124953c1e78c4a150433571188fdc8d (diff)
downloadirssi-6e27475e9884f4fb91d4359ca8a8cffab48f10f9.zip
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
Diffstat (limited to 'src/core')
-rw-r--r--src/core/misc.c48
1 files changed, 34 insertions, 14 deletions
diff --git a/src/core/misc.c b/src/core/misc.c
index 73b66128..1212c602 100644
--- a/src/core/misc.c
+++ b/src/core/misc.c
@@ -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;