williamr@4
|
1 |
/*
|
williamr@4
|
2 |
* Copyright (c) 1999
|
williamr@4
|
3 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@4
|
4 |
*
|
williamr@4
|
5 |
* Copyright (c) 1999
|
williamr@4
|
6 |
* Boris Fomitchev
|
williamr@4
|
7 |
*
|
williamr@4
|
8 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@4
|
9 |
* or implied. Any use is at your own risk.
|
williamr@4
|
10 |
*
|
williamr@4
|
11 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@4
|
12 |
* without fee, provided the above notices are retained on all copies.
|
williamr@4
|
13 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@4
|
14 |
* provided the above notices are retained, and a notice that the code was
|
williamr@4
|
15 |
* modified is included with the above copyright notice.
|
williamr@4
|
16 |
*
|
williamr@4
|
17 |
*/
|
williamr@4
|
18 |
#ifndef _STLP_TIME_FACETS_C
|
williamr@4
|
19 |
#define _STLP_TIME_FACETS_C
|
williamr@4
|
20 |
|
williamr@4
|
21 |
#ifndef _STLP_INTERNAL_TIME_FACETS_H
|
williamr@4
|
22 |
# include <stl/_time_facets.h>
|
williamr@4
|
23 |
#endif
|
williamr@4
|
24 |
|
williamr@4
|
25 |
#ifndef _STLP_INTERNAL_NUM_PUT_H
|
williamr@4
|
26 |
# include <stl/_num_put.h>
|
williamr@4
|
27 |
#endif
|
williamr@4
|
28 |
|
williamr@4
|
29 |
#ifndef _STLP_INTERNAL_NUM_GET_H
|
williamr@4
|
30 |
# include <stl/_num_get.h>
|
williamr@4
|
31 |
#endif
|
williamr@4
|
32 |
|
williamr@4
|
33 |
_STLP_BEGIN_NAMESPACE
|
williamr@4
|
34 |
|
williamr@4
|
35 |
//----------------------------------------------------------------------
|
williamr@4
|
36 |
// Declarations of static template members.
|
williamr@4
|
37 |
#if (_STLP_STATIC_TEMPLATE_DATA > 0)
|
williamr@4
|
38 |
|
williamr@4
|
39 |
# if !defined (__BORLANDC__)
|
williamr@4
|
40 |
template <class _CharT, class _InputIterator>
|
williamr@4
|
41 |
locale::id time_get<_CharT, _InputIterator>::id;
|
williamr@4
|
42 |
|
williamr@4
|
43 |
template <class _CharT, class _OutputIterator>
|
williamr@4
|
44 |
locale::id time_put<_CharT, _OutputIterator>::id;
|
williamr@4
|
45 |
# endif
|
williamr@4
|
46 |
|
williamr@4
|
47 |
# if (defined (__CYGWIN__) || defined (__MINGW32__)) && \
|
williamr@4
|
48 |
defined (_STLP_USE_DYNAMIC_LIB) && !defined (__BUILDING_STLPORT)
|
williamr@4
|
49 |
/*
|
williamr@4
|
50 |
* Under cygwin, when STLport is used as a shared library, the id needs
|
williamr@4
|
51 |
* to be specified as imported otherwise they will be duplicated in the
|
williamr@4
|
52 |
* calling executable.
|
williamr@4
|
53 |
*/
|
williamr@4
|
54 |
template <>
|
williamr@4
|
55 |
_STLP_DECLSPEC locale::id time_get<char, istreambuf_iterator<char, char_traits<char> > >::id;
|
williamr@4
|
56 |
/*
|
williamr@4
|
57 |
template <>
|
williamr@4
|
58 |
_STLP_DECLSPEC locale::id time_get<char, const char*>::id;
|
williamr@4
|
59 |
*/
|
williamr@4
|
60 |
|
williamr@4
|
61 |
template <>
|
williamr@4
|
62 |
_STLP_DECLSPEC locale::id time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
|
williamr@4
|
63 |
/*
|
williamr@4
|
64 |
template <>
|
williamr@4
|
65 |
_STLP_DECLSPEC locale::id time_put<char, char*>::id;
|
williamr@4
|
66 |
*/
|
williamr@4
|
67 |
|
williamr@4
|
68 |
# ifndef _STLP_NO_WCHAR_T
|
williamr@4
|
69 |
template <>
|
williamr@4
|
70 |
_STLP_DECLSPEC locale::id time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
|
williamr@4
|
71 |
/*
|
williamr@4
|
72 |
template <>
|
williamr@4
|
73 |
_STLP_DECLSPEC locale::id time_get<wchar_t, const wchar_t*>::id;
|
williamr@4
|
74 |
*/
|
williamr@4
|
75 |
|
williamr@4
|
76 |
template <>
|
williamr@4
|
77 |
_STLP_DECLSPEC locale::id time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
|
williamr@4
|
78 |
/*
|
williamr@4
|
79 |
template <>
|
williamr@4
|
80 |
_STLP_DECLSPEC locale::id time_put<wchar_t, wchar_t*>::id;
|
williamr@4
|
81 |
*/
|
williamr@4
|
82 |
# endif /* _STLP_NO_WCHAR_T */
|
williamr@4
|
83 |
# endif /* __CUGWIN__ && _STLP_USE_DYNAMIC_LIB */
|
williamr@4
|
84 |
|
williamr@4
|
85 |
#else /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
|
williamr@4
|
86 |
|
williamr@4
|
87 |
//typedef time_get<char, const char*> time_get_char;
|
williamr@4
|
88 |
typedef time_get<char, istreambuf_iterator<char, char_traits<char> > > time_get_char_2;
|
williamr@4
|
89 |
//typedef time_put<char, char*> time_put_char;
|
williamr@4
|
90 |
typedef time_put<char, ostreambuf_iterator<char, char_traits<char> > > time_put_char_2;
|
williamr@4
|
91 |
|
williamr@4
|
92 |
//__DECLARE_INSTANCE(locale::id, time_get_char::id, );
|
williamr@4
|
93 |
__DECLARE_INSTANCE(locale::id, time_get_char_2::id, );
|
williamr@4
|
94 |
//__DECLARE_INSTANCE(locale::id, time_put_char::id, );
|
williamr@4
|
95 |
__DECLARE_INSTANCE(locale::id, time_put_char_2::id, );
|
williamr@4
|
96 |
|
williamr@4
|
97 |
# if !defined (_STLP_NO_WCHAR_T)
|
williamr@4
|
98 |
|
williamr@4
|
99 |
//typedef time_get<wchar_t, const wchar_t*> time_get_wchar_t;
|
williamr@4
|
100 |
typedef time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > > time_get_wchar_t_2;
|
williamr@4
|
101 |
//typedef time_put<wchar_t, wchar_t*> time_put_wchar_t;
|
williamr@4
|
102 |
typedef time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > time_put_wchar_t_2;
|
williamr@4
|
103 |
|
williamr@4
|
104 |
//__DECLARE_INSTANCE(locale::id, time_get_wchar_t::id, );
|
williamr@4
|
105 |
__DECLARE_INSTANCE(locale::id, time_get_wchar_t_2::id, );
|
williamr@4
|
106 |
//__DECLARE_INSTANCE(locale::id, time_put_wchar_t::id, );
|
williamr@4
|
107 |
__DECLARE_INSTANCE(locale::id, time_put_wchar_t_2::id, );
|
williamr@4
|
108 |
|
williamr@4
|
109 |
# endif
|
williamr@4
|
110 |
|
williamr@4
|
111 |
#endif /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
|
williamr@4
|
112 |
|
williamr@4
|
113 |
_STLP_MOVE_TO_PRIV_NAMESPACE
|
williamr@4
|
114 |
|
williamr@4
|
115 |
template <class _InIt, class _CharT>
|
williamr@4
|
116 |
const string* _STLP_CALL
|
williamr@4
|
117 |
__match(_InIt& __first, _InIt& __last, const string *__name, const string *__name_end,
|
williamr@4
|
118 |
const ctype<_CharT>& __ct) {
|
williamr@4
|
119 |
typedef ptrdiff_t difference_type;
|
williamr@4
|
120 |
difference_type __n = __name_end - __name;
|
williamr@4
|
121 |
difference_type __i;
|
williamr@4
|
122 |
size_t __pos = 0;
|
williamr@4
|
123 |
difference_type __check_count = __n;
|
williamr@4
|
124 |
bool __do_check[_MAXNAMES];
|
williamr@4
|
125 |
const string* __matching_name[_MAX_NAME_LENGTH];
|
williamr@4
|
126 |
|
williamr@4
|
127 |
for (__i = 0; __i < _MAXNAMES; ++__i)
|
williamr@4
|
128 |
__do_check[__i] = true;
|
williamr@4
|
129 |
|
williamr@4
|
130 |
for (__i = 0; __i < _MAX_NAME_LENGTH; ++__i)
|
williamr@4
|
131 |
__matching_name[__i] = __name_end;
|
williamr@4
|
132 |
|
williamr@4
|
133 |
while (__first != __last) {
|
williamr@4
|
134 |
for (__i = 0; __i < __n; ++__i) {
|
williamr@4
|
135 |
if (__do_check[__i]) {
|
williamr@4
|
136 |
if (*__first == __ct.widen(__name[__i][__pos])) {
|
williamr@4
|
137 |
if (__pos == (__name[__i].size() - 1)) {
|
williamr@4
|
138 |
__do_check[__i] = 0;
|
williamr@4
|
139 |
__matching_name[__pos + 1] = __name + __i;
|
williamr@4
|
140 |
--__check_count;
|
williamr@4
|
141 |
if (__check_count == 0) {
|
williamr@4
|
142 |
++__first;
|
williamr@4
|
143 |
return __name + __i;
|
williamr@4
|
144 |
}
|
williamr@4
|
145 |
}
|
williamr@4
|
146 |
}
|
williamr@4
|
147 |
else {
|
williamr@4
|
148 |
__do_check[__i] = 0;
|
williamr@4
|
149 |
--__check_count;
|
williamr@4
|
150 |
if (__check_count == 0)
|
williamr@4
|
151 |
return __matching_name[__pos];
|
williamr@4
|
152 |
}
|
williamr@4
|
153 |
}
|
williamr@4
|
154 |
}
|
williamr@4
|
155 |
|
williamr@4
|
156 |
++__first; ++__pos;
|
williamr@4
|
157 |
}
|
williamr@4
|
158 |
|
williamr@4
|
159 |
return __matching_name[__pos];
|
williamr@4
|
160 |
}
|
williamr@4
|
161 |
|
williamr@4
|
162 |
// __get_formatted_time reads input that is assumed to be formatted
|
williamr@4
|
163 |
// according to the rules for the C strftime function (C standard,
|
williamr@4
|
164 |
// 7.12.3.5). This function is used to implement the do_get_time
|
williamr@4
|
165 |
// and do_get_date virtual functions, which depend on the locale
|
williamr@4
|
166 |
// specifications for the time and day formats respectively.
|
williamr@4
|
167 |
// Note the catchall default case, intended mainly for the '%Z'
|
williamr@4
|
168 |
// format designator, which does not make sense here since the
|
williamr@4
|
169 |
// representation of timezones is not part of the locale.
|
williamr@4
|
170 |
//
|
williamr@4
|
171 |
// The case branches are implemented either by doing a match using
|
williamr@4
|
172 |
// the appopriate name table or by doing a __get_integer_nogroup.
|
williamr@4
|
173 |
//
|
williamr@4
|
174 |
// 'y' format is assumed to mean that the input represents years
|
williamr@4
|
175 |
// since 1900. That is, 2002 should be represented as 102. There
|
williamr@4
|
176 |
// is no century-guessing.
|
williamr@4
|
177 |
//
|
williamr@4
|
178 |
// The match is successful if and only if the second component of the
|
williamr@4
|
179 |
// return value is format_end.
|
williamr@4
|
180 |
|
williamr@4
|
181 |
// Note that the antepenultimate parameter is being used only to determine
|
williamr@4
|
182 |
// the correct overloading for the calls to __get_integer_nogroup.
|
williamr@4
|
183 |
template <class _InIt1, class _Ch>
|
williamr@4
|
184 |
string::const_iterator _STLP_CALL
|
williamr@4
|
185 |
__get_formatted_time _STLP_WEAK (_InIt1 __first, _InIt1 __last,
|
williamr@4
|
186 |
string::const_iterator __format, string::const_iterator __format_end,
|
williamr@4
|
187 |
_Ch*, const _Time_Info& __table,
|
williamr@4
|
188 |
const ios_base& __s, ios_base::iostate& __err, tm* __t) {
|
williamr@4
|
189 |
const ctype<_Ch>& __ct = *__STATIC_CAST(const ctype<_Ch>*, __s._M_ctype_facet());
|
williamr@4
|
190 |
while (__first != __last && __format != __format_end) {
|
williamr@4
|
191 |
if (*__format == '%') {
|
williamr@4
|
192 |
++__format;
|
williamr@4
|
193 |
char __c = *__format;
|
williamr@4
|
194 |
if (__c == '#') { //MS extension
|
williamr@4
|
195 |
++__format;
|
williamr@4
|
196 |
__c = *__format;
|
williamr@4
|
197 |
}
|
williamr@4
|
198 |
|
williamr@4
|
199 |
switch (__c) {
|
williamr@4
|
200 |
case 'a': {
|
williamr@4
|
201 |
const string* __pr = __match(__first, __last,
|
williamr@4
|
202 |
__table._M_dayname + 0, __table._M_dayname + 7,
|
williamr@4
|
203 |
__ct);
|
williamr@4
|
204 |
if (__pr == __table._M_dayname + 7)
|
williamr@4
|
205 |
return __format;
|
williamr@4
|
206 |
__t->tm_wday = __STATIC_CAST(int, __pr - __table._M_dayname);
|
williamr@4
|
207 |
break;
|
williamr@4
|
208 |
}
|
williamr@4
|
209 |
|
williamr@4
|
210 |
case 'A': {
|
williamr@4
|
211 |
const string* __pr = __match(__first, __last,
|
williamr@4
|
212 |
__table._M_dayname + 7, __table._M_dayname + 14,
|
williamr@4
|
213 |
__ct);
|
williamr@4
|
214 |
if (__pr == __table._M_dayname + 14)
|
williamr@4
|
215 |
return __format;
|
williamr@4
|
216 |
__t->tm_wday = __STATIC_CAST(int, __pr - __table._M_dayname - 7);
|
williamr@4
|
217 |
break;
|
williamr@4
|
218 |
}
|
williamr@4
|
219 |
|
williamr@4
|
220 |
case 'b': {
|
williamr@4
|
221 |
const string* __pr = __match(__first, __last,
|
williamr@4
|
222 |
__table._M_monthname + 0, __table._M_monthname + 12,
|
williamr@4
|
223 |
__ct);
|
williamr@4
|
224 |
if (__pr == __table._M_monthname + 12)
|
williamr@4
|
225 |
return __format;
|
williamr@4
|
226 |
__t->tm_mon = __STATIC_CAST(int, __pr - __table._M_monthname);
|
williamr@4
|
227 |
break;
|
williamr@4
|
228 |
}
|
williamr@4
|
229 |
|
williamr@4
|
230 |
case 'B': {
|
williamr@4
|
231 |
const string* __pr = __match(__first, __last,
|
williamr@4
|
232 |
__table._M_monthname + 12, __table._M_monthname + 24,
|
williamr@4
|
233 |
__ct);
|
williamr@4
|
234 |
if (__pr == __table._M_monthname + 24)
|
williamr@4
|
235 |
return __format;
|
williamr@4
|
236 |
__t->tm_mon = __STATIC_CAST(int, __pr - __table._M_monthname - 12);
|
williamr@4
|
237 |
break;
|
williamr@4
|
238 |
}
|
williamr@4
|
239 |
|
williamr@4
|
240 |
case 'd': {
|
williamr@4
|
241 |
bool __pr = __get_decimal_integer(__first, __last, __t->tm_mday, __STATIC_CAST(_Ch*, 0));
|
williamr@4
|
242 |
if (!__pr || __t->tm_mday < 1 || __t->tm_mday > 31) {
|
williamr@4
|
243 |
__err |= ios_base::failbit;
|
williamr@4
|
244 |
return __format;
|
williamr@4
|
245 |
}
|
williamr@4
|
246 |
break;
|
williamr@4
|
247 |
}
|
williamr@4
|
248 |
|
williamr@4
|
249 |
case 'H': case 'I': {
|
williamr@4
|
250 |
bool __pr = __get_decimal_integer(__first, __last, __t->tm_hour, __STATIC_CAST(_Ch*, 0));
|
williamr@4
|
251 |
if (!__pr)
|
williamr@4
|
252 |
return __format;
|
williamr@4
|
253 |
break;
|
williamr@4
|
254 |
}
|
williamr@4
|
255 |
|
williamr@4
|
256 |
case 'j': {
|
williamr@4
|
257 |
bool __pr = __get_decimal_integer(__first, __last, __t->tm_yday, __STATIC_CAST(_Ch*, 0));
|
williamr@4
|
258 |
if (!__pr)
|
williamr@4
|
259 |
return __format;
|
williamr@4
|
260 |
break;
|
williamr@4
|
261 |
}
|
williamr@4
|
262 |
|
williamr@4
|
263 |
case 'm': {
|
williamr@4
|
264 |
bool __pr = __get_decimal_integer(__first, __last, __t->tm_mon, __STATIC_CAST(_Ch*, 0));
|
williamr@4
|
265 |
--__t->tm_mon;
|
williamr@4
|
266 |
if (!__pr || __t->tm_mon < 0 || __t->tm_mon > 11) {
|
williamr@4
|
267 |
__err |= ios_base::failbit;
|
williamr@4
|
268 |
return __format;
|
williamr@4
|
269 |
}
|
williamr@4
|
270 |
break;
|
williamr@4
|
271 |
}
|
williamr@4
|
272 |
|
williamr@4
|
273 |
case 'M': {
|
williamr@4
|
274 |
bool __pr = __get_decimal_integer(__first, __last, __t->tm_min, __STATIC_CAST(_Ch*, 0));
|
williamr@4
|
275 |
if (!__pr)
|
williamr@4
|
276 |
return __format;
|
williamr@4
|
277 |
break;
|
williamr@4
|
278 |
}
|
williamr@4
|
279 |
|
williamr@4
|
280 |
case 'p': {
|
williamr@4
|
281 |
const string* __pr = __match(__first, __last,
|
williamr@4
|
282 |
__table._M_am_pm + 0, __table._M_am_pm + 2, __ct);
|
williamr@4
|
283 |
if (__pr == __table._M_am_pm + 2)
|
williamr@4
|
284 |
return __format;
|
williamr@4
|
285 |
// 12:00 PM <=> 12:00, 12:00 AM <=> 00:00
|
williamr@4
|
286 |
if (__pr == __table._M_am_pm + 1 && __t->tm_hour != 12 )
|
williamr@4
|
287 |
__t->tm_hour += 12;
|
williamr@4
|
288 |
if (__pr == __table._M_am_pm && __t->tm_hour == 12 )
|
williamr@4
|
289 |
__t->tm_hour = 0;
|
williamr@4
|
290 |
break;
|
williamr@4
|
291 |
}
|
williamr@4
|
292 |
|
williamr@4
|
293 |
case 'S': {
|
williamr@4
|
294 |
bool __pr = __get_decimal_integer(__first, __last, __t->tm_sec, __STATIC_CAST(_Ch*, 0));
|
williamr@4
|
295 |
if (!__pr)
|
williamr@4
|
296 |
return __format;
|
williamr@4
|
297 |
break;
|
williamr@4
|
298 |
}
|
williamr@4
|
299 |
|
williamr@4
|
300 |
case 'y': {
|
williamr@4
|
301 |
bool __pr = __get_decimal_integer(__first, __last, __t->tm_year, __STATIC_CAST(_Ch*, 0));
|
williamr@4
|
302 |
if (!__pr)
|
williamr@4
|
303 |
return __format;
|
williamr@4
|
304 |
break;
|
williamr@4
|
305 |
}
|
williamr@4
|
306 |
|
williamr@4
|
307 |
case 'Y': {
|
williamr@4
|
308 |
bool __pr = __get_decimal_integer(__first, __last, __t->tm_year, __STATIC_CAST(_Ch*, 0));
|
williamr@4
|
309 |
__t->tm_year -= 1900;
|
williamr@4
|
310 |
if (!__pr)
|
williamr@4
|
311 |
return __format;
|
williamr@4
|
312 |
break;
|
williamr@4
|
313 |
}
|
williamr@4
|
314 |
|
williamr@4
|
315 |
default:
|
williamr@4
|
316 |
break;
|
williamr@4
|
317 |
}
|
williamr@4
|
318 |
}
|
williamr@4
|
319 |
else {
|
williamr@4
|
320 |
if (*__first++ != __ct.widen(*__format)) break;
|
williamr@4
|
321 |
}
|
williamr@4
|
322 |
|
williamr@4
|
323 |
++__format;
|
williamr@4
|
324 |
}
|
williamr@4
|
325 |
|
williamr@4
|
326 |
return __format;
|
williamr@4
|
327 |
}
|
williamr@4
|
328 |
|
williamr@4
|
329 |
template <class _InIt, class _CharT>
|
williamr@4
|
330 |
bool _STLP_CALL
|
williamr@4
|
331 |
__get_short_or_long_dayname(_InIt& __first, _InIt& __last, const ctype<_CharT>& __ct,
|
williamr@4
|
332 |
const _Time_Info& __table, tm* __t) {
|
williamr@4
|
333 |
const string* __pr =
|
williamr@4
|
334 |
__match(__first, __last, __table._M_dayname + 0, __table._M_dayname + 14, __ct);
|
williamr@4
|
335 |
__t->tm_wday = __STATIC_CAST(int, (__pr - __table._M_dayname) % 7);
|
williamr@4
|
336 |
return __pr != __table._M_dayname + 14;
|
williamr@4
|
337 |
}
|
williamr@4
|
338 |
|
williamr@4
|
339 |
template <class _InIt, class _CharT>
|
williamr@4
|
340 |
bool _STLP_CALL
|
williamr@4
|
341 |
__get_short_or_long_monthname(_InIt& __first, _InIt& __last, const ctype<_CharT>& __ct,
|
williamr@4
|
342 |
const _Time_Info& __table, tm* __t) {
|
williamr@4
|
343 |
const string* __pr =
|
williamr@4
|
344 |
__match(__first, __last, __table._M_monthname + 0, __table._M_monthname + 24, __ct);
|
williamr@4
|
345 |
__t->tm_mon = __STATIC_CAST(int, (__pr - __table._M_monthname) % 12);
|
williamr@4
|
346 |
return __pr != __table._M_monthname + 24;
|
williamr@4
|
347 |
}
|
williamr@4
|
348 |
|
williamr@4
|
349 |
#if !defined (_STLP_NO_WCHAR_T)
|
williamr@4
|
350 |
template <class _OuIt>
|
williamr@4
|
351 |
_OuIt _STLP_CALL
|
williamr@4
|
352 |
__put_time(char * __first, char * __last, _OuIt __out_ite,
|
williamr@4
|
353 |
const ios_base& __s, wchar_t) {
|
williamr@4
|
354 |
const ctype<wchar_t>& __ct = *__STATIC_CAST(const ctype<wchar_t>*, __s._M_ctype_facet());
|
williamr@4
|
355 |
wchar_t __wbuf[64];
|
williamr@4
|
356 |
__ct.widen(__first, __last, __wbuf);
|
williamr@4
|
357 |
ptrdiff_t __len = __last - __first;
|
williamr@4
|
358 |
wchar_t * __eend = __wbuf + __len;
|
williamr@4
|
359 |
return copy((wchar_t*)__wbuf, __eend, __out_ite);
|
williamr@4
|
360 |
}
|
williamr@4
|
361 |
#endif
|
williamr@4
|
362 |
|
williamr@4
|
363 |
_STLP_MOVE_TO_STD_NAMESPACE
|
williamr@4
|
364 |
|
williamr@4
|
365 |
template <class _Ch, class _InIt>
|
williamr@4
|
366 |
_InIt
|
williamr@4
|
367 |
time_get<_Ch, _InIt>::do_get_date(_InIt __s, _InIt __end,
|
williamr@4
|
368 |
ios_base& __str, ios_base::iostate& __err,
|
williamr@4
|
369 |
tm* __t) const {
|
williamr@4
|
370 |
typedef string::const_iterator string_iterator;
|
williamr@4
|
371 |
|
williamr@4
|
372 |
string_iterator __format = _M_timeinfo._M_date_format.begin();
|
williamr@4
|
373 |
string_iterator __format_end = _M_timeinfo._M_date_format.end();
|
williamr@4
|
374 |
|
williamr@4
|
375 |
string_iterator __result
|
williamr@4
|
376 |
= _STLP_PRIV __get_formatted_time(__s, __end, __format, __format_end,
|
williamr@4
|
377 |
__STATIC_CAST(_Ch*, 0), _M_timeinfo,
|
williamr@4
|
378 |
__str, __err, __t);
|
williamr@4
|
379 |
if (__result == __format_end)
|
williamr@4
|
380 |
__err = ios_base::goodbit;
|
williamr@4
|
381 |
else {
|
williamr@4
|
382 |
__err = ios_base::failbit;
|
williamr@4
|
383 |
if (__s == __end)
|
williamr@4
|
384 |
__err |= ios_base::eofbit;
|
williamr@4
|
385 |
}
|
williamr@4
|
386 |
return __s;
|
williamr@4
|
387 |
}
|
williamr@4
|
388 |
|
williamr@4
|
389 |
template <class _Ch, class _InIt>
|
williamr@4
|
390 |
_InIt
|
williamr@4
|
391 |
time_get<_Ch, _InIt>::do_get_time(_InIt __s, _InIt __end,
|
williamr@4
|
392 |
ios_base& __str, ios_base::iostate& __err,
|
williamr@4
|
393 |
tm* __t) const {
|
williamr@4
|
394 |
typedef string::const_iterator string_iterator;
|
williamr@4
|
395 |
string_iterator __format = _M_timeinfo._M_time_format.begin();
|
williamr@4
|
396 |
string_iterator __format_end = _M_timeinfo._M_time_format.end();
|
williamr@4
|
397 |
|
williamr@4
|
398 |
string_iterator __result
|
williamr@4
|
399 |
= _STLP_PRIV __get_formatted_time(__s, __end, __format, __format_end,
|
williamr@4
|
400 |
__STATIC_CAST(_Ch*, 0), _M_timeinfo,
|
williamr@4
|
401 |
__str, __err, __t);
|
williamr@4
|
402 |
__err = __result == __format_end ? ios_base::goodbit
|
williamr@4
|
403 |
: ios_base::failbit;
|
williamr@4
|
404 |
if (__s == __end)
|
williamr@4
|
405 |
__err |= ios_base::eofbit;
|
williamr@4
|
406 |
return __s;
|
williamr@4
|
407 |
}
|
williamr@4
|
408 |
|
williamr@4
|
409 |
template <class _Ch, class _InIt>
|
williamr@4
|
410 |
_InIt
|
williamr@4
|
411 |
time_get<_Ch, _InIt>::do_get_year(_InIt __s, _InIt __end,
|
williamr@4
|
412 |
ios_base&, ios_base::iostate& __err,
|
williamr@4
|
413 |
tm* __t) const {
|
williamr@4
|
414 |
if (__s == __end) {
|
williamr@4
|
415 |
__err = ios_base::failbit | ios_base::eofbit;
|
williamr@4
|
416 |
return __s;
|
williamr@4
|
417 |
}
|
williamr@4
|
418 |
|
williamr@4
|
419 |
bool __pr = _STLP_PRIV __get_decimal_integer(__s, __end, __t->tm_year, __STATIC_CAST(_Ch*, 0));
|
williamr@4
|
420 |
__t->tm_year -= 1900;
|
williamr@4
|
421 |
__err = __pr ? ios_base::goodbit : ios_base::failbit;
|
williamr@4
|
422 |
if (__s == __end)
|
williamr@4
|
423 |
__err |= ios_base::eofbit;
|
williamr@4
|
424 |
|
williamr@4
|
425 |
return __s;
|
williamr@4
|
426 |
}
|
williamr@4
|
427 |
|
williamr@4
|
428 |
template <class _Ch, class _InIt>
|
williamr@4
|
429 |
_InIt
|
williamr@4
|
430 |
time_get<_Ch, _InIt>::do_get_weekday(_InIt __s, _InIt __end,
|
williamr@4
|
431 |
ios_base &__str, ios_base::iostate &__err,
|
williamr@4
|
432 |
tm *__t) const {
|
williamr@4
|
433 |
const ctype<_Ch>& __ct = *__STATIC_CAST(const ctype<_Ch>*, __str._M_ctype_facet());
|
williamr@4
|
434 |
bool __result =
|
williamr@4
|
435 |
_STLP_PRIV __get_short_or_long_dayname(__s, __end, __ct, _M_timeinfo, __t);
|
williamr@4
|
436 |
if (__result)
|
williamr@4
|
437 |
__err = ios_base::goodbit;
|
williamr@4
|
438 |
else {
|
williamr@4
|
439 |
__err = ios_base::failbit;
|
williamr@4
|
440 |
if (__s == __end)
|
williamr@4
|
441 |
__err |= ios_base::eofbit;
|
williamr@4
|
442 |
}
|
williamr@4
|
443 |
return __s;
|
williamr@4
|
444 |
}
|
williamr@4
|
445 |
|
williamr@4
|
446 |
template <class _Ch, class _InIt>
|
williamr@4
|
447 |
_InIt
|
williamr@4
|
448 |
time_get<_Ch, _InIt>::do_get_monthname(_InIt __s, _InIt __end,
|
williamr@4
|
449 |
ios_base &__str, ios_base::iostate &__err,
|
williamr@4
|
450 |
tm *__t) const {
|
williamr@4
|
451 |
const ctype<_Ch>& __ct = *__STATIC_CAST(const ctype<_Ch>*, __str._M_ctype_facet());
|
williamr@4
|
452 |
bool __result =
|
williamr@4
|
453 |
_STLP_PRIV __get_short_or_long_monthname(__s, __end, __ct, _M_timeinfo, __t);
|
williamr@4
|
454 |
if (__result)
|
williamr@4
|
455 |
__err = ios_base::goodbit;
|
williamr@4
|
456 |
else {
|
williamr@4
|
457 |
__err = ios_base::failbit;
|
williamr@4
|
458 |
if (__s == __end)
|
williamr@4
|
459 |
__err |= ios_base::eofbit;
|
williamr@4
|
460 |
}
|
williamr@4
|
461 |
return __s;
|
williamr@4
|
462 |
}
|
williamr@4
|
463 |
|
williamr@4
|
464 |
template<class _Ch, class _OutputIter>
|
williamr@4
|
465 |
_OutputIter
|
williamr@4
|
466 |
time_put<_Ch,_OutputIter>::put(_OutputIter __s, ios_base& __f, _Ch __fill,
|
williamr@4
|
467 |
const tm* __tmb, const _Ch* __pat,
|
williamr@4
|
468 |
const _Ch* __pat_end) const {
|
williamr@4
|
469 |
// locale __loc = __f.getloc();
|
williamr@4
|
470 |
// const ctype<_Ch>& _Ct = use_facet<ctype<_Ch> >(__loc);
|
williamr@4
|
471 |
const ctype<_Ch>& _Ct = *__STATIC_CAST(const ctype<_Ch>*, __f._M_ctype_facet());
|
williamr@4
|
472 |
while (__pat != __pat_end) {
|
williamr@4
|
473 |
char __c = _Ct.narrow(*__pat, 0);
|
williamr@4
|
474 |
if (__c == '%') {
|
williamr@4
|
475 |
char __mod = 0;
|
williamr@4
|
476 |
++__pat;
|
williamr@4
|
477 |
__c = _Ct.narrow(*__pat++, 0);
|
williamr@4
|
478 |
if (__c == '#') { // MS extension
|
williamr@4
|
479 |
__mod = __c;
|
williamr@4
|
480 |
__c = _Ct.narrow(*__pat++, 0);
|
williamr@4
|
481 |
}
|
williamr@4
|
482 |
__s = do_put(__s, __f, __fill, __tmb, __c, __mod);
|
williamr@4
|
483 |
}
|
williamr@4
|
484 |
else
|
williamr@4
|
485 |
*__s++ = *__pat++;
|
williamr@4
|
486 |
}
|
williamr@4
|
487 |
return __s;
|
williamr@4
|
488 |
}
|
williamr@4
|
489 |
|
williamr@4
|
490 |
template<class _Ch, class _OutputIter>
|
williamr@4
|
491 |
_OutputIter
|
williamr@4
|
492 |
time_put<_Ch,_OutputIter>::do_put(_OutputIter __s, ios_base& __f, _Ch /* __fill */,
|
williamr@4
|
493 |
const tm* __tmb, char __format,
|
williamr@4
|
494 |
char __modifier ) const {
|
williamr@4
|
495 |
char __buf[64];
|
williamr@4
|
496 |
char * __iend = _STLP_PRIV __write_formatted_time(_STLP_ARRAY_AND_SIZE(__buf),
|
williamr@4
|
497 |
__format, __modifier, _M_timeinfo, __tmb);
|
williamr@4
|
498 |
// locale __loc = __f.getloc();
|
williamr@4
|
499 |
return _STLP_PRIV __put_time(__buf, __iend, __s, __f, _Ch());
|
williamr@4
|
500 |
}
|
williamr@4
|
501 |
|
williamr@4
|
502 |
_STLP_END_NAMESPACE
|
williamr@4
|
503 |
|
williamr@4
|
504 |
#endif /* _STLP_TIME_FACETS_C */
|
williamr@4
|
505 |
|
williamr@4
|
506 |
// Local Variables:
|
williamr@4
|
507 |
// mode:C++
|
williamr@4
|
508 |
// End:
|