Esempio n. 1
0
const char *strnstrn(const char *needle, int needle_len,
                     const char *haystack, int haystack_len) {
  int i=0, j=0, compiled[KMPPATSIZE];

  if(needle_len > KMPPATSIZE)
    abort();
  kmp_precompute(needle, needle_len, compiled);
  while (j < haystack_len) {
    while (i > -1 && needle[i] != haystack[j])
      i = compiled[i];
    i++; j++;
    if (i >= needle_len) {
      return haystack + j - i;
    }
  }
  return NULL;
}
Esempio n. 2
0
const char *strnstrn(const char *needle, int needle_len,
                     const char *haystack, int haystack_len) {
  int i=0, j=0, compiled[KMPPATSIZE];

  if(needle_len > KMPPATSIZE) {
    mtevFatal(mtev_error, "errorin strnstrn: needle_len (%d) < KMPPATSIZE (%d)\n",
            needle_len, KMPPATSIZE);
  }
  kmp_precompute(needle, needle_len, compiled);
  while (j < haystack_len) {
    while (i > -1 && needle[i] != haystack[j])
      i = compiled[i];
    i++; j++;
    if (i >= needle_len) {
      return haystack + j - i;
    }
  }
  return NULL;
}