コード例 #1
0
ファイル: pick.c プロジェクト: ScoreUnder/pick
int
min_match(const char *string, size_t offset, size_t *start, size_t *end)
{
	char	 *s, *e, *q;

	q = query;
	if ((s = e = strcasechr(&string[offset], q)) == NULL)
		return 0;

	for (;;) {
		for (e++, q++; isu8cont(*q); e++, q++);
		if (*q == '\0')
			break;
		if ((e = strcasechr(e, q)) == NULL)
			return 0;
	}

	*start = s - string;
	*end = e - string;
	/* Less than or equal is used in order to obtain the left-most match. */
	if (min_match(string, offset + 1, start, end)
	    && (size_t)(e - s) <= *end - *start) {
		*start = s - string;
		*end = e - string;
	}
	return 1;
}
コード例 #2
0
ファイル: match.c プロジェクト: hbaughman/fzy
int has_match(const char *needle, const char *haystack) {
	while (*needle) {
		char nch = *needle++;

		if (!(haystack = strcasechr(haystack, nch))) {
			return 0;
		}
		haystack++;
	}
	return 1;
}
コード例 #3
0
ファイル: 10-fuzzy.c プロジェクト: andrewgregory/snippets
int main(void) {
    tap_plan(12);

    tap_is_str(strcasechr("aBcDeF", 'd'), "DeF", NULL);
    tap_is_str(strcasechr("aBcDeF", 'D'), "DeF", NULL);
    tap_is_str(strcasechr("aBcDeF", 'e'), "eF", NULL);
    tap_is_str(strcasechr("aBcDeF", 'E'), "eF", NULL);

    tap_is_str(strfuzzy("abcdefg", "adg"), "g", NULL);
    tap_is_str(strfuzzy("abcdefg", "cdg"), "g", NULL);
    tap_is_str(strfuzzy("abcdefg", "ace"), "efg", NULL);
    tap_is_str(strfuzzy("abcdefg", "cb"), NULL, NULL);

    tap_is_str(strcasefuzzy("abcdefg", "aDg"), "g", NULL);
    tap_is_str(strcasefuzzy("abcdefg", "cDg"), "g", NULL);
    tap_is_str(strcasefuzzy("abcdefg", "aCe"), "efg", NULL);
    tap_is_str(strcasefuzzy("abcdefg", "cB"), NULL, NULL);

    return tap_finish();
}
コード例 #4
0
ファイル: strings.c プロジェクト: mej/libast
char *
strcasepbrk(const char *haystack, register const char *needle)
{
    register const char *t;

    REQUIRE_RVAL(needle != (spif_ptr_t) NULL, (spif_ptr_t) NULL);
    REQUIRE_RVAL(haystack != (spif_ptr_t) NULL, (spif_ptr_t) NULL);
    for (t = haystack; t && *t; t++) {
        if (strcasechr(needle, *t)) {
            return ((char *) t);
        }
    }
    return (NULL);
}
コード例 #5
0
ファイル: lib_strcasestr.c プロジェクト: andrecurvello/NuttX
FAR char *strcasestr(FAR const char *str, FAR const char *substr)
{
  const char *candidate;  /* Candidate in str with matching start character */
  char         ch;        /* First character of the substring */
  int          len;       /* The length of the substring */

  /* Special case the empty substring */

  len = strlen(substr);
  ch  = *substr;

  if (!ch)
    {
      /* We'll say that an empty substring matches at the beginning of
       * the string
       */

      return (char*)str;
    }

  /* Search for the substring */

  candidate = str;
  ch        = toupper(ch);

  for (;;)
    {
      /* strcasechr() will return a pointer to the next occurrence of the
       * character ch in the string (ignoring case)
       */

      candidate = strcasechr(candidate, ch);
      if (!candidate || strlen(candidate) < len)
        {
           /* First character of the substring does not appear in the string
            * or the remainder of the string is not long enough to contain the
            * substring.
            */

           return NULL;
        }

      /* Check if this is the beginning of a matching substring (ignoring case) */

      if (strncasecmp(candidate, substr, len) == 0)
        {
           /* Yes.. return the pointer to the first occurrence of the matching
            * substring.
            */

           return (char*)candidate;
        }

      /* No, find the next candidate after this one */

      candidate++;
    }

  /* Won't get here, but some compilers might complain */

  return NULL;
}