GNOME Bugzilla – Bug 129539
Thousands separator doesn't work if it is a non-ASCII character
Last modified: 2004-12-22 21:47:04 UTC
gcalctool uses only the first byte of nl_langinfo(THOUSEP). In locales (such as cs_CZ.UTF-8) where THOUSEP is not a single byte, this results in invalid UTF-8 and thousands separator does not appear on the display.
Created attachment 22604 [details] [review] Treat thousands separator and decimal point as strings.
The attached patch changes all code I could find to treat the decimal point and thousands separator as multi-byte characters (strings) of length up to MB_LEN_MAX. The needed buffers have been enlarged from MAX_DIGITS to MAX_BUFFER (but digits can't be entered if the current display would be > MAX_DIGITS characters). It looks like the code would benefit from having a separate "internal" representation (using the "C" locale convention) and a separate string for display instead of converting all the time, but I'll leave that for later or for others :)
Thanks Miloslav! I'd actually started looking at this last week, but I was getting confused because nl_langinfo(THOUSEP) was returning an empty string for me, and I didn't understand why. Seems that's what's supposed to happen in the C locale. Toshi (who I've cc:'ed on the bug), sorted me out (thanks!). I'll apply your patch when I return to work on Monday. I'll also ask Toshi to check it as he has access to more locales then I have installed on my machine. This should be in time for the GNOME 2.5.2 call for tarballs.
Unfortunately, the patch doesn't handle the C locale, where nl_langinfo() returns an empty string. Working on a fix for that now. I'm probably going to adjust it so that if nl_anginfo(THOUSEP) returns an empty string, then get_tsep() returns ",".
Created attachment 22641 [details] Adjustments (to work in C locale, radix_char -> radix, OneTrueCodeStyle(TM))
Changes checked into CVS HEAD. Fixed in v4.3.31. I made a few minor changes over the original patch: 1/ Adjusted get_tsep() to handle the C locale, where nl_langinfo(THOUSEP) returns an empty string. If that happens, then get_tsep() returns (",". 2/ Adjusted all occurances of radix_char to radix for consistency. 3/ Adjusted get_radix() to check if nl_langinfo(RADIXCHAR) returned an empty string (it shouldn't), in which case get_radix() now just returns ".". 4/ Trivial adjustments to code style to maintain the OneTrueStyle(TM) ;-) Milo/Toshi, if you get a chance could you test it to make sure I haven't broken it again with all these minor changes. Thanks!