]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/config/locale/generic/time_members.cc
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / 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
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 2, 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 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING.  If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
21
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction.  Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License.  This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30
31 //
32 // ISO C++ 14882: 22.2.5.1.2 - time_get virtual functions
33 // ISO C++ 14882: 22.2.5.3.2 - time_put virtual functions
34 //
35
36 // Written by Benjamin Kosnik <bkoz@redhat.com>
37
38 #include <locale>
39 #include <cstdlib>
40 #include <cstring>
41
42 _GLIBCXX_BEGIN_NAMESPACE(std)
43
44   template<>
45     void
46     __timepunct<char>::
47     _M_put(char* __s, size_t __maxlen, const char* __format, 
48            const tm* __tm) const
49     {
50       char* __old = setlocale(LC_ALL, NULL);
51       const size_t __llen = strlen(__old) + 1;
52       char* __sav = new char[__llen];
53       memcpy(__sav, __old, __llen);
54       setlocale(LC_ALL, _M_name_timepunct);
55       const size_t __len = strftime(__s, __maxlen, __format, __tm);
56       setlocale(LC_ALL, __sav);
57       delete [] __sav;
58       // Make sure __s is null terminated.
59       if (__len == 0)
60         __s[0] = '\0';
61     }
62
63   template<> 
64     void
65     __timepunct<char>::_M_initialize_timepunct(__c_locale)
66     { 
67       // "C" locale.
68       if (!_M_data)
69         _M_data = new __timepunct_cache<char>;
70
71       _M_data->_M_date_format = "%m/%d/%y";
72       _M_data->_M_date_era_format = "%m/%d/%y";
73       _M_data->_M_time_format = "%H:%M:%S";
74       _M_data->_M_time_era_format = "%H:%M:%S";
75       _M_data->_M_date_time_format = "";
76       _M_data->_M_date_time_era_format = "";
77       _M_data->_M_am = "AM";
78       _M_data->_M_pm = "PM";
79       _M_data->_M_am_pm_format = "";
80           
81       // Day names, starting with "C"'s Sunday.
82       _M_data->_M_day1 = "Sunday";
83       _M_data->_M_day2 = "Monday";
84       _M_data->_M_day3 = "Tuesday";
85       _M_data->_M_day4 = "Wednesday";
86       _M_data->_M_day5 = "Thursday";
87       _M_data->_M_day6 = "Friday";
88       _M_data->_M_day7 = "Saturday";
89
90       // Abbreviated day names, starting with "C"'s Sun.
91       _M_data->_M_aday1 = "Sun";
92       _M_data->_M_aday2 = "Mon";
93       _M_data->_M_aday3 = "Tue";
94       _M_data->_M_aday4 = "Wed";
95       _M_data->_M_aday5 = "Thu";
96       _M_data->_M_aday6 = "Fri";
97       _M_data->_M_aday7 = "Sat";
98
99       // Month names, starting with "C"'s January.
100       _M_data->_M_month01 = "January";
101       _M_data->_M_month02 = "February";
102       _M_data->_M_month03 = "March";
103       _M_data->_M_month04 = "April";
104       _M_data->_M_month05 = "May";
105       _M_data->_M_month06 = "June";
106       _M_data->_M_month07 = "July";
107       _M_data->_M_month08 = "August";
108       _M_data->_M_month09 = "September";
109       _M_data->_M_month10 = "October";
110       _M_data->_M_month11 = "November";
111       _M_data->_M_month12 = "December";
112
113       // Abbreviated month names, starting with "C"'s Jan.
114       _M_data->_M_amonth01 = "Jan";
115       _M_data->_M_amonth02 = "Feb";
116       _M_data->_M_amonth03 = "Mar";
117       _M_data->_M_amonth04 = "Apr";
118       _M_data->_M_amonth05 = "May";
119       _M_data->_M_amonth06 = "Jun";
120       _M_data->_M_amonth07 = "Jul";
121       _M_data->_M_amonth08 = "Aug";
122       _M_data->_M_amonth09 = "Sep";
123       _M_data->_M_amonth10 = "Oct";
124       _M_data->_M_amonth11 = "Nov";
125       _M_data->_M_amonth12 = "Dec";
126     }
127
128 #ifdef _GLIBCXX_USE_WCHAR_T
129   template<>
130     void
131     __timepunct<wchar_t>::
132     _M_put(wchar_t* __s, size_t __maxlen, const wchar_t* __format, 
133            const tm* __tm) const
134     {
135       char* __old = setlocale(LC_ALL, NULL);
136       const size_t __llen = strlen(__old) + 1;
137       char* __sav = new char[__llen];
138       memcpy(__sav, __old, __llen);
139       setlocale(LC_ALL, _M_name_timepunct);
140       const size_t __len = wcsftime(__s, __maxlen, __format, __tm);
141       setlocale(LC_ALL, __sav);
142       delete [] __sav;
143       // Make sure __s is null terminated.
144       if (__len == 0)
145         __s[0] = L'\0';      
146     }
147
148   template<> 
149     void
150     __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale)
151     {
152       // "C" locale.
153       if (!_M_data)
154         _M_data = new __timepunct_cache<wchar_t>;
155
156       _M_data->_M_date_format = L"%m/%d/%y";
157       _M_data->_M_date_era_format = L"%m/%d/%y";
158       _M_data->_M_time_format = L"%H:%M:%S";
159       _M_data->_M_time_era_format = L"%H:%M:%S";
160       _M_data->_M_date_time_format = L"";
161       _M_data->_M_date_time_era_format = L"";
162       _M_data->_M_am = L"AM";
163       _M_data->_M_pm = L"PM";
164       _M_data->_M_am_pm_format = L"";
165
166       // Day names, starting with "C"'s Sunday.
167       _M_data->_M_day1 = L"Sunday";
168       _M_data->_M_day2 = L"Monday";
169       _M_data->_M_day3 = L"Tuesday";
170       _M_data->_M_day4 = L"Wednesday";
171       _M_data->_M_day5 = L"Thursday";
172       _M_data->_M_day6 = L"Friday";
173       _M_data->_M_day7 = L"Saturday";
174
175       // Abbreviated day names, starting with "C"'s Sun.
176       _M_data->_M_aday1 = L"Sun";
177       _M_data->_M_aday2 = L"Mon";
178       _M_data->_M_aday3 = L"Tue";
179       _M_data->_M_aday4 = L"Wed";
180       _M_data->_M_aday5 = L"Thu";
181       _M_data->_M_aday6 = L"Fri";
182       _M_data->_M_aday7 = L"Sat";
183
184       // Month names, starting with "C"'s January.
185       _M_data->_M_month01 = L"January";
186       _M_data->_M_month02 = L"February";
187       _M_data->_M_month03 = L"March";
188       _M_data->_M_month04 = L"April";
189       _M_data->_M_month05 = L"May";
190       _M_data->_M_month06 = L"June";
191       _M_data->_M_month07 = L"July";
192       _M_data->_M_month08 = L"August";
193       _M_data->_M_month09 = L"September";
194       _M_data->_M_month10 = L"October";
195       _M_data->_M_month11 = L"November";
196       _M_data->_M_month12 = L"December";
197
198       // Abbreviated month names, starting with "C"'s Jan.
199       _M_data->_M_amonth01 = L"Jan";
200       _M_data->_M_amonth02 = L"Feb";
201       _M_data->_M_amonth03 = L"Mar";
202       _M_data->_M_amonth04 = L"Apr";
203       _M_data->_M_amonth05 = L"May";
204       _M_data->_M_amonth06 = L"Jun";
205       _M_data->_M_amonth07 = L"Jul";
206       _M_data->_M_amonth08 = L"Aug";
207       _M_data->_M_amonth09 = L"Sep";
208       _M_data->_M_amonth10 = L"Oct";
209       _M_data->_M_amonth11 = L"Nov";
210       _M_data->_M_amonth12 = L"Dec";
211     }
212 #endif
213
214 _GLIBCXX_END_NAMESPACE