Date: Thu, 24 May 2007 15:33:49 +0400 From: "Artem Kuchin" <matrix@itlegion.ru> To: "Massimo Fusaro" <mcfusaro@gmail.com> Cc: freebsd-stable@freebsd.org Subject: Re: How to test locale in C? All my tests fail. Message-ID: <02e401c79df7$676b80d0$05000100@Artem> References: <023401c79ded$ba3b7fe0$05000100@Artem> <60f6f5610705240347g708c3375i82d176e415e80b4@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Massimo Fusaro wrote:
>> From the setlocale(3) manual page:
>>
>> ... A locale argument of NULL causes setlocale() to return the
>> current locale. ...
Right. that why i first
call
setlocale(LC_CTYPE, "ru_RU.CP1251");
to set locale
and the call
setlocale(LC_CTYPE,NULL);
to check what locale is currently set.
I tried without call setlocale(LC_CTYPE,NULL);
- no difference.
--
Regards,
Artem
>> --
>> -max
>>
>> 2007/5/24, Artem Kuchin <matrix@itlegion.ru>:
>>> Maybe it is the wrong list, but maybe someone can quickly
>>> help me out.
>>>
>>> I have a very stupid problem. I cannot convert to upper
>>> or lower case using manually set locale (setlocale(..)).
>>>
>>> A very simple program:
>>> #include <locale.h>
>>> #include <errno.h>
>>> #include <ctype.h>
>>>
>>> main(){
>>>
>>> char *b=setlocale(LC_CTYPE, "ru_RU.CP1251");
>>> if (!b){
>>> printf("FAILED! %d\n",errno);
>>> }
>>> else {
>>> printf("OK: %s %d\n",b,errno);
>>> printf("IS UPPER Ê: %d\n",isupper('Ê'));
>>> printf("IS UPPER ê: %d\n",isupper('ê'));
>>> printf("IS LOWER Ê: %d\n",islower('Ê'));
>>> printf("IS LOWER ê: %d\n",islower('ê'));
>>> printf("LOCALE %s\n",setlocale(LC_CTYPE,NULL));
>>> printf("1: TO UPPER %c TO LOWER
>>> %c\n",toupper('Ö'),tolower('ö')); printf("1-0: TO UPPER %c
>>> TO LOWER %c\n",toupper('ñ'),tolower('Ñ')); printf("2: TO
>>> UPPER %c TO LOWER %c\n",toupper('r'),tolower('R')); }
>>> }
>>>
>>> Output is always:
>>>
>>> OK: ru_RU.CP1251 0
>>> IS UPPER Ê: 0
>>> IS UPPER ê: 0
>>> IS LOWER Ê: 0
>>> IS LOWER ê: 0
>>> LOCALE ru_RU.CP1251
>>> 1: TO UPPER Ö TO LOWER ö
>>> 1-0: TO UPPER ñ TO LOWER Ñ
>>> 2: TO UPPER R TO LOWER r
>>>
>>> Ê,Ö,Ñ - is lower case leters and
>>> ê,ö,ñ - is upper case
>>>
>>> As you see, it simply does not work at all.
>>> It seems like the locale is "C" but as you see
>>> setlocale returned ru_RU.CP1251
>>>
>>> tested on 6.2, 5.4 and 4.10 - all the same.
>>> What am i doing wrong?
>>> (except posting in the wrong list ;)
>>>
>>>
>>>
>>> --
>>> Regards,
>>> Artem
>>>
>>> _______________________________________________
>>> freebsd-stable@freebsd.org mailing list
>>> http://lists.freebsd.org/mailman/listinfo/freebsd-stable
>>> To unsubscribe, send any mail to
>>> "freebsd-stable-unsubscribe@freebsd.org"
>>>
>>
>
>
>
>> _______________________________________________
>> freebsd-stable@freebsd.org mailing list
>> http://lists.freebsd.org/mailman/listinfo/freebsd-stable
>> To unsubscribe, send any mail to
>> "freebsd-stable-unsubscribe@freebsd.org"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?02e401c79df7$676b80d0$05000100>
