This source file includes following definitions.
- c_strcasestr
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 "c-strcasestr.h"
22
23 #include <stdbool.h>
24 #include <string.h>
25
26 #include "c-ctype.h"
27 #include "c-strcase.h"
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
35 #define CMP_FUNC(p1, p2, l) \
36 c_strncasecmp ((const char *) (p1), (const char *) (p2), l)
37 #include "str-two-way.h"
38
39
40
41 char *
42 c_strcasestr (const char *haystack_start, const char *needle_start)
43 {
44 const char *haystack = haystack_start;
45 const char *needle = needle_start;
46 size_t needle_len;
47 size_t haystack_len;
48 bool ok = true;
49
50
51
52
53 while (*haystack && *needle)
54 ok &= (c_tolower ((unsigned char) *haystack++)
55 == c_tolower ((unsigned char) *needle++));
56 if (*needle)
57 return NULL;
58 if (ok)
59 return (char *) haystack_start;
60 needle_len = needle - needle_start;
61 haystack = haystack_start + 1;
62 haystack_len = needle_len - 1;
63
64
65
66
67 if (needle_len < LONG_NEEDLE_THRESHOLD)
68 return two_way_short_needle ((const unsigned char *) haystack,
69 haystack_len,
70 (const unsigned char *) needle_start,
71 needle_len);
72 return two_way_long_needle ((const unsigned char *) haystack, haystack_len,
73 (const unsigned char *) needle_start,
74 needle_len);
75 }
76
77 #undef LONG_NEEDLE_THRESHOLD