Example #1
0
static int irc_compare_nicks_int(const char *const nick1, const char *const nick2) {
	int	i = 0;

	while (nick1[i] != '\0') {
		if (irc_tolower(nick1[i]) != irc_tolower(nick2[i]))
			return(1);
		i++;
	}
	if (nick2[i] != '\0')
		return(1);

	return(0);
}
Example #2
0
/**
 * irc_str_cmp:
 * @s1: First string
 * @s2: Second string
 *
 * Compares two strings for equality ignoring case
 * according to the IRC RFC.
 *
 * See Also: irc_tolower()
 * Returns: 0 when equal
 */
int
irc_str_cmp (const char *s1, const char *s2)
{
    int c1, c2;

	while (*s1 && *s2)
	{
		c1 = (int)irc_tolower (*s1);
		c2 = (int)irc_tolower (*s2);
		if (c1 != c2)
			return (c1 - c2);
		s1++; s2++;
	}

	return (((int)*s1) - ((int)*s2));
}
Example #3
0
/**
 * irc_strcasestr:
 * @haystack: String to look in
 * @needle: String to look for
 *
 * Looks for @needle in @haystack ignoring case according
 * to the IRC RFC and returns pointer to the start of the
 * match. If @needle is empty returns pointer to @haystack.
 * If not found returns %NULL.
 *
 * See also: irc_tolower()
 */
char *
irc_strcasestr (const char *haystack, const char *needle)
{
	const gsize needle_len = strlen (needle);
	const gsize haystack_len = strlen (haystack);

	for (gsize i = 0; haystack_len - i >= needle_len; ++i, ++haystack)
	{
		char *haystack_p = (char*)haystack;
		char *needle_p = (char*)needle;
		gsize matched = 0;

		while (*needle_p && irc_tolower(*haystack_p) == irc_tolower(*needle_p))
		{
			++haystack_p;
			++needle_p;
			++matched;
		}
		if (matched == needle_len)
			return (char*)haystack;
	}
	return NULL;
}