]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/config/locale/generic/time_members.cc
PR libstdc++/36104 part four
[thirdparty/gcc.git] / libstdc++-v3 / config / locale / generic / time_members.cc
CommitLineData
1c26d8fd 1// std::time_get, std::time_put implementation, generic version -*- C++ -*-
1ab65677 2
32ade559 3// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010
4ba851b5 4// Free Software Foundation, Inc.
1ab65677
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)
1ab65677
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
748086b7
JJ
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/>.
1ab65677
BK
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>
4ba851b5 34#include <cstdlib>
538075fe 35#include <cstring>
1ab65677 36
12ffa228
BK
37namespace std _GLIBCXX_VISIBILITY(default)
38{
39_GLIBCXX_BEGIN_NAMESPACE_VERSION
3cbc7af0 40
da5c0f6e
BK
41 template<>
42 void
43 __timepunct<char>::
32ade559
BK
44 _M_put(char* __s, size_t __maxlen, const char* __format,
45 const tm* __tm) const throw()
da5c0f6e 46 {
445877a9 47 char* __old = setlocale(LC_ALL, 0);
538075fe
PC
48 const size_t __llen = strlen(__old) + 1;
49 char* __sav = new char[__llen];
50 memcpy(__sav, __old, __llen);
6d030676 51 setlocale(LC_ALL, _M_name_timepunct);
cb793089 52 const size_t __len = strftime(__s, __maxlen, __format, __tm);
538075fe
PC
53 setlocale(LC_ALL, __sav);
54 delete [] __sav;
cb793089
PC
55 // Make sure __s is null terminated.
56 if (__len == 0)
57 __s[0] = '\0';
da5c0f6e
BK
58 }
59
32ade559 60 template<>
1ab65677
BK
61 void
62 __timepunct<char>::_M_initialize_timepunct(__c_locale)
32ade559 63 {
fea4065d
BK
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 = "";
32ade559 77
1ab65677 78 // Day names, starting with "C"'s Sunday.
fea4065d
BK
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";
1ab65677
BK
86
87 // Abbreviated day names, starting with "C"'s Sun.
fea4065d
BK
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";
1ab65677
BK
95
96 // Month names, starting with "C"'s January.
fea4065d
BK
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";
1ab65677
BK
109
110 // Abbreviated month names, starting with "C"'s Jan.
fea4065d
BK
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";
ba98a8d8 117 _M_data->_M_amonth07 = "Jul";
fea4065d
BK
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";
1ab65677
BK
123 }
124
3d7c150e 125#ifdef _GLIBCXX_USE_WCHAR_T
da5c0f6e
BK
126 template<>
127 void
128 __timepunct<wchar_t>::
32ade559
BK
129 _M_put(wchar_t* __s, size_t __maxlen, const wchar_t* __format,
130 const tm* __tm) const throw()
da5c0f6e 131 {
445877a9 132 char* __old = setlocale(LC_ALL, 0);
538075fe
PC
133 const size_t __llen = strlen(__old) + 1;
134 char* __sav = new char[__llen];
135 memcpy(__sav, __old, __llen);
6d030676 136 setlocale(LC_ALL, _M_name_timepunct);
cb793089 137 const size_t __len = wcsftime(__s, __maxlen, __format, __tm);
538075fe
PC
138 setlocale(LC_ALL, __sav);
139 delete [] __sav;
cb793089
PC
140 // Make sure __s is null terminated.
141 if (__len == 0)
32ade559 142 __s[0] = L'\0';
da5c0f6e
BK
143 }
144
32ade559 145 template<>
1ab65677
BK
146 void
147 __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale)
da5c0f6e 148 {
fea4065d
BK
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"";
da5c0f6e
BK
162
163 // Day names, starting with "C"'s Sunday.
fea4065d
BK
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";
da5c0f6e
BK
171
172 // Abbreviated day names, starting with "C"'s Sun.
fea4065d
BK
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";
da5c0f6e
BK
180
181 // Month names, starting with "C"'s January.
fea4065d
BK
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";
da5c0f6e
BK
194
195 // Abbreviated month names, starting with "C"'s Jan.
fea4065d
BK
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";
ba98a8d8 202 _M_data->_M_amonth07 = L"Jul";
fea4065d
BK
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";
da5c0f6e 208 }
1ab65677 209#endif
3cbc7af0 210
12ffa228
BK
211_GLIBCXX_END_NAMESPACE_VERSION
212} // namespace