|
Ruby 1.9.2p290(2011-07-09revision32553)
|
00001 /* public domain rewrite of strstr(3) */ 00002 00003 char * 00004 strstr(const char *haystack, const char *needle) 00005 { 00006 const char *hend; 00007 const char *a, *b; 00008 00009 if (*needle == 0) return (char *)haystack; 00010 hend = haystack + strlen(haystack) - strlen(needle) + 1; 00011 while (haystack < hend) { 00012 if (*haystack == *needle) { 00013 a = haystack; 00014 b = needle; 00015 for (;;) { 00016 if (*b == 0) return (char *)haystack; 00017 if (*a++ != *b++) { 00018 break; 00019 } 00020 } 00021 } 00022 haystack++; 00023 } 00024 return 0; 00025 } 00026
1.7.3