Example #1
0
/* This function is equivalent to strcasestr() for multibyte strings. */
char *mbstrcasestr(const char *haystack, const char *needle)
{
#ifdef ENABLE_UTF8
    if (use_utf8) {
	size_t haystack_len, needle_len;

	assert(haystack != NULL && needle != NULL);

	if (*needle == '\0')
	    return (char *)haystack;

	haystack_len = mbstrlen(haystack);
	needle_len = mbstrlen(needle);

	for (; *haystack != '\0' && haystack_len >= needle_len;
		haystack += move_mbright(haystack, 0), haystack_len--) {
	    if (mbstrncasecmp(haystack, needle, needle_len) == 0)
		return (char *)haystack;
	}

	return NULL;
    } else
#endif
	return strcasestr(haystack, needle);
}
Example #2
0
/* This function is equivalent to strcasestr() for multibyte strings,
 * except in that it scans the string in reverse, starting at rev_start. */
char *mbrevstrcasestr(const char *haystack, const char *needle, const
	char *rev_start)
{
#ifdef ENABLE_UTF8
    if (use_utf8) {
	size_t rev_start_len, needle_len;

	if (*needle == '\0')
	    return (char *)rev_start;

	needle_len = mbstrlen(needle);

	if (mbstrlen(haystack) < needle_len)
	    return NULL;

	rev_start_len = mbstrlen(rev_start);

	while (TRUE) {
	    if (rev_start_len >= needle_len &&
			mbstrncasecmp(rev_start, needle, needle_len) == 0)
		return (char *)rev_start;

	    /* If we've reached the head of the haystack, we found nothing. */
	    if (rev_start == haystack)
		return NULL;

	    rev_start = haystack + move_mbleft(haystack, rev_start - haystack);
	    rev_start_len++;
	}
    } else
#endif
	return revstrcasestr(haystack, needle, rev_start);
}
Example #3
0
/* This function is equivalent to strcasestr() for multibyte strings,
 * except in that it scans the string in reverse, starting at
 * rev_start. */
char *mbrevstrcasestr(const char *haystack, const char *needle, const
	char *rev_start)
{
#ifdef ENABLE_UTF8
    if (use_utf8) {
	bool begin_line = FALSE;
	size_t rev_start_len, needle_len;

	assert(haystack != NULL && needle != NULL && rev_start != NULL);

	if (*needle == '\0')
	    return (char *)rev_start;

	needle_len = mbstrlen(needle);

	if (mbstrlen(haystack) < needle_len)
	    return NULL;

	rev_start_len = mbstrlen(rev_start);

	while (!begin_line) {
	    if (rev_start_len >= needle_len &&
			mbstrncasecmp(rev_start, needle, needle_len) == 0 &&
			mblen(rev_start, MB_CUR_MAX) > 0)
		return (char *)rev_start;

	    if (rev_start == haystack)
		begin_line = TRUE;
	    else {
		rev_start = haystack + move_mbleft(haystack, rev_start -
			haystack);
		rev_start_len++;
	    }
	}

	return NULL;
    } else
#endif
	return revstrcasestr(haystack, needle, rev_start);
}
Example #4
0
/* This function is equivalent to strcasestr() for multibyte strings. */
char *mbstrcasestr(const char *haystack, const char *needle)
{
#ifdef ENABLE_UTF8
    if (use_utf8) {
	size_t needle_len;

	if (*needle == '\0')
	    return (char *)haystack;

	needle_len = mbstrlen(needle);

	while (*haystack != '\0') {
	    if (mbstrncasecmp(haystack, needle, needle_len) == 0)
		return (char *)haystack;

	    haystack += move_mbright(haystack, 0);
	}

	return NULL;
    } else
#endif
	return (char *) strcasestr(haystack, needle);
}
Example #5
0
/* This function is equivalent to strcasecmp() for multibyte strings. */
int mbstrcasecmp(const char *s1, const char *s2)
{
    return mbstrncasecmp(s1, s2, (size_t)-1);
}
Example #6
0
/* This function is equivalent to strcasecmp() for multibyte strings. */
int mbstrcasecmp(const char *s1, const char *s2)
{
    return mbstrncasecmp(s1, s2, HIGHEST_POSITIVE);
}