Welcome! Log In Create A New Profile

Advanced

wcscasecmp and wcsncasecmp not available?

Posted by DrTwox 
wcscasecmp and wcsncasecmp not available?
March 03, 2009 12:49PM
[www.opengroup.org]

I presume these two functions are not in devkitPPC/newlib as they don't appear to be in wchar.h. Is this a limitation of devkitPPC/newlib locale support or are they GNU only extensions, not standard?

Edit: Also, to further prove my ignorance, in /devkitPRO/devkitPPC/powerpc-gekko/include/limits.h is
#define MB_LEN_MAX 1
... shouldn't that be larger? Obviously you could just use your own size definitions, but that kinda defeats the purpose of defines like this.



Edited 1 time(s). Last edit at 03/03/2009 01:24PM by DrTwox.
Re: wcscasecmp and wcsncasecmp not available?
March 03, 2009 05:54PM
Those two functions aren't included in a number of libraries AFAIK - they are extensions. That includes newlib - newlib's wchar support on the whole is minimal. If you want to use wchar's, you'll have to define functions yourself.
Re: wcscasecmp and wcsncasecmp not available?
March 04, 2009 09:43AM
Okay, I figured as much...
towlower is available in wctypes.h, and this seems to work for basic Latin characters.
int wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n) {
	while (n--) {
		wint_t c1 = towlower(*s1);
		wint_t c2 = towlower(*s2);
		wint_t diff = c1 - c2;

		if (diff != 0) {
			return diff;
		}

		if (!c1) {
			return 0;
		}

		++s1;
		++s2;
	}

	return 0;
}

Tested with:

wchar_t s1[4] = { 0x00C0, 0x00C8, 0x00D2, '\0'}; /* ÀÈÒ */
wchar_t s2[4] = { 0x00E0, 0x00E8, 0x00F2, '\0'}; /* àèò */
if (wcsncasecmp(s1, s2, 3) == 0) {
	printf("wcsncasecmp of %ls and %ls match", s1, s2);
} else {
	printf("wcsncasecmp of %ls and %ls do not match", s1, s2);
}
outputs: wcsncasecmp of ÀÈÒ and àèò match

Which isn't an exhaustive test, but it will do for now!
Sorry, only registered users may post in this forum.

Click here to login