[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCHv2] dprintf implementation
From: |
Vincent Pelletier |
Subject: |
Re: [PATCHv2] dprintf implementation |
Date: |
Thu, 14 Apr 2005 09:13:32 +0200 |
User-agent: |
Debian Thunderbird 1.0.2 (X11/20050331) |
Hollis Blanchard wrote:
> int
> grub_strword(const char *haystack, const char *needle)
> {
> char *match;
> char *end;
>
> match = strstr (haystack, needle);
>
> if (match == NULL)
> return 0;
> if ((match > haystack) && (!grub_iswordseparator (match[-1])))
> return 0;
>
> end = match + strlen(needle)+1;
> if (*end && !grub_iswordseparator (*end))
> return 0;
>
> return 1;
> }
I find a little problem (sorry :) ) :
haystack = "filesystem file"
needle = "file"
won't match.
A loop might do the trick, but after a short try I don't see how.
Here is a new version of my strword. It should be easier to read.
int
grub_strword (const char *haystack, const char *needle)
{
const char *n_pos = needle;
while (grub_iswordseparator (*haystack))
haystack++;
while (*haystack)
{
/* Crawl both the needle and the haystack word we're on. */
while(*haystack && !grub_iswordseparator (*haystack) && *haystack
== *n_pos)
{
haystack++;
n_pos++;
}
/* If we reached the end of both words at the same time, the word
is found. If not, eat everything in the haystack that isn't the
next word (or the end of string) and "reset" the needle. */
if ( (!*haystack || grub_iswordseparator (*haystack))
&& (!*n_pos || grub_iswordseparator (*n_pos)))
return 1;
else
{
n_pos = needle;
while (*haystack && !grub_iswordseparator (*haystack))
haystack++;
while (grub_iswordseparator (*haystack))
haystack++;
}
}
return 0;
}
Vincent Pelletier