From: Vincent Pelletier <subdino2004@yahoo.fr>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: [PATCHv2] dprintf implementation
Date: Thu, 14 Apr 2005 09:13:32 +0200 [thread overview]
Message-ID: <425E181C.1000908@yahoo.fr> (raw)
In-Reply-To: <a6f3036e78c2b3459321f524ec84b59a@penguinppc.org>
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
next prev parent reply other threads:[~2005-04-14 7:26 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-21 21:04 [PATCH] dprintf implementation Vincent Pelletier
2005-02-23 23:11 ` Hollis Blanchard
2005-02-24 8:02 ` Vincent Pelletier
2005-02-24 8:49 ` Aki Tossavainen
2005-02-24 19:30 ` Yoshinori K. Okuji
2005-02-24 22:42 ` Vincent Pelletier
2005-02-25 0:18 ` Hollis Blanchard
2005-02-25 7:14 ` Aki Tossavainen
2005-02-25 11:52 ` [PATCHv2] " Vincent Pelletier
2005-02-25 16:02 ` Hollis Blanchard
2005-02-25 16:13 ` Aki Tossavainen
2005-02-25 16:41 ` Hollis Blanchard
2005-02-25 17:12 ` Yoshinori K. Okuji
2005-02-25 18:04 ` Vincent Pelletier
2005-02-25 18:58 ` Yoshinori K. Okuji
2005-04-14 3:31 ` Hollis Blanchard
2005-04-14 7:13 ` Vincent Pelletier [this message]
2005-04-14 14:08 ` Vincent Pelletier
2005-05-09 2:06 ` Hollis Blanchard
2005-04-14 11:37 ` Yoshinori K. Okuji
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=425E181C.1000908@yahoo.fr \
--to=subdino2004@yahoo.fr \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.