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