| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#include <config.h> |
| 19 |
|
| 20 |
|
| 21 |
#include <string.h> |
| 22 |
|
| 23 |
#include <ctype.h> |
| 24 |
#include <stdbool.h> |
| 25 |
#include <strings.h> |
| 26 |
|
| 27 |
#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) |
| 28 |
|
| 29 |
|
| 30 |
#define RETURN_TYPE char * |
| 31 |
#define AVAILABLE(h, h_l, j, n_l) \ |
| 32 |
(!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \ |
| 33 |
&& ((h_l) = (j) + (n_l))) |
| 34 |
#define CANON_ELEMENT(c) TOLOWER (c) |
| 35 |
#define CMP_FUNC(p1, p2, l) \ |
| 36 |
strncasecmp ((const char *) (p1), (const char *) (p2), l) |
| 37 |
#include "str-two-way.h" |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
char * |
| 43 |
strcasestr (const char *haystack_start, const char *needle_start) |
| 44 |
{ |
| 45 |
const char *haystack = haystack_start; |
| 46 |
const char *needle = needle_start; |
| 47 |
size_t needle_len; |
| 48 |
size_t haystack_len; |
| 49 |
bool ok = true; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
while (*haystack && *needle) |
| 55 |
{ |
| 56 |
ok &= (TOLOWER ((unsigned char) *haystack) |
| 57 |
== TOLOWER ((unsigned char) *needle)); |
| 58 |
haystack++; |
| 59 |
needle++; |
| 60 |
} |
| 61 |
if (*needle) |
| 62 |
return NULL; |
| 63 |
if (ok) |
| 64 |
return (char *) haystack_start; |
| 65 |
needle_len = needle - needle_start; |
| 66 |
haystack = haystack_start + 1; |
| 67 |
haystack_len = needle_len - 1; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
if (needle_len < LONG_NEEDLE_THRESHOLD) |
| 73 |
return two_way_short_needle ((const unsigned char *) haystack, |
| 74 |
haystack_len, |
| 75 |
(const unsigned char *) needle_start, |
| 76 |
needle_len); |
| 77 |
return two_way_long_needle ((const unsigned char *) haystack, haystack_len, |
| 78 |
(const unsigned char *) needle_start, |
| 79 |
needle_len); |
| 80 |
} |
| 81 |
|
| 82 |
#undef LONG_NEEDLE_THRESHOLD |