How to test locale in C? All my tests fail.

Artem Kuchin matrix at itlegion.ru
Thu May 24 10:24:40 UTC 2007


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 



More information about the freebsd-stable mailing list