]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/config/locale/gnu/time_members.cc
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / config / locale / gnu / time_members.cc
CommitLineData
1ab65677
BK
1// std::time_get, std::time_put implementation, GNU version -*- C++ -*-
2
aa118a03 3// Copyright (C) 2001-2014 Free Software Foundation, Inc.
1ab65677
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
1ab65677
BK
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
748086b7
JJ
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
1ab65677 19
748086b7
JJ
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
1ab65677
BK
24
25//
26// ISO C++ 14882: 22.2.5.1.2 - time_get virtual functions
27// ISO C++ 14882: 22.2.5.3.2 - time_put virtual functions
28//
29
30// Written by Benjamin Kosnik <bkoz@redhat.com>
31
32#include <locale>
6aa43d99 33#include <bits/c++locale_internal.h>
1ab65677 34
12ffa228
BK
35namespace std _GLIBCXX_VISIBILITY(default)
36{
37_GLIBCXX_BEGIN_NAMESPACE_VERSION
3cbc7af0 38
da5c0f6e
BK
39 template<>
40 void
41 __timepunct<char>::
d3a193e3 42 _M_put(char* __s, size_t __maxlen, const char* __format,
32ade559 43 const tm* __tm) const throw()
da5c0f6e 44 {
99ffa1e3 45#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
cb793089
PC
46 const size_t __len = __strftime_l(__s, __maxlen, __format, __tm,
47 _M_c_locale_timepunct);
da5c0f6e 48#else
445877a9 49 char* __old = setlocale(LC_ALL, 0);
538075fe
PC
50 const size_t __llen = strlen(__old) + 1;
51 char* __sav = new char[__llen];
52 memcpy(__sav, __old, __llen);
6d030676 53 setlocale(LC_ALL, _M_name_timepunct);
cb793089 54 const size_t __len = strftime(__s, __maxlen, __format, __tm);
538075fe
PC
55 setlocale(LC_ALL, __sav);
56 delete [] __sav;
da5c0f6e 57#endif
cb793089
PC
58 // Make sure __s is null terminated.
59 if (__len == 0)
60 __s[0] = '\0';
da5c0f6e
BK
61 }
62
1ab65677
BK
63 template<>
64 void
65 __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc)
66 {
fea4065d
BK
67 if (!_M_data)
68 _M_data = new __timepunct_cache<char>;
69
aa53f832 70 if (!__cloc)
1ab65677
BK
71 {
72 // "C" locale
8ae81136 73 _M_c_locale_timepunct = _S_get_c_locale();
89671b70 74
fea4065d
BK
75 _M_data->_M_date_format = "%m/%d/%y";
76 _M_data->_M_date_era_format = "%m/%d/%y";
77 _M_data->_M_time_format = "%H:%M:%S";
78 _M_data->_M_time_era_format = "%H:%M:%S";
79 _M_data->_M_date_time_format = "";
80 _M_data->_M_date_time_era_format = "";
81 _M_data->_M_am = "AM";
82 _M_data->_M_pm = "PM";
83 _M_data->_M_am_pm_format = "";
da5c0f6e 84
1ab65677 85 // Day names, starting with "C"'s Sunday.
fea4065d
BK
86 _M_data->_M_day1 = "Sunday";
87 _M_data->_M_day2 = "Monday";
88 _M_data->_M_day3 = "Tuesday";
89 _M_data->_M_day4 = "Wednesday";
90 _M_data->_M_day5 = "Thursday";
91 _M_data->_M_day6 = "Friday";
92 _M_data->_M_day7 = "Saturday";
1ab65677
BK
93
94 // Abbreviated day names, starting with "C"'s Sun.
fea4065d
BK
95 _M_data->_M_aday1 = "Sun";
96 _M_data->_M_aday2 = "Mon";
97 _M_data->_M_aday3 = "Tue";
98 _M_data->_M_aday4 = "Wed";
99 _M_data->_M_aday5 = "Thu";
100 _M_data->_M_aday6 = "Fri";
101 _M_data->_M_aday7 = "Sat";
1ab65677
BK
102
103 // Month names, starting with "C"'s January.
fea4065d
BK
104 _M_data->_M_month01 = "January";
105 _M_data->_M_month02 = "February";
106 _M_data->_M_month03 = "March";
107 _M_data->_M_month04 = "April";
108 _M_data->_M_month05 = "May";
109 _M_data->_M_month06 = "June";
110 _M_data->_M_month07 = "July";
111 _M_data->_M_month08 = "August";
112 _M_data->_M_month09 = "September";
113 _M_data->_M_month10 = "October";
114 _M_data->_M_month11 = "November";
115 _M_data->_M_month12 = "December";
1ab65677
BK
116
117 // Abbreviated month names, starting with "C"'s Jan.
fea4065d
BK
118 _M_data->_M_amonth01 = "Jan";
119 _M_data->_M_amonth02 = "Feb";
120 _M_data->_M_amonth03 = "Mar";
121 _M_data->_M_amonth04 = "Apr";
122 _M_data->_M_amonth05 = "May";
123 _M_data->_M_amonth06 = "Jun";
ba98a8d8 124 _M_data->_M_amonth07 = "Jul";
fea4065d
BK
125 _M_data->_M_amonth08 = "Aug";
126 _M_data->_M_amonth09 = "Sep";
127 _M_data->_M_amonth10 = "Oct";
128 _M_data->_M_amonth11 = "Nov";
129 _M_data->_M_amonth12 = "Dec";
1ab65677
BK
130 }
131 else
132 {
133 _M_c_locale_timepunct = _S_clone_c_locale(__cloc);
134
fea4065d
BK
135 _M_data->_M_date_format = __nl_langinfo_l(D_FMT, __cloc);
136 _M_data->_M_date_era_format = __nl_langinfo_l(ERA_D_FMT, __cloc);
137 _M_data->_M_time_format = __nl_langinfo_l(T_FMT, __cloc);
138 _M_data->_M_time_era_format = __nl_langinfo_l(ERA_T_FMT, __cloc);
139 _M_data->_M_date_time_format = __nl_langinfo_l(D_T_FMT, __cloc);
a80e0e83
PC
140 _M_data->_M_date_time_era_format = __nl_langinfo_l(ERA_D_T_FMT,
141 __cloc);
fea4065d
BK
142 _M_data->_M_am = __nl_langinfo_l(AM_STR, __cloc);
143 _M_data->_M_pm = __nl_langinfo_l(PM_STR, __cloc);
144 _M_data->_M_am_pm_format = __nl_langinfo_l(T_FMT_AMPM, __cloc);
1ab65677
BK
145
146 // Day names, starting with "C"'s Sunday.
fea4065d
BK
147 _M_data->_M_day1 = __nl_langinfo_l(DAY_1, __cloc);
148 _M_data->_M_day2 = __nl_langinfo_l(DAY_2, __cloc);
149 _M_data->_M_day3 = __nl_langinfo_l(DAY_3, __cloc);
150 _M_data->_M_day4 = __nl_langinfo_l(DAY_4, __cloc);
151 _M_data->_M_day5 = __nl_langinfo_l(DAY_5, __cloc);
152 _M_data->_M_day6 = __nl_langinfo_l(DAY_6, __cloc);
153 _M_data->_M_day7 = __nl_langinfo_l(DAY_7, __cloc);
1ab65677
BK
154
155 // Abbreviated day names, starting with "C"'s Sun.
fea4065d
BK
156 _M_data->_M_aday1 = __nl_langinfo_l(ABDAY_1, __cloc);
157 _M_data->_M_aday2 = __nl_langinfo_l(ABDAY_2, __cloc);
158 _M_data->_M_aday3 = __nl_langinfo_l(ABDAY_3, __cloc);
159 _M_data->_M_aday4 = __nl_langinfo_l(ABDAY_4, __cloc);
160 _M_data->_M_aday5 = __nl_langinfo_l(ABDAY_5, __cloc);
161 _M_data->_M_aday6 = __nl_langinfo_l(ABDAY_6, __cloc);
162 _M_data->_M_aday7 = __nl_langinfo_l(ABDAY_7, __cloc);
1ab65677
BK
163
164 // Month names, starting with "C"'s January.
fea4065d
BK
165 _M_data->_M_month01 = __nl_langinfo_l(MON_1, __cloc);
166 _M_data->_M_month02 = __nl_langinfo_l(MON_2, __cloc);
167 _M_data->_M_month03 = __nl_langinfo_l(MON_3, __cloc);
168 _M_data->_M_month04 = __nl_langinfo_l(MON_4, __cloc);
169 _M_data->_M_month05 = __nl_langinfo_l(MON_5, __cloc);
170 _M_data->_M_month06 = __nl_langinfo_l(MON_6, __cloc);
171 _M_data->_M_month07 = __nl_langinfo_l(MON_7, __cloc);
172 _M_data->_M_month08 = __nl_langinfo_l(MON_8, __cloc);
173 _M_data->_M_month09 = __nl_langinfo_l(MON_9, __cloc);
174 _M_data->_M_month10 = __nl_langinfo_l(MON_10, __cloc);
175 _M_data->_M_month11 = __nl_langinfo_l(MON_11, __cloc);
176 _M_data->_M_month12 = __nl_langinfo_l(MON_12, __cloc);
1ab65677
BK
177
178 // Abbreviated month names, starting with "C"'s Jan.
fea4065d
BK
179 _M_data->_M_amonth01 = __nl_langinfo_l(ABMON_1, __cloc);
180 _M_data->_M_amonth02 = __nl_langinfo_l(ABMON_2, __cloc);
181 _M_data->_M_amonth03 = __nl_langinfo_l(ABMON_3, __cloc);
182 _M_data->_M_amonth04 = __nl_langinfo_l(ABMON_4, __cloc);
183 _M_data->_M_amonth05 = __nl_langinfo_l(ABMON_5, __cloc);
184 _M_data->_M_amonth06 = __nl_langinfo_l(ABMON_6, __cloc);
185 _M_data->_M_amonth07 = __nl_langinfo_l(ABMON_7, __cloc);
186 _M_data->_M_amonth08 = __nl_langinfo_l(ABMON_8, __cloc);
187 _M_data->_M_amonth09 = __nl_langinfo_l(ABMON_9, __cloc);
188 _M_data->_M_amonth10 = __nl_langinfo_l(ABMON_10, __cloc);
189 _M_data->_M_amonth11 = __nl_langinfo_l(ABMON_11, __cloc);
190 _M_data->_M_amonth12 = __nl_langinfo_l(ABMON_12, __cloc);
1ab65677
BK
191 }
192 }
193
3d7c150e 194#ifdef _GLIBCXX_USE_WCHAR_T
da5c0f6e
BK
195 template<>
196 void
197 __timepunct<wchar_t>::
d3a193e3 198 _M_put(wchar_t* __s, size_t __maxlen, const wchar_t* __format,
32ade559 199 const tm* __tm) const throw()
da5c0f6e 200 {
99ffa1e3 201#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
cb793089
PC
202 const size_t __len = __wcsftime_l(__s, __maxlen, __format, __tm,
203 _M_c_locale_timepunct);
da5c0f6e 204#else
445877a9 205 char* __old = setlocale(LC_ALL, 0);
538075fe
PC
206 const size_t __llen = strlen(__old) + 1;
207 char* __sav = new char[__llen];
208 memcpy(__sav, __old, __llen);
6d030676 209 setlocale(LC_ALL, _M_name_timepunct);
cb793089 210 const size_t __len = wcsftime(__s, __maxlen, __format, __tm);
538075fe
PC
211 setlocale(LC_ALL, __sav);
212 delete [] __sav;
da5c0f6e 213#endif
cb793089
PC
214 // Make sure __s is null terminated.
215 if (__len == 0)
216 __s[0] = L'\0';
da5c0f6e
BK
217 }
218
1ab65677
BK
219 template<>
220 void
221 __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc)
222 {
fea4065d
BK
223 if (!_M_data)
224 _M_data = new __timepunct_cache<wchar_t>;
225
aa53f832 226 if (!__cloc)
1ab65677
BK
227 {
228 // "C" locale
8ae81136 229 _M_c_locale_timepunct = _S_get_c_locale();
89671b70 230
fea4065d
BK
231 _M_data->_M_date_format = L"%m/%d/%y";
232 _M_data->_M_date_era_format = L"%m/%d/%y";
233 _M_data->_M_time_format = L"%H:%M:%S";
234 _M_data->_M_time_era_format = L"%H:%M:%S";
235 _M_data->_M_date_time_format = L"";
236 _M_data->_M_date_time_era_format = L"";
237 _M_data->_M_am = L"AM";
238 _M_data->_M_pm = L"PM";
239 _M_data->_M_am_pm_format = L"";
da5c0f6e
BK
240
241 // Day names, starting with "C"'s Sunday.
fea4065d
BK
242 _M_data->_M_day1 = L"Sunday";
243 _M_data->_M_day2 = L"Monday";
244 _M_data->_M_day3 = L"Tuesday";
245 _M_data->_M_day4 = L"Wednesday";
246 _M_data->_M_day5 = L"Thursday";
247 _M_data->_M_day6 = L"Friday";
248 _M_data->_M_day7 = L"Saturday";
da5c0f6e
BK
249
250 // Abbreviated day names, starting with "C"'s Sun.
fea4065d
BK
251 _M_data->_M_aday1 = L"Sun";
252 _M_data->_M_aday2 = L"Mon";
253 _M_data->_M_aday3 = L"Tue";
254 _M_data->_M_aday4 = L"Wed";
255 _M_data->_M_aday5 = L"Thu";
256 _M_data->_M_aday6 = L"Fri";
257 _M_data->_M_aday7 = L"Sat";
da5c0f6e
BK
258
259 // Month names, starting with "C"'s January.
fea4065d
BK
260 _M_data->_M_month01 = L"January";
261 _M_data->_M_month02 = L"February";
262 _M_data->_M_month03 = L"March";
263 _M_data->_M_month04 = L"April";
264 _M_data->_M_month05 = L"May";
265 _M_data->_M_month06 = L"June";
266 _M_data->_M_month07 = L"July";
267 _M_data->_M_month08 = L"August";
268 _M_data->_M_month09 = L"September";
269 _M_data->_M_month10 = L"October";
270 _M_data->_M_month11 = L"November";
271 _M_data->_M_month12 = L"December";
da5c0f6e
BK
272
273 // Abbreviated month names, starting with "C"'s Jan.
fea4065d
BK
274 _M_data->_M_amonth01 = L"Jan";
275 _M_data->_M_amonth02 = L"Feb";
276 _M_data->_M_amonth03 = L"Mar";
277 _M_data->_M_amonth04 = L"Apr";
278 _M_data->_M_amonth05 = L"May";
279 _M_data->_M_amonth06 = L"Jun";
ba98a8d8 280 _M_data->_M_amonth07 = L"Jul";
fea4065d
BK
281 _M_data->_M_amonth08 = L"Aug";
282 _M_data->_M_amonth09 = L"Sep";
283 _M_data->_M_amonth10 = L"Oct";
284 _M_data->_M_amonth11 = L"Nov";
285 _M_data->_M_amonth12 = L"Dec";
1ab65677
BK
286 }
287 else
288 {
289 _M_c_locale_timepunct = _S_clone_c_locale(__cloc);
da5c0f6e 290
a80e0e83
PC
291 union { char *__s; wchar_t *__w; } __u;
292
293 __u.__s = __nl_langinfo_l(_NL_WD_FMT, __cloc);
294 _M_data->_M_date_format = __u.__w;
295 __u.__s = __nl_langinfo_l(_NL_WERA_D_FMT, __cloc);
296 _M_data->_M_date_era_format = __u.__w;
297 __u.__s = __nl_langinfo_l(_NL_WT_FMT, __cloc);
298 _M_data->_M_time_format = __u.__w;
299 __u.__s = __nl_langinfo_l(_NL_WERA_T_FMT, __cloc);
300 _M_data->_M_time_era_format = __u.__w;
301 __u.__s = __nl_langinfo_l(_NL_WD_T_FMT, __cloc);
302 _M_data->_M_date_time_format = __u.__w;
303 __u.__s = __nl_langinfo_l(_NL_WERA_D_T_FMT, __cloc);
304 _M_data->_M_date_time_era_format = __u.__w;
305 __u.__s = __nl_langinfo_l(_NL_WAM_STR, __cloc);
306 _M_data->_M_am = __u.__w;
307 __u.__s = __nl_langinfo_l(_NL_WPM_STR, __cloc);
308 _M_data->_M_pm = __u.__w;
309 __u.__s = __nl_langinfo_l(_NL_WT_FMT_AMPM, __cloc);
310 _M_data->_M_am_pm_format = __u.__w;
da5c0f6e
BK
311
312 // Day names, starting with "C"'s Sunday.
a80e0e83
PC
313 __u.__s = __nl_langinfo_l(_NL_WDAY_1, __cloc);
314 _M_data->_M_day1 = __u.__w;
315 __u.__s = __nl_langinfo_l(_NL_WDAY_2, __cloc);
316 _M_data->_M_day2 = __u.__w;
317 __u.__s = __nl_langinfo_l(_NL_WDAY_3, __cloc);
318 _M_data->_M_day3 = __u.__w;
319 __u.__s = __nl_langinfo_l(_NL_WDAY_4, __cloc);
320 _M_data->_M_day4 = __u.__w;
321 __u.__s = __nl_langinfo_l(_NL_WDAY_5, __cloc);
322 _M_data->_M_day5 = __u.__w;
323 __u.__s = __nl_langinfo_l(_NL_WDAY_6, __cloc);
324 _M_data->_M_day6 = __u.__w;
325 __u.__s = __nl_langinfo_l(_NL_WDAY_7, __cloc);
326 _M_data->_M_day7 = __u.__w;
da5c0f6e
BK
327
328 // Abbreviated day names, starting with "C"'s Sun.
a80e0e83
PC
329 __u.__s = __nl_langinfo_l(_NL_WABDAY_1, __cloc);
330 _M_data->_M_aday1 = __u.__w;
331 __u.__s = __nl_langinfo_l(_NL_WABDAY_2, __cloc);
332 _M_data->_M_aday2 = __u.__w;
333 __u.__s = __nl_langinfo_l(_NL_WABDAY_3, __cloc);
334 _M_data->_M_aday3 = __u.__w;
335 __u.__s = __nl_langinfo_l(_NL_WABDAY_4, __cloc);
336 _M_data->_M_aday4 = __u.__w;
337 __u.__s = __nl_langinfo_l(_NL_WABDAY_5, __cloc);
338 _M_data->_M_aday5 = __u.__w;
339 __u.__s = __nl_langinfo_l(_NL_WABDAY_6, __cloc);
340 _M_data->_M_aday6 = __u.__w;
341 __u.__s = __nl_langinfo_l(_NL_WABDAY_7, __cloc);
342 _M_data->_M_aday7 = __u.__w;
da5c0f6e
BK
343
344 // Month names, starting with "C"'s January.
a80e0e83
PC
345 __u.__s = __nl_langinfo_l(_NL_WMON_1, __cloc);
346 _M_data->_M_month01 = __u.__w;
347 __u.__s = __nl_langinfo_l(_NL_WMON_2, __cloc);
348 _M_data->_M_month02 = __u.__w;
349 __u.__s = __nl_langinfo_l(_NL_WMON_3, __cloc);
350 _M_data->_M_month03 = __u.__w;
351 __u.__s = __nl_langinfo_l(_NL_WMON_4, __cloc);
352 _M_data->_M_month04 = __u.__w;
353 __u.__s = __nl_langinfo_l(_NL_WMON_5, __cloc);
354 _M_data->_M_month05 = __u.__w;
355 __u.__s = __nl_langinfo_l(_NL_WMON_6, __cloc);
356 _M_data->_M_month06 = __u.__w;
357 __u.__s = __nl_langinfo_l(_NL_WMON_7, __cloc);
358 _M_data->_M_month07 = __u.__w;
359 __u.__s = __nl_langinfo_l(_NL_WMON_8, __cloc);
360 _M_data->_M_month08 = __u.__w;
361 __u.__s = __nl_langinfo_l(_NL_WMON_9, __cloc);
362 _M_data->_M_month09 = __u.__w;
363 __u.__s = __nl_langinfo_l(_NL_WMON_10, __cloc);
364 _M_data->_M_month10 = __u.__w;
365 __u.__s = __nl_langinfo_l(_NL_WMON_11, __cloc);
366 _M_data->_M_month11 = __u.__w;
367 __u.__s = __nl_langinfo_l(_NL_WMON_12, __cloc);
368 _M_data->_M_month12 = __u.__w;
da5c0f6e
BK
369
370 // Abbreviated month names, starting with "C"'s Jan.
a80e0e83
PC
371 __u.__s = __nl_langinfo_l(_NL_WABMON_1, __cloc);
372 _M_data->_M_amonth01 = __u.__w;
373 __u.__s = __nl_langinfo_l(_NL_WABMON_2, __cloc);
374 _M_data->_M_amonth02 = __u.__w;
375 __u.__s = __nl_langinfo_l(_NL_WABMON_3, __cloc);
376 _M_data->_M_amonth03 = __u.__w;
377 __u.__s = __nl_langinfo_l(_NL_WABMON_4, __cloc);
378 _M_data->_M_amonth04 = __u.__w;
379 __u.__s = __nl_langinfo_l(_NL_WABMON_5, __cloc);
380 _M_data->_M_amonth05 = __u.__w;
381 __u.__s = __nl_langinfo_l(_NL_WABMON_6, __cloc);
382 _M_data->_M_amonth06 = __u.__w;
383 __u.__s = __nl_langinfo_l(_NL_WABMON_7, __cloc);
384 _M_data->_M_amonth07 = __u.__w;
385 __u.__s = __nl_langinfo_l(_NL_WABMON_8, __cloc);
386 _M_data->_M_amonth08 = __u.__w;
387 __u.__s = __nl_langinfo_l(_NL_WABMON_9, __cloc);
388 _M_data->_M_amonth09 = __u.__w;
389 __u.__s = __nl_langinfo_l(_NL_WABMON_10, __cloc);
390 _M_data->_M_amonth10 = __u.__w;
391 __u.__s = __nl_langinfo_l(_NL_WABMON_11, __cloc);
392 _M_data->_M_amonth11 = __u.__w;
393 __u.__s = __nl_langinfo_l(_NL_WABMON_12, __cloc);
394 _M_data->_M_amonth12 = __u.__w;
1ab65677
BK
395 }
396 }
397#endif
3cbc7af0 398
12ffa228
BK
399_GLIBCXX_END_NAMESPACE_VERSION
400} // namespace