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 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org http://lists.gnu.org/mailman/listinfo/grub-devel