31#if defined (__IBMCPP__) && !defined (_RWSTD_NO_IMPLICIT_INCLUSION)
35# define _RWSTD_NO_IMPLICIT_INCLUSION
65 const char*,
const std::locale*);
69 const char*,
const std::locale*);
80 rw_info (0, 0, __LINE__,
"classic \"C\" locale");
83 std::locale *
loc =
new std::locale (std::locale::classic ());
99 const charT fn[] = {
'f',
'a',
'l',
's',
'e',
'\0' };
100 const charT tn[] = {
't',
'r',
'u',
'e',
'\0' };
126 const char *first_non_c = 0;
129 for (
const char*
s =
rw_locales (); *
s;
s += std::strlen (
s) + 1) {
132 && std::strcmp (
"C",
s)
133 && std::strcmp (
"POSIX",
s))
140 std::sprintf (envvar,
"LC_ALL=%s", first_non_c);
152#ifndef _RWSTD_NO_WCHAR_T
158# ifndef _RWSTD_NO_MBTOWC
160 const int n =
s && *
s ? std::mbtowc (&wc,
s, std::strlen (
s)) : 0;
170 return n > 0 ? wc :
n ? -1 : 0;
176template <
class charT>
180 const std::locale *
loc)
183 const char *tmploc = std::setlocale (
LC_ALL, locname);
189 char locnamebuf [1024];
190 RW_ASSERT ((std::strlen (tmploc) + 1) <
sizeof locnamebuf);
191 std::strcpy (locnamebuf, tmploc);
196 "locale (%s) -> \"%s\"; LANG=%s, "
197 "LC_ALL=%s, LC_NUMERIC=%s",
199 std::getenv (
"LANG"),
200 std::getenv (
"LC_ALL"),
201 std::getenv (
"LC_NUMERIC"));
204 const std::lconv *plconv = std::localeconv ();
217 const std::string grouping =
218 plconv->grouping ? plconv->grouping :
"";
221 std::setlocale (
LC_ALL,
"");
223 loc =
new std::locale (locname);
227 if ( (
'C' == locnamebuf [0] &&
'\0' == locnamebuf [1])
228 || (
'C' == locname [0] &&
'\0' == locname [1])
229 || *
loc == std::locale::classic ()) {
257template <
class charT>
260 const std::locale *
loc)
262 typedef std::numpunct<charT>
Punct;
263 typedef std::char_traits<charT>
Traits;
267 :
Punct ().decimal_point ();
270 rw_assert (Traits::eq (
c, expect), 0, __LINE__,
271 "numpunct<%s>::decimal_point() == %{#lc}, got %{#lc}",
277template <
class charT>
280 const std::locale *
loc)
282 typedef std::numpunct<charT>
Punct;
283 typedef std::char_traits<charT>
Traits;
287 :
Punct ().thousands_sep ();
289 rw_assert (Traits::eq (
c, expect), 0, __LINE__,
290 "numpunct<%s>::thousands_sep() == %{#lc}, got %{#lc}",
296template <
class charT>
299 const std::string &expect,
300 const std::locale *
loc)
302 typedef std::numpunct<charT>
Punct;
304 const std::string
s =
loc ?
306 :
Punct ().grouping ();
309 &&
s.size () != expect.size () &&
s.size () && expect.size ()) {
315 const std::string *lng =
s.size () > expect.size () ? &expect : &
s;
316 const std::string *shrt =
s.size () < expect.size () ? &expect : &
s;
318 std::size_t
i = shrt->size () - 1;
320 for ( ;
i != lng->size (); ++
i)
321 if ((*shrt) [shrt->size () - 1] != (*lng)[
i])
325 "numpunct<%s>::grouping() equivalent to %{#S}, got %{#S}",
330 "numpunct<%s>::grouping() == %{#S}, got %{#S}",
336template <
class charT>
339 const std::locale *
loc)
341 typedef std::numpunct<charT>
Punct;
343 const std::basic_string<charT>
s =
loc ?
345 :
Punct ().falsename ();
347 const int char_size = int (
sizeof (
charT));
350 "numpunct<%s>::falsename() == %{#*S}, got %{#*S}",
351 tname, char_size, &expect, char_size, &
s);
356template <
class charT>
359 const std::locale *
loc)
361 typedef std::numpunct<charT>
Punct;
363 const std::basic_string<charT>
s =
loc ?
365 :
Punct ().truename ();
367 const int char_size = int (
sizeof (
charT));
370 "numpunct<%s>::truename() == %{#*S}, got %{#*S}",
371 tname, char_size, &expect, char_size, &
s);
381#ifndef _RWSTD_WCHAR_T
392int main (
int argc,
char *argv[])
394 return rw_test (argc, argv, __FILE__,
395 "lib.locale.numpunct",
std::numpunct_byname< char > NumpunctByname
void check_decimal_point(charT, const char *, const std::locale *)
void check_falsename(const std::basic_string< charT > &, const char *, const std::locale *)
void check_truename(const std::basic_string< charT > &, const char *, const std::locale *)
void check_grouping(charT, const char *, const std::string &, const std::locale *)
char widen(char, const char *s)
void check_thousands_sep(charT, const char *, const std::locale *)
bool check_numpunct(charT, const char *, const char *, const std::locale *)
#define _STD_HAS_FACET(type, arg)
#define _RWSTD_STATIC_CAST(T, x)
#define _STD_USE_FACET(type, arg)
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_putenv(const char *, int=-1)
_TEST_EXPORT char * rw_locales(int=_UNUSED_CAT, const char *=0, bool=true)