]>
Commit | Line | Data |
---|---|---|
1c26d8fd | 1 | // std::time_get, std::time_put implementation, generic version -*- C++ -*- |
1ab65677 | 2 | |
748086b7 | 3 | // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 |
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 | |
3cbc7af0 BK |
37 | _GLIBCXX_BEGIN_NAMESPACE(std) |
38 | ||
da5c0f6e BK |
39 | template<> |
40 | void | |
41 | __timepunct<char>:: | |
d3a193e3 BK |
42 | _M_put(char* __s, size_t __maxlen, const char* __format, |
43 | const tm* __tm) const | |
da5c0f6e | 44 | { |
538075fe PC |
45 | char* __old = setlocale(LC_ALL, NULL); |
46 | const size_t __llen = strlen(__old) + 1; | |
47 | char* __sav = new char[__llen]; | |
48 | memcpy(__sav, __old, __llen); | |
6d030676 | 49 | setlocale(LC_ALL, _M_name_timepunct); |
cb793089 | 50 | const size_t __len = strftime(__s, __maxlen, __format, __tm); |
538075fe PC |
51 | setlocale(LC_ALL, __sav); |
52 | delete [] __sav; | |
cb793089 PC |
53 | // Make sure __s is null terminated. |
54 | if (__len == 0) | |
55 | __s[0] = '\0'; | |
da5c0f6e BK |
56 | } |
57 | ||
1ab65677 BK |
58 | template<> |
59 | void | |
60 | __timepunct<char>::_M_initialize_timepunct(__c_locale) | |
61 | { | |
fea4065d BK |
62 | // "C" locale. |
63 | if (!_M_data) | |
64 | _M_data = new __timepunct_cache<char>; | |
65 | ||
66 | _M_data->_M_date_format = "%m/%d/%y"; | |
67 | _M_data->_M_date_era_format = "%m/%d/%y"; | |
68 | _M_data->_M_time_format = "%H:%M:%S"; | |
69 | _M_data->_M_time_era_format = "%H:%M:%S"; | |
70 | _M_data->_M_date_time_format = ""; | |
71 | _M_data->_M_date_time_era_format = ""; | |
72 | _M_data->_M_am = "AM"; | |
73 | _M_data->_M_pm = "PM"; | |
74 | _M_data->_M_am_pm_format = ""; | |
1ab65677 BK |
75 | |
76 | // Day names, starting with "C"'s Sunday. | |
fea4065d BK |
77 | _M_data->_M_day1 = "Sunday"; |
78 | _M_data->_M_day2 = "Monday"; | |
79 | _M_data->_M_day3 = "Tuesday"; | |
80 | _M_data->_M_day4 = "Wednesday"; | |
81 | _M_data->_M_day5 = "Thursday"; | |
82 | _M_data->_M_day6 = "Friday"; | |
83 | _M_data->_M_day7 = "Saturday"; | |
1ab65677 BK |
84 | |
85 | // Abbreviated day names, starting with "C"'s Sun. | |
fea4065d BK |
86 | _M_data->_M_aday1 = "Sun"; |
87 | _M_data->_M_aday2 = "Mon"; | |
88 | _M_data->_M_aday3 = "Tue"; | |
89 | _M_data->_M_aday4 = "Wed"; | |
90 | _M_data->_M_aday5 = "Thu"; | |
91 | _M_data->_M_aday6 = "Fri"; | |
92 | _M_data->_M_aday7 = "Sat"; | |
1ab65677 BK |
93 | |
94 | // Month names, starting with "C"'s January. | |
fea4065d BK |
95 | _M_data->_M_month01 = "January"; |
96 | _M_data->_M_month02 = "February"; | |
97 | _M_data->_M_month03 = "March"; | |
98 | _M_data->_M_month04 = "April"; | |
99 | _M_data->_M_month05 = "May"; | |
100 | _M_data->_M_month06 = "June"; | |
101 | _M_data->_M_month07 = "July"; | |
102 | _M_data->_M_month08 = "August"; | |
103 | _M_data->_M_month09 = "September"; | |
104 | _M_data->_M_month10 = "October"; | |
105 | _M_data->_M_month11 = "November"; | |
106 | _M_data->_M_month12 = "December"; | |
1ab65677 BK |
107 | |
108 | // Abbreviated month names, starting with "C"'s Jan. | |
fea4065d BK |
109 | _M_data->_M_amonth01 = "Jan"; |
110 | _M_data->_M_amonth02 = "Feb"; | |
111 | _M_data->_M_amonth03 = "Mar"; | |
112 | _M_data->_M_amonth04 = "Apr"; | |
113 | _M_data->_M_amonth05 = "May"; | |
114 | _M_data->_M_amonth06 = "Jun"; | |
ba98a8d8 | 115 | _M_data->_M_amonth07 = "Jul"; |
fea4065d BK |
116 | _M_data->_M_amonth08 = "Aug"; |
117 | _M_data->_M_amonth09 = "Sep"; | |
118 | _M_data->_M_amonth10 = "Oct"; | |
119 | _M_data->_M_amonth11 = "Nov"; | |
120 | _M_data->_M_amonth12 = "Dec"; | |
1ab65677 BK |
121 | } |
122 | ||
3d7c150e | 123 | #ifdef _GLIBCXX_USE_WCHAR_T |
da5c0f6e BK |
124 | template<> |
125 | void | |
126 | __timepunct<wchar_t>:: | |
d3a193e3 BK |
127 | _M_put(wchar_t* __s, size_t __maxlen, const wchar_t* __format, |
128 | const tm* __tm) const | |
da5c0f6e | 129 | { |
538075fe PC |
130 | char* __old = setlocale(LC_ALL, NULL); |
131 | const size_t __llen = strlen(__old) + 1; | |
132 | char* __sav = new char[__llen]; | |
133 | memcpy(__sav, __old, __llen); | |
6d030676 | 134 | setlocale(LC_ALL, _M_name_timepunct); |
cb793089 | 135 | const size_t __len = wcsftime(__s, __maxlen, __format, __tm); |
538075fe PC |
136 | setlocale(LC_ALL, __sav); |
137 | delete [] __sav; | |
cb793089 PC |
138 | // Make sure __s is null terminated. |
139 | if (__len == 0) | |
140 | __s[0] = L'\0'; | |
da5c0f6e BK |
141 | } |
142 | ||
1ab65677 BK |
143 | template<> |
144 | void | |
145 | __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale) | |
da5c0f6e | 146 | { |
fea4065d BK |
147 | // "C" locale. |
148 | if (!_M_data) | |
149 | _M_data = new __timepunct_cache<wchar_t>; | |
150 | ||
151 | _M_data->_M_date_format = L"%m/%d/%y"; | |
152 | _M_data->_M_date_era_format = L"%m/%d/%y"; | |
153 | _M_data->_M_time_format = L"%H:%M:%S"; | |
154 | _M_data->_M_time_era_format = L"%H:%M:%S"; | |
155 | _M_data->_M_date_time_format = L""; | |
156 | _M_data->_M_date_time_era_format = L""; | |
157 | _M_data->_M_am = L"AM"; | |
158 | _M_data->_M_pm = L"PM"; | |
159 | _M_data->_M_am_pm_format = L""; | |
da5c0f6e BK |
160 | |
161 | // Day names, starting with "C"'s Sunday. | |
fea4065d BK |
162 | _M_data->_M_day1 = L"Sunday"; |
163 | _M_data->_M_day2 = L"Monday"; | |
164 | _M_data->_M_day3 = L"Tuesday"; | |
165 | _M_data->_M_day4 = L"Wednesday"; | |
166 | _M_data->_M_day5 = L"Thursday"; | |
167 | _M_data->_M_day6 = L"Friday"; | |
168 | _M_data->_M_day7 = L"Saturday"; | |
da5c0f6e BK |
169 | |
170 | // Abbreviated day names, starting with "C"'s Sun. | |
fea4065d BK |
171 | _M_data->_M_aday1 = L"Sun"; |
172 | _M_data->_M_aday2 = L"Mon"; | |
173 | _M_data->_M_aday3 = L"Tue"; | |
174 | _M_data->_M_aday4 = L"Wed"; | |
175 | _M_data->_M_aday5 = L"Thu"; | |
176 | _M_data->_M_aday6 = L"Fri"; | |
177 | _M_data->_M_aday7 = L"Sat"; | |
da5c0f6e BK |
178 | |
179 | // Month names, starting with "C"'s January. | |
fea4065d BK |
180 | _M_data->_M_month01 = L"January"; |
181 | _M_data->_M_month02 = L"February"; | |
182 | _M_data->_M_month03 = L"March"; | |
183 | _M_data->_M_month04 = L"April"; | |
184 | _M_data->_M_month05 = L"May"; | |
185 | _M_data->_M_month06 = L"June"; | |
186 | _M_data->_M_month07 = L"July"; | |
187 | _M_data->_M_month08 = L"August"; | |
188 | _M_data->_M_month09 = L"September"; | |
189 | _M_data->_M_month10 = L"October"; | |
190 | _M_data->_M_month11 = L"November"; | |
191 | _M_data->_M_month12 = L"December"; | |
da5c0f6e BK |
192 | |
193 | // Abbreviated month names, starting with "C"'s Jan. | |
fea4065d BK |
194 | _M_data->_M_amonth01 = L"Jan"; |
195 | _M_data->_M_amonth02 = L"Feb"; | |
196 | _M_data->_M_amonth03 = L"Mar"; | |
197 | _M_data->_M_amonth04 = L"Apr"; | |
198 | _M_data->_M_amonth05 = L"May"; | |
199 | _M_data->_M_amonth06 = L"Jun"; | |
ba98a8d8 | 200 | _M_data->_M_amonth07 = L"Jul"; |
fea4065d BK |
201 | _M_data->_M_amonth08 = L"Aug"; |
202 | _M_data->_M_amonth09 = L"Sep"; | |
203 | _M_data->_M_amonth10 = L"Oct"; | |
204 | _M_data->_M_amonth11 = L"Nov"; | |
205 | _M_data->_M_amonth12 = L"Dec"; | |
da5c0f6e | 206 | } |
1ab65677 | 207 | #endif |
3cbc7af0 BK |
208 | |
209 | _GLIBCXX_END_NAMESPACE |