bug-coreutils
[Top][All Lists]
Advanced

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

Re: tr '[:upper:]' '[:lower:]' -- misaligned construct


From: Micah Cowan
Subject: Re: tr '[:upper:]' '[:lower:]' -- misaligned construct
Date: Mon, 07 Jan 2008 10:49:24 -0800
User-agent: Thunderbird 2.0.0.9 (X11/20071031)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jim Meyering wrote:
> Here's a tentative patch that also avoids repeated
> (and wasteful) initialization of the xlate array.

I note that POSIX requires that, in the case that the arguments are
exactly '[:lower:]' and '[:upper:]' (or the reverse of the same), tr is
actually supposed to ignore the 'lower' and 'upper' character classes,
and instead initialize the mapping from the locale's "tolower"/"toupper"
definition. This would have avoided the length mismatch in the first
place, and while that issue appears to be addressed, tr still does not
conform to POSIX, as, if tr were to encounter a locale definition file
with an LC_CTYPE category definition such as the following:

  ...
  upper A;...;Z
  lower a;...;z
  tolower (A,Z)
  ...

This would require
 $ echo AAAA | tr '[:upper:]' '[:lower:]'
to output "ZZZZ" (though it isn't even lowercased), rather than 'aaaa'.

While the example above is, of course, contrived, there may well be
locales where the tolower/toupper mappings differ from the longest
possible mapping between the 'upper' and 'lower' classes.

In fact, as it currently stands, I expect tr mishandles a case such as:
  $ echo σιγμας | tr '[:lower:]' '[:upper:]'
(Note the two variants of "sigma" in there, which both have a single
corresponding capital letter; I'm afraid I can't actually verify this is
broken, as my work desktop is not set up to compile coreutils, and I
lack the time to correct this for now; the stock (old) tr on the system,
running Fedora Core 6, silently passes it through without conversion.)

- --
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHgnQ07M8hyUobTrERAj1OAJ4sH0pvLyWRPm0A5HOybsVjaI2HLQCeJQ8X
DEuKSy4u/ip63Df/UbC4FVY=
=PC3H
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]