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

Bug#63717: isalpha()/toupper() functions do not work for non-ASCII characters



On Sun, May 07, 2000 at 06:04:03PM +0200, srittau wrote:
> The is*() and toupper()/tolower() functions do not work on non-ASCII
> characters, even if LC_CTYPE etc. are set to the correct language used:

Yes they do.

> srittau@moby:~$ locale
> LANG=de_DE
> LC_CTYPE="de_DE"
> LC_NUMERIC="de_DE"
> LC_TIME="de_DE"
> LC_COLLATE="de_DE"
> LC_MONETARY="de_DE"
> LC_MESSAGES="de_DE"
> LC_ALL=
> srittau@moby:~$ cat try.c
> #include <ctype.h>
> #include <stdio.h>
> 
> int main()
> {
>   int c = 'ä';
>   printf("%c: %d\n", c, isprint(c));
> 
>   return 0;
> }
> srittau@moby:~$ gcc try.c -o try -Wall
> srittau@moby:~$ ./try 
> ä: 0
> srittau@moby:~$ 

This is expected behaviour.  In the absence of a "setlocale" call the
program's locale is C.  To use the locale settings from the environment,
call setlocale(LC_ALL, "").  Observe:

$ locale
LANG=fi_FI
LC_CTYPE="fi_FI"
LC_NUMERIC="fi_FI"
LC_TIME="fi_FI"
LC_COLLATE="fi_FI"
LC_MONETARY="fi_FI"
LC_MESSAGES="fi_FI"
LC_ALL=
$ cat try-orig.c
#include <ctype.h>
#include <stdio.h>

int main()
{
  int c = 'ä';
  printf("%c: %d\n", c, isprint(c));

  return 0;
}
$ gcc try-orig.c -o try-orig -Wall
$ ./try-orig 
ä: 0
$ cat try.c
#include <ctype.h>
#include <locale.h>
#include <stdio.h>

int main()
{
  int c = 'ä';
  setlocale(LC_ALL, "");
  printf("%c: %d\n", c, isprint(c));

  return 0;
}
$ gcc try.c -o try -Wall
$ ./try
ä: 16384
$ 

This behaviour is (AFAIK) described in the ISO C standards, and in the
setlocale(3) manual page.

To the maintainer: you may close this bug.

-- 
%%% Antti-Juhani Kaijanaho % gaia@iki.fi % http://www.iki.fi/gaia/ %%%

                    I'm moving IRL on May 2, 2000.
               New contact information on the home page


Reply to: