Named locales not ok for locales without thousands separator
Nathan Myers
ncm-nospam@cantrip.org
Sun Jan 27 17:38:00 GMT 2002
On Mon, Jan 28, 2002 at 01:57:15AM +0100, Paolo Carlini wrote:
> today, for the first time I configured current 3.1 + glibc2.2.5 with
> --enable-clocale=gnu (testsuite ok, many XPASSes). Then I wanted to
> check some of Peter Schmid testcases, in particular that submitted as
> part of libstdc++/5280.
>
> It seems that something is still not ok when the concerned locale has
> NO thousands separator (e.g., fr_FR or it_IT).
What does it mean for a locale to have "no" thousands separator?
The thousands_sep() member function has no choice but to return
a character. (The grouping() member function can return an empty
string, in which case the thousands separator isn't used.)
This is not to say it isn't broken, just that I don't understand
what you are saying *is* broken.
The best way to make a test case would be to derive from std::numpunct<>
and construct a locale using it. Then you're not dependent on anybody's
data files:
#include <locale>
#include <stringstream>
struct testpunct : std::numpunct<char> {
char do_thousands_sep() const { return '*'; }
string do_grouping() const { return string("\002"); }
};
...
std::locale loc(locale(), new testpunct);
std::stringstream str(loc);
str << 12345;
assert(str.str() == "1*23*45");
(Untested, if ironically so. When you override locale facet virtuals,
don't forget to declare them "const".)
Nathan Myers
ncm at cantrip dot org
More information about the Libstdc++
mailing list