Import gcc-4.7.2 to new vendor branch
[dragonfly.git] / contrib / gcc-4.7 / libstdc++-v3 / config / locale / generic / time_members.cc
1 // std::time_get, std::time_put implementation, generic version -*- C++ -*-
2
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010
4 // Free Software Foundation, Inc.
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
9 // Free Software Foundation; either version 3, or (at your option)
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 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
20
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24 // <http://www.gnu.org/licenses/>.
25
26 //
27 // ISO C++ 14882: 22.2.5.1.2 - time_get virtual functions
28 // ISO C++ 14882: 22.2.5.3.2 - time_put virtual functions
29 //
30
31 // Written by Benjamin Kosnik <bkoz@redhat.com>
32
33 #include <locale>
34 #include <cstdlib>
35 #include <cstring>
36
37 namespace std _GLIBCXX_VISIBILITY(default)
38 {
39 _GLIBCXX_BEGIN_NAMESPACE_VERSION
40
41   template<>
42     void
43     __timepunct<char>::
44     _M_put(char* __s, size_t __maxlen, const char* __format,
45            const tm* __tm) const throw()
46     {
47       char* __old = setlocale(LC_ALL, 0);
48       const size_t __llen = strlen(__old) + 1;
49       char* __sav = new char[__llen];
50       memcpy(__sav, __old, __llen);
51       setlocale(LC_ALL, _M_name_timepunct);
52       const size_t __len = strftime(__s, __maxlen, __format, __tm);
53       setlocale(LC_ALL, __sav);
54       delete [] __sav;
55       // Make sure __s is null terminated.
56       if (__len == 0)
57         __s[0] = '\0';
58     }
59
60   template<>
61     void
62     __timepunct<char>::_M_initialize_timepunct(__c_locale)
63     {
64       // "C" locale.
65       if (!_M_data)
66         _M_data = new __timepunct_cache<char>;
67
68       _M_data->_M_date_format = "%m/%d/%y";
69       _M_data->_M_date_era_format = "%m/%d/%y";
70       _M_data->_M_time_format = "%H:%M:%S";
71       _M_data->_M_time_era_format = "%H:%M:%S";
72       _M_data->_M_date_time_format = "";
73       _M_data->_M_date_time_era_format = "";
74       _M_data->_M_am = "AM";
75       _M_data->_M_pm = "PM";
76       _M_data->_M_am_pm_format = "";
77
78       // Day names, starting with "C"'s Sunday.
79       _M_data->_M_day1 = "Sunday";
80       _M_data->_M_day2 = "Monday";
81       _M_data->_M_day3 = "Tuesday";
82       _M_data->_M_day4 = "Wednesday";
83       _M_data->_M_day5 = "Thursday";
84       _M_data->_M_day6 = "Friday";
85       _M_data->_M_day7 = "Saturday";
86
87       // Abbreviated day names, starting with "C"'s Sun.
88       _M_data->_M_aday1 = "Sun";
89       _M_data->_M_aday2 = "Mon";
90       _M_data->_M_aday3 = "Tue";
91       _M_data->_M_aday4 = "Wed";
92       _M_data->_M_aday5 = "Thu";
93       _M_data->_M_aday6 = "Fri";
94       _M_data->_M_aday7 = "Sat";
95
96       // Month names, starting with "C"'s January.
97       _M_data->_M_month01 = "January";
98       _M_data->_M_month02 = "February";
99       _M_data->_M_month03 = "March";
100       _M_data->_M_month04 = "April";
101       _M_data->_M_month05 = "May";
102       _M_data->_M_month06 = "June";
103       _M_data->_M_month07 = "July";
104       _M_data->_M_month08 = "August";
105       _M_data->_M_month09 = "September";
106       _M_data->_M_month10 = "October";
107       _M_data->_M_month11 = "November";
108       _M_data->_M_month12 = "December";
109
110       // Abbreviated month names, starting with "C"'s Jan.
111       _M_data->_M_amonth01 = "Jan";
112       _M_data->_M_amonth02 = "Feb";
113       _M_data->_M_amonth03 = "Mar";
114       _M_data->_M_amonth04 = "Apr";
115       _M_data->_M_amonth05 = "May";
116       _M_data->_M_amonth06 = "Jun";
117       _M_data->_M_amonth07 = "Jul";
118       _M_data->_M_amonth08 = "Aug";
119       _M_data->_M_amonth09 = "Sep";
120       _M_data->_M_amonth10 = "Oct";
121       _M_data->_M_amonth11 = "Nov";
122       _M_data->_M_amonth12 = "Dec";
123     }
124
125 #ifdef _GLIBCXX_USE_WCHAR_T
126   template<>
127     void
128     __timepunct<wchar_t>::
129     _M_put(wchar_t* __s, size_t __maxlen, const wchar_t* __format,
130            const tm* __tm) const throw()
131     {
132       char* __old = setlocale(LC_ALL, 0);
133       const size_t __llen = strlen(__old) + 1;
134       char* __sav = new char[__llen];
135       memcpy(__sav, __old, __llen);
136       setlocale(LC_ALL, _M_name_timepunct);
137       const size_t __len = wcsftime(__s, __maxlen, __format, __tm);
138       setlocale(LC_ALL, __sav);
139       delete [] __sav;
140       // Make sure __s is null terminated.
141       if (__len == 0)
142         __s[0] = L'\0';
143     }
144
145   template<>
146     void
147     __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale)
148     {
149       // "C" locale.
150       if (!_M_data)
151         _M_data = new __timepunct_cache<wchar_t>;
152
153       _M_data->_M_date_format = L"%m/%d/%y";
154       _M_data->_M_date_era_format = L"%m/%d/%y";
155       _M_data->_M_time_format = L"%H:%M:%S";
156       _M_data->_M_time_era_format = L"%H:%M:%S";
157       _M_data->_M_date_time_format = L"";
158       _M_data->_M_date_time_era_format = L"";
159       _M_data->_M_am = L"AM";
160       _M_data->_M_pm = L"PM";
161       _M_data->_M_am_pm_format = L"";
162
163       // Day names, starting with "C"'s Sunday.
164       _M_data->_M_day1 = L"Sunday";
165       _M_data->_M_day2 = L"Monday";
166       _M_data->_M_day3 = L"Tuesday";
167       _M_data->_M_day4 = L"Wednesday";
168       _M_data->_M_day5 = L"Thursday";
169       _M_data->_M_day6 = L"Friday";
170       _M_data->_M_day7 = L"Saturday";
171
172       // Abbreviated day names, starting with "C"'s Sun.
173       _M_data->_M_aday1 = L"Sun";
174       _M_data->_M_aday2 = L"Mon";
175       _M_data->_M_aday3 = L"Tue";
176       _M_data->_M_aday4 = L"Wed";
177       _M_data->_M_aday5 = L"Thu";
178       _M_data->_M_aday6 = L"Fri";
179       _M_data->_M_aday7 = L"Sat";
180
181       // Month names, starting with "C"'s January.
182       _M_data->_M_month01 = L"January";
183       _M_data->_M_month02 = L"February";
184       _M_data->_M_month03 = L"March";
185       _M_data->_M_month04 = L"April";
186       _M_data->_M_month05 = L"May";
187       _M_data->_M_month06 = L"June";
188       _M_data->_M_month07 = L"July";
189       _M_data->_M_month08 = L"August";
190       _M_data->_M_month09 = L"September";
191       _M_data->_M_month10 = L"October";
192       _M_data->_M_month11 = L"November";
193       _M_data->_M_month12 = L"December";
194
195       // Abbreviated month names, starting with "C"'s Jan.
196       _M_data->_M_amonth01 = L"Jan";
197       _M_data->_M_amonth02 = L"Feb";
198       _M_data->_M_amonth03 = L"Mar";
199       _M_data->_M_amonth04 = L"Apr";
200       _M_data->_M_amonth05 = L"May";
201       _M_data->_M_amonth06 = L"Jun";
202       _M_data->_M_amonth07 = L"Jul";
203       _M_data->_M_amonth08 = L"Aug";
204       _M_data->_M_amonth09 = L"Sep";
205       _M_data->_M_amonth10 = L"Oct";
206       _M_data->_M_amonth11 = L"Nov";
207       _M_data->_M_amonth12 = L"Dec";
208     }
209 #endif
210
211 _GLIBCXX_END_NAMESPACE_VERSION
212 } // namespace