static gint
camel_ustrncasecmp (const gchar *ps1, const gchar *ps2, gsize len)
{
	gunichar u1, u2 = 0;
	const guchar *s1 = (const guchar *)ps1;
	const guchar *s2 = (const guchar *)ps2;

	CAMEL_SEARCH_COMPARE (s1, s2, NULL);

	u1 = camel_utf8_getc (&s1);
	u2 = camel_utf8_getc (&s2);
	while (len > 0 && u1 && u2) {
		u1 = g_unichar_tolower (u1);
		u2 = g_unichar_tolower (u2);
		if (u1 < u2)
			return -1;
		else if (u1 > u2)
			return 1;

		len--;
		u1 = camel_utf8_getc (&s1);
		u2 = camel_utf8_getc (&s2);
	}

	if (len == 0)
		return 0;

	/* end of one of the strings ? */
	CAMEL_SEARCH_COMPARE (u1, u2, 0);

	/* if we have invalid utf8 sequence ?  */
	CAMEL_SEARCH_COMPARE (s1, s2, NULL);

	return 0;
}
Пример #2
0
static int
camel_ustrcasecmp (const char *ps1, const char *ps2)
{
	gunichar u1, u2 = 0;
	const unsigned char *s1 = (const unsigned char *)ps1;
	const unsigned char *s2 = (const unsigned char *)ps2;

	CAMEL_SEARCH_COMPARE (s1, s2, NULL);

	u1 = camel_utf8_getc(&s1);
	u2 = camel_utf8_getc(&s2);
	while (u1 && u2) {
		u1 = g_unichar_tolower (u1);
		u2 = g_unichar_tolower (u2);
		if (u1 < u2)
			return -1;
		else if (u1 > u2)
			return 1;

		u1 = camel_utf8_getc(&s1);
		u2 = camel_utf8_getc(&s2);
	}

	/* end of one of the strings ? */
	CAMEL_SEARCH_COMPARE (u1, u2, 0);

	/* if we have invalid utf8 sequence ?  */
	CAMEL_SEARCH_COMPARE (s1, s2, NULL);

	return 0;
}