MCPcopy Create free account
hub / github.com/pydata/numexpr / stringcontains

Function stringcontains

numexpr3/string_functions.hpp:474–515  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

472}
473
474int
475stringcontains(const char *haystack_start, const char *needle_start, npy_intp max_haystack_len, npy_intp max_needle_len)
476{
477 // contains(str1, str2) function for string columns.
478 // Based on Newlib/strstr.c.
479 // needle_len - Length of needle.
480 // haystack_len - Known minimum length of haystack.
481 size_t needle_len = min((size_t)max_needle_len, strlen(needle_start));
482 size_t haystack_len = min((size_t)max_haystack_len, strlen(haystack_start));
483
484 const char *haystack = haystack_start;
485 const char *needle = needle_start;
486 bool ok = true; /* needle is prefix of haystack. */
487
488 if(haystack_len<needle_len)
489 return 0;
490
491 size_t si = 0;
492 while (*haystack && *needle && si < needle_len)
493 {
494 ok &= *haystack++ == *needle++;
495 si++;
496 }
497 if (ok)
498 {
499 return 1;
500 }
501
502 if (needle_len < LONG_NEEDLE_THRESHOLD)
503 {
504 char *res = two_way_short_needle ((const unsigned char *) haystack_start,
505 haystack_len,
506 (const unsigned char *) needle_start, needle_len) ;
507 int ptrcomp = res != NULL;
508 return ptrcomp;
509 }
510
511 char* res = two_way_long_needle ((const unsigned char *) haystack, haystack_len,
512 (const unsigned char *) needle, needle_len);
513 int ptrcomp2 = res != NULL ? 1 : 0;
514 return ptrcomp2;
515}

Callers

nothing calls this directly

Calls 2

two_way_short_needleFunction · 0.85
two_way_long_needleFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…