Re: [dwm] [dmenu] patch: non-consecutive substring matching

From: Anydot <dfenze_AT_gmail.com>
Date: Tue, 5 Jun 2007 01:05:00 +0200

On (04/06/07 15:04), Anselm R. Garbe wrote:
> Hi Dave,
>
> many thx for your patch. The idocontains() algorithm is
> implemented in a very simple way, I like it. Though I'm not sure
> yet what others think about it, and if it should be applied for
> the mainstream dmenu.

Imho this can be very useful, but as substitution of the current strstr
type matching. Next will be good to somewhat change the proposed
function:

static int
strido(const char *text, const char *pattern) {
        for (; *text && *pattern; text++)
                if (*text == *pattern)
                        pattern++;

        return !*pattern;
}

function is renamed to strido, and it's basic behaviour is same, changed
are only corner case. Check for NULL of any parameter are unnecessary,
as that aren't in libc str* func checked too. Testing for zero length
are unnecessary too, as this will be catch by loop's condition.

Also, in proposed function, the input of idocontains("", "pattern") will
lead to wrong result as it returnes 0 - matched.

-- 
Premysl "Anydot" Hruby >> http://na.srck.net <<
Received on Tue Jun 05 2007 - 01:05:07 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 14:43:52 UTC