65 # define LONG_NEEDLE_THRESHOLD 32U 67 # define LONG_NEEDLE_THRESHOLD SIZE_MAX 71 # define MAX(a, b) ((a < b) ? (b) : (a)) 75 # define CANON_ELEMENT(c) c 78 # define CMP_FUNC memcmp 112 size_t max_suffix, max_suffix_rev;
123 return needle_len - 1;
139 while (j + k < needle_len)
174 while (j + k < needle_len)
183 p = j - max_suffix_rev;
199 max_suffix_rev = j++;
218 if (max_suffix_rev + 1 < max_suffix + 1)
219 return max_suffix + 1;
221 return max_suffix_rev + 1;
236 const unsigned char *needle,
size_t needle_len)
250 if (
CMP_FUNC (needle, needle + period, suffix) == 0)
257 while (
AVAILABLE (haystack, haystack_len, j, needle_len))
260 i =
MAX (suffix, memory);
271 if (i + 1 < memory + 1)
276 memory = needle_len - period;
289 period =
MAX (suffix, needle_len - suffix) + 1;
291 while (
AVAILABLE (haystack, haystack_len, j, needle_len))
330 const unsigned char *needle,
size_t needle_len)
336 size_t shift_table[1U << CHAR_BIT];
347 for (i = 0; i < 1U << CHAR_BIT; i++)
348 shift_table[i] = needle_len;
349 for (i = 0; i < needle_len; i++)
354 if (
CMP_FUNC (needle, needle + period, suffix) == 0)
362 while (
AVAILABLE (haystack, haystack_len, j, needle_len))
366 shift = shift_table[
CANON_ELEMENT (haystack[j + needle_len - 1])];
369 if (memory && shift < period)
374 shift = needle_len - period;
382 i =
MAX (suffix, memory);
386 if (needle_len - 1 <= i)
393 if (i + 1 < memory + 1)
398 memory = needle_len - period;
412 period =
MAX (suffix, needle_len - suffix) + 1;
414 while (
AVAILABLE (haystack, haystack_len, j, needle_len))
418 shift = shift_table[
CANON_ELEMENT (haystack[j + needle_len - 1])];
430 if (needle_len - 1 <= i)
#define SIZE_MAX
Definition: quotearg.c:52
static size_t critical_factorization(const unsigned char *needle, size_t needle_len, size_t *period)
Definition: str-two-way.h:108
#define RETURN_TYPE
Definition: strstr.c:29
#define AVAILABLE(h, h_l, j, n_l)
Definition: strstr.c:30
static RETURN_TYPE two_way_long_needle(const unsigned char *haystack, size_t haystack_len, const unsigned char *needle, size_t needle_len)
Definition: str-two-way.h:329
#define CANON_ELEMENT(c)
Definition: str-two-way.h:75
#define CMP_FUNC
Definition: str-two-way.h:78
#define MAX(a, b)
Definition: str-two-way.h:71
static RETURN_TYPE two_way_short_needle(const unsigned char *haystack, size_t haystack_len, const unsigned char *needle, size_t needle_len)
Definition: str-two-way.h:235
#define NULL
Definition: stddef.in.h:72