1 |
19 |
jlechner |
// { dg-require-namedlocale "" }
|
2 |
|
|
|
3 |
|
|
// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
|
4 |
|
|
//
|
5 |
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
6 |
|
|
// software; you can redistribute it and/or modify it under the
|
7 |
|
|
// terms of the GNU General Public License as published by the
|
8 |
|
|
// Free Software Foundation; either version 2, or (at your option)
|
9 |
|
|
// any later version.
|
10 |
|
|
|
11 |
|
|
// This library is distributed in the hope that it will be useful,
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
|
|
// GNU General Public License for more details.
|
15 |
|
|
|
16 |
|
|
// You should have received a copy of the GNU General Public License along
|
17 |
|
|
// with this library; see the file COPYING. If not, write to the Free
|
18 |
|
|
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
19 |
|
|
// USA.
|
20 |
|
|
|
21 |
|
|
#include <sstream>
|
22 |
|
|
#include <locale>
|
23 |
|
|
#include <testsuite_hooks.h>
|
24 |
|
|
|
25 |
|
|
int main()
|
26 |
|
|
{
|
27 |
|
|
using namespace std;
|
28 |
|
|
|
29 |
|
|
bool test __attribute__((unused)) = true;
|
30 |
|
|
locale l1 = locale("de_DE");
|
31 |
|
|
locale l2 = locale("es_ES");
|
32 |
|
|
|
33 |
|
|
const time_put<char> &tp = use_facet<time_put<char> >(l1);
|
34 |
|
|
ostringstream oss;
|
35 |
|
|
oss.imbue(l2);
|
36 |
|
|
|
37 |
|
|
tm t = tm();
|
38 |
|
|
tp.put(oss.rdbuf(), oss, ' ', &t, 'A');
|
39 |
|
|
string res = oss.str();
|
40 |
|
|
|
41 |
|
|
VERIFY( res == "domingo" );
|
42 |
|
|
|
43 |
|
|
return 0;
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
// Two interpretations of the standard.
|
47 |
|
|
|
48 |
|
|
// 1 : time_get, time_put each have their own data internally
|
49 |
|
|
// use internal data for time and date specifics
|
50 |
|
|
// use getloc for ctype info
|
51 |
|
|
|
52 |
|
|
// 2 : time_get, time_put use the ios_base& argument and getloc to
|
53 |
|
|
// retrieve the necessary data.
|
54 |
|
|
// use getloc for ctype, time and date specifics
|
55 |
|
|
|
56 |
|
|
// It is my opinion that the language in the standard is sufficiently
|
57 |
|
|
// vague to permit both interpretations. In particular, the interface
|
58 |
|
|
// for time_get and time_put is based on strftime, which as
|
59 |
|
|
// POSIX notes is dependent on LC_TIME. The C++ standard, however,
|
60 |
|
|
// does not specify the equivalent mappings of LC_TIME to time_get and
|
61 |
|
|
// time_put.
|
62 |
|
|
|
63 |
|
|
/*
|
64 |
|
|
The problems with the first approach, as above, are numerous.
|
65 |
|
|
|
66 |
|
|
1) The locale usage and design for formatters and parsers becomes
|
67 |
|
|
fragmented. On one side, num_put and money_put, and on the other,
|
68 |
|
|
time_put. This inconsistency is not useful.
|
69 |
|
|
|
70 |
|
|
2) The data structures for time and date formatting are the largest in
|
71 |
|
|
the locale library. Making time_put and time_get keep separate
|
72 |
|
|
copies is inefficient. (Note that time_put and time_get are in the
|
73 |
|
|
same locale::category).
|
74 |
|
|
*/
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
/*
|
78 |
|
|
22.2.5 - The time category [lib.category.time]
|
79 |
|
|
|
80 |
|
|
-1- Templates time_get<charT,InputIterator> and
|
81 |
|
|
time_put<charT,OutputIterator> provide date and time formatting and
|
82 |
|
|
parsing. All specifications of member functions for time_put and
|
83 |
|
|
time_get in the subclauses of lib.category.time only apply to the
|
84 |
|
|
instantiations required in Tables 51 and 52
|
85 |
|
|
(lib.locale.category). Their members use their ios_base&,
|
86 |
|
|
ios_base::iostate&, and fill arguments as described in
|
87 |
|
|
(lib.locale.categories), and the ctype<> facet, to determine
|
88 |
|
|
formatting details.
|
89 |
|
|
*/
|
90 |
|
|
|
91 |
|
|
/*
|
92 |
|
|
22.2 - Standard locale categories [lib.locale.categories]
|
93 |
|
|
|
94 |
|
|
-1- Each of the standard categories includes a family of facets. Some
|
95 |
|
|
of these implement formatting or parsing of a datum, for use by
|
96 |
|
|
standard or users' iostream operators << and >>, as members put() and
|
97 |
|
|
get(), respectively. Each such member function takes an ios_base&
|
98 |
|
|
argument whose members flags(), precision(), and width(), specify the
|
99 |
|
|
format of the corresponding datum. (lib.ios.base). Those functions
|
100 |
|
|
which need to use other facets call its member getloc() to retrieve
|
101 |
|
|
the locale imbued there. Formatting facets use the character argument
|
102 |
|
|
fill to fill out the specified width where necessary.
|
103 |
|
|
*/
|
104 |
|
|
|
105 |
|
|
/*
|
106 |
|
|
With GCC/libstdc++, the output of the program with the arguments
|
107 |
|
|
of de_DE es_ES is:
|
108 |
|
|
domingo
|
109 |
|
|
lunes
|
110 |
|
|
martes
|
111 |
|
|
miércoles
|
112 |
|
|
jueves
|
113 |
|
|
viernes
|
114 |
|
|
sábado
|
115 |
|
|
|
116 |
|
|
With Intel C++, it is: (this is clearly wrong)
|
117 |
|
|
Sunday
|
118 |
|
|
Monday
|
119 |
|
|
Tuesday
|
120 |
|
|
Wednesday
|
121 |
|
|
Thursday
|
122 |
|
|
Friday
|
123 |
|
|
Saturday
|
124 |
|
|
|
125 |
|
|
And with RogueWave C++
|
126 |
|
|
Sonntag
|
127 |
|
|
Montag
|
128 |
|
|
Dienstag
|
129 |
|
|
Mittwoch
|
130 |
|
|
Donnerstag
|
131 |
|
|
Freitag
|
132 |
|
|
Samstag
|
133 |
|
|
*/
|