Re: GnomeICU Release



Kaixo!

On Sun, Jan 14, 2001 at 12:26:00AM +0000, simos@pc96.ma.rhbnc.ac.uk wrote:

> I believe you could use "qsort" for sorting and "strcoll" for comparison.
> Once Unicode comes into place, you will need to replace strcoll with the
> Unicode counterpart.

strcoll() is locale-dependent; so you haven't to change anything to use
it with unicode; only set a unicode locale when launching your program.

In fact strcoll() is like a strcasecmp() but locale-dependent.
(and, yes, it is case insensitive; if you want a locale-dependent but case
sensitive one, you have to create your own; eg something like:

int strcoll_case(char *a,char *b)
{
	int n=0;
	char c[2],d[2];

	c={0,0}; d={0,0}; 

	if (a && *a) c[0]=*a++; 
	if (b && *b) c[0]=*b++; 

	while (n==0 && *c && *d ) {
		n = strcoll(c,d);
		if (n==0) { 
	             c[0]=*a++; d[0]=*b++;
			/* are both lowercase? */
		     n=((d[0] == tolower(c[0]) || d[0] == tolower(d[0])) ? 0 :
			/* or both uppercase? */
			(d[0] == toupper(c[0]) || d[0] == upper(d[0])) ? 0 :
			/* they don't match */
			(c[0] == toupper(c[0])) ? -1 : 1 );
		}
	}
	return n;
}


(PS: I would be interested in a better algorithm, or if it is possible to
do it trough some standard function)

-- 
Ki ça vos våye bén,
Pablo Saratxaga

http://www.srtxg.easynet.be/		PGP Key available, key ID: 0x8F0E4975




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]