On Feb 25, 2005, at 5:52 AM, Vincent Pelletier wrote:

grub_strword (string, word) : searches for word (a serie of non-word-separators eventualy ended by word-separators) in string (a succession of 0 or more words which can begin by word-separator(s))

grub_strword looks a little overcomplicated; would something like this work?


int
grub_strword (const char *haystack, const char *needle)
{
    int pos = 0;
    int found = 0;

    while (haystack[pos]) {
        /* Advance to next word. */
        while (grub_iswordseparator (haystack[pos]))
            pos++;

        if (0 == grub_strcmp (&haystack[pos], needle))
            {
                found = 1;
                break;
            }
    }

    return found;
}

That assumes 'needle' contains no separator characters. I think that's a safe assumption, given that 'needle' should come from a list of #defines. Or we could even sanity-check that in grub_strword, which IMHO would still be simpler than your earlier code.

Also, don't forget to add double spaces after periods in comments; otherwise the emacs^W"style" police will kick in your door and make you write 500 ChangeLog entries as punishment.

-Hollis



_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to