char *strcasestr(char *haystack, char *needle) a simple case independent strstr()

char *strcasestr(char *haystack, char *needle) a simple case independent strstr()

Post by Jan Pantelt » Fri, 06 Oct 2000 04:00:00



Well, I needed it, and so i wrote it.
Sort of fun.

Any 'optimizers' can have a go now :-)

char *strcasestr(char *haystack, char *needle)
{
/* case independent strstr */
char *hptr;
char *nptr;
char *pptr;

/* start at the beginning of haystack */
pptr = haystack;

/* for each position in haystack */
while(1)
        {
        /* starting at this position in haystack */
        hptr = pptr;
        nptr = needle;

        /* test if strings match from here on */
        while(1)
                {
                /* test for end of needle */
                if(*nptr == 0)
                        {
                        /* found match */
                        return pptr;
                        }

                /* test for end of haystack */
                if(*hptr == 0) break;

                /* test for any differences */
                if( toupper(*hptr) != toupper(*nptr) ) break;                

                /* increment positions in strings */
                hptr++;
                nptr++;

                }/* end while all characters in needle */

        /* try next position in haystack */
        pptr++;

        /* test for end of haystack */
        if(*pptr == 0) break;

        }/* end while all positions in haystack */

return 0;

Quote:}/* end function strcasestr */

 
 
 

1. [2.5] const char* to char* conversion in console.h

The read function for consoles in include/linux/console.h contains const
char* for a pointer that it will actually modify. Although no one seems
to be using this as of now, it should be corrected.

--- include/linux/console.h.orig        Tue Apr  1 18:32:24 2003

 {
        char    name[8];
        void    (*write)(struct console *, const char *, unsigned);
-       int     (*read)(struct console *, const char *, unsigned);
+       int     (*read)(struct console *, char *, unsigned);
        kdev_t  (*device)(struct console *);
        void    (*unblank)(void);
        int     (*setup)(struct console *, char *);

--
Amit Shah
http://amitshah.nav.to/

A: No.
Q: Should I include quotations after my reply?

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

2. Help about wish and tcl commands !

3. KernelJanitor - Change applicable char *foo to char foo[]

4. Has it been done: User Script File System?

5. how to change password length from 6 chars to 4 chars on RH6.1 ??

6. help!Need to generate passwds and nicknames!

7. const char* to char* update in console.h

8. ./configure failed for kdelib-1.1 (Slackware 3.5)

9. ?? Modem sends ~15 chars, wait 30s, 15 chars, wait 30s...??

10. SED / Line / (Need to get data from searched line from specific char to char)

11. Gnu C++ stream.h char* form(const char*, ...)

12. read from $var, char by char

13. [2.5] const char* to char* update in console.h