]>
Commit | Line | Data |
---|---|---|
be803e41 | 1 | // { dg-require-namedlocale "de_DE.ISO8859-15" } |
2 | // { dg-require-namedlocale "es_ES.ISO8859-15" } | |
e590fca1 | 3 | |
f1717362 | 4 | // Copyright (C) 2004-2016 Free Software Foundation, Inc. |
7fbeb37d | 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 | |
6bc9506f | 9 | // Free Software Foundation; either version 3, or (at your option) |
7fbeb37d | 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 | |
6bc9506f | 18 | // with this library; see the file COPYING3. If not see |
19 | // <http://www.gnu.org/licenses/>. | |
7fbeb37d | 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; | |
be803e41 | 30 | locale l1 = locale(ISO_8859(15,de_DE)); |
31 | locale l2 = locale(ISO_8859(15,es_ES)); | |
7fbeb37d | 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 | ||
9e3e6e41 | 66 | 1) The locale usage and design for formatters and parsers becomes |
7fbeb37d | 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 | |
9e3e6e41 | 84 | instantiations required in Tables 51 and 52 |
7fbeb37d | 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 | |
be803e41 | 107 | of de_DE.ISO8859-15 es_ES is: |
7fbeb37d | 108 | domingo |
109 | lunes | |
110 | martes | |
111 |