OSDN Git Service

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