Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
2 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
5 * Silicon Graphics Computer Systems, Inc.
10 * This material is provided "as is", with absolutely no warranty expressed
11 * or implied. Any use is at your own risk.
13 * Permission to use or copy this software for any purpose is hereby granted
14 * without fee, provided the above notices are retained on all copies.
15 * Permission to modify the code and to distribute modified code is granted,
16 * provided the above notices are retained, and a notice that the code was
17 * modified is included with the above copyright notice.
20 #ifndef _STLP_TIME_FACETS_C
21 #define _STLP_TIME_FACETS_C
23 #ifndef _STLP_INTERNAL_TIME_FACETS_H
24 # include <stl/_time_facets.h>
27 #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
29 #ifndef _STLP_INTERNAL_NUM_PUT_H
30 # include <stl/_num_put.h>
33 #ifndef _STLP_INTERNAL_NUM_GET_H
34 # include <stl/_num_get.h>
39 //----------------------------------------------------------------------
40 // Declarations of static template members.
41 # if ( _STLP_STATIC_TEMPLATE_DATA > 0 )
42 # if !defined(__LIBSTD_CPP_SYMBIAN32_WSD__) && !defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
43 template <class _CharT, class _InputIterator>
44 locale::id time_get<_CharT, _InputIterator>::id;
46 template <class _CharT, class _OutputIterator>
47 locale::id time_put<_CharT, _OutputIterator>::id;
50 # else /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
52 typedef time_get<char, const char*> time_get_char;
53 typedef time_get<char, char*> time_get_char_2;
54 typedef time_get<char, istreambuf_iterator<char, char_traits<char> > > time_get_char_3;
55 typedef time_put<char, const char*> time_put_char;
56 typedef time_put<char, char*> time_put_char_2;
57 typedef time_put<char, ostreambuf_iterator<char, char_traits<char> > > time_put_char_3;
60 __DECLARE_INSTANCE(locale::id, time_get_char::id, );
61 __DECLARE_INSTANCE(locale::id, time_get_char_2::id, );
62 __DECLARE_INSTANCE(locale::id, time_get_char_3::id, );
63 __DECLARE_INSTANCE(locale::id, time_put_char::id, );
64 __DECLARE_INSTANCE(locale::id, time_put_char_2::id, );
65 __DECLARE_INSTANCE(locale::id, time_put_char_3::id, );
68 # ifndef _STLP_NO_WCHAR_T
70 typedef time_get<wchar_t, const wchar_t*> time_get_wchar_t;
71 typedef time_get<wchar_t, wchar_t*> time_get_wchar_t_2;
72 typedef time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > > time_get_wchar_t_3;
73 typedef time_put<wchar_t, const wchar_t*> time_put_wchar_t;
74 typedef time_put<wchar_t, wchar_t*> time_put_wchar_t_2;
75 typedef time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > time_put_wchar_t_3;
78 __DECLARE_INSTANCE(locale::id, time_get_wchar_t::id, );
79 __DECLARE_INSTANCE(locale::id, time_get_wchar_t_2::id, );
80 __DECLARE_INSTANCE(locale::id, time_get_wchar_t_3::id, );
81 __DECLARE_INSTANCE(locale::id, time_put_wchar_t::id, );
82 __DECLARE_INSTANCE(locale::id, time_put_wchar_t_2::id, );
83 __DECLARE_INSTANCE(locale::id, time_put_wchar_t_3::id, );
88 # endif /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
90 template <class _InIt, class _RAIt, class _DiffType>
92 __match(_InIt& __first, _InIt& __last, _RAIt __name, _RAIt __name_end, _DiffType*) {
93 typedef _DiffType difference_type;
94 difference_type __n = __name_end - __name;
97 difference_type __pos = 0;
98 difference_type __check_count = __n;
99 bool __do_check[_MAXNAMES];
100 _RAIt __matching_name[_MAX_NAME_LENGTH];
102 for (__i = 0; __i < __n; ++__i)
103 __max_pos = (max)(__max_pos, __name[__i].size());
105 for (__i = 0; __i < _MAXNAMES; ++__i)
106 __do_check[__i] = true;
110 for (__i = 0; __i < _MAX_NAME_LENGTH; ++__i)
111 __matching_name[__i] = __name_end;
113 while (__first != __last) {
114 for (__i = 0; __i < __n; ++__i)
116 if (*__first == __name[__i][__pos]) {
117 if (__pos == _DiffType(__name[__i].size()) - 1) {
119 __matching_name[__pos+1] = __name + __i;
121 if (__check_count == 0) {
130 if (__check_count == 0)
131 return __matching_name[__pos];
137 return __matching_name[__pos];
140 template <class _InIt, class _RAIt>
142 __match(_InIt& __first, _InIt& __last, _RAIt __name, _RAIt __name_end) {
143 return __match((_InIt&)__first, (_InIt&)__last, __name, __name_end, _STLP_DISTANCE_TYPE(__name, _InIt));
146 // __get_formatted_time reads input that is assumed to be formatted
147 // according to the rules for the C strftime function (C standard,
148 // 7.12.3.5). This function is used to implement the do_get_time
149 // and do_get_date virtual functions, which depend on the locale
150 // specifications for the time and day formats respectively.
151 // Note the catchall default case, intended mainly for the '%Z'
152 // format designator, which does not make sense here since the
153 // representation of timezones is not part of the locale.
155 // The case branches are implemented either by doing a match using
156 // the appopriate name table or by doing a __get_integer_nogroup.
158 // 'y' format is assumed to mean that the input represents years
159 // since 1900. That is, 2002 should be represented as 102. There
160 // is no century-guessing.
162 // The match is successful if and only if the second component of the
163 // return value is format_end.
165 // Note that the antepenultimate parameter is being used only to determine
166 // the correct overloading for the calls to __get_integer_nogroup.
168 template <class _InIt1, class _InIt2 /* , class _Ch */ >
170 __get_formatted_time _STLP_WEAK (_InIt1 __first, _InIt1 __last,
171 _InIt2 __format, _InIt2 __format_end,
172 /* _Ch, */ const _Time_Info& __table,
173 ios_base::iostate& __err,
175 while(__first != __last && __format != __format_end) {
176 if (*__format == '%') {
178 char __c = *__format;
182 __match(__first, __last,
183 (string*)__table._M_dayname + 0 , (string*)__table._M_dayname + 7);
184 if (__pr == (string*)__table._M_dayname + 7)
186 __t->tm_wday = (int)(__pr - (string*)__table._M_dayname);
192 __match(__first, __last,
193 (string*)__table._M_dayname + 7, (string*)__table._M_dayname + 14);
194 if (__pr == (string*)__table._M_dayname + 14)
196 __t->tm_wday = (int)(__pr - (string*)__table._M_dayname - 7);
202 __match(__first, __last,
203 (string*)__table._M_monthname + 0, (string*)__table._M_monthname + 12);
204 if (__pr == (string*)__table._M_monthname + 12)
206 __t->tm_mon = (int)(__pr - (string*)__table._M_monthname);
212 __match(__first, __last,
213 (string*)__table._M_monthname + 12, (string*)__table._M_monthname + 24);
214 if (__pr == (string*)__table._M_monthname + 24)
216 __t->tm_mon = (int)(__pr - (string*)__table._M_monthname - 12);
222 __get_decimal_integer(__first, __last, __t->tm_mday);
223 if (!__pr || __t->tm_mday < 1 || __t->tm_mday > 31) {
224 __err |= ios_base::failbit;
230 case 'H': case 'I': {
232 __get_decimal_integer(__first, __last, __t->tm_hour);
240 __get_decimal_integer(__first, __last, __t->tm_yday);
248 __get_decimal_integer(__first, __last, __t->tm_mon);
250 if (!__pr || __t->tm_mon < 0 || __t->tm_mon > 11) {
251 __err |= ios_base::failbit;
259 __get_decimal_integer(__first, __last, __t->tm_min);
267 __match(__first, __last, (string*)__table._M_am_pm + 0, (string*)__table._M_am_pm + 2);
268 if (__pr == (string*)__table._M_am_pm + 2)
270 if (__pr == (string*)__table._M_am_pm + 1)
277 __get_decimal_integer(__first, __last, __t->tm_sec);
285 __get_decimal_integer(__first, __last, __t->tm_year);
293 __get_decimal_integer(__first, __last, __t->tm_year);
294 __t->tm_year -= 1900;
306 if (*__first != *__format)
317 template <class _InIt>
319 __get_short_or_long_dayname(_InIt& __first, _InIt& __last,
320 const _Time_Info& __table, tm* __t) {
322 __match(__first, __last, __table._M_dayname + 0, __table._M_dayname + 14);
323 __t->tm_wday = (int)(__pr - __table._M_dayname) % 7;
324 return __pr != __table._M_dayname + 14;
327 template <class _InIt>
329 __get_short_or_long_monthname(_InIt& __first, _InIt& __last,
330 const _Time_Info& __table, tm* __t) {
332 __match(__first, __last, (string*)__table._M_monthname + 0, (string*)__table._M_monthname + 24);
333 __t->tm_mon = (int)(__pr - __table._M_monthname) % 12;
334 return __pr != __table._M_monthname + 24;
337 # ifndef _STLP_NO_WCHAR_T
338 template <class _OuIt>
340 __put_time(char * __first, char * __last, _OuIt __stl_out,
341 const ios_base& __s, wchar_t) {
342 //const ctype<wchar_t>& __ct = *(ctype<wchar_t>*)__s._M_ctype_facet();
343 const ctype<wchar_t>& __ct = use_facet< ctype<wchar_t> >(__s.getloc());
345 __ct.widen(__first, __last, __wbuf);
346 ptrdiff_t __len = __last - __first;
347 wchar_t * __eend = __wbuf + __len;
348 return copy((wchar_t*)__wbuf, __eend, __stl_out);
353 template <class _CharT, class _OuIt>
355 __put_time(char * __first, char * __last, _OuIt __stl_out,
356 const ios_base& __s, _CharT) {
357 //const ctype<wchar_t>& __ct = *(ctype<wchar_t>*)__s._M_ctype_facet();
358 const ctype<_CharT>& __ct = use_facet< ctype<_CharT> >(__s.getloc());
360 __ct.widen(__first, __last, __wbuf);
361 ptrdiff_t __len = __last - __first;
362 _CharT * __eend = __wbuf + __len;
363 return copy((_CharT*)__wbuf, __eend, __stl_out);
367 template <class _Ch, class _InIt>
369 time_get<_Ch, _InIt>::do_get_date(_InIt __s, _InIt __end,
370 ios_base& /* __str */, ios_base::iostate& __err,
373 typedef string::const_iterator string_iterator;
375 string_iterator __format
376 = _M_timeinfo._M_date_format.begin();
377 string_iterator __format_end
378 = _M_timeinfo._M_date_format.end();
380 string_iterator __result
381 = __get_formatted_time(__s, __end, __format, __format_end,
382 /* _Ch() ,*/ _M_timeinfo, __err, __t);
383 if (__result == __format_end)
384 __err = ios_base::goodbit;
386 __err = ios_base::failbit;
388 __err |= ios_base::eofbit;
393 template <class _Ch, class _InIt>
395 time_get<_Ch, _InIt>::do_get_time(_InIt __s, _InIt __end,
396 ios_base& /* __str */, ios_base::iostate& __err,
399 typedef string::const_iterator string_iterator;
400 string_iterator __format
401 = _M_timeinfo._M_time_format.begin();
402 string_iterator __format_end
403 = _M_timeinfo._M_time_format.end();
405 string_iterator __result
406 = __get_formatted_time(__s, __end, __format, __format_end,
407 /* _Ch() , */ _M_timeinfo, __err, __t);
408 __err = __result == __format_end ? ios_base::goodbit
411 __err |= ios_base::eofbit;
415 template <class _Ch, class _InIt>
417 time_get<_Ch, _InIt>::do_get_year(_InIt __s, _InIt __end,
419 ios_base::iostate& __err,
424 __err = ios_base::failbit | ios_base::eofbit;
428 bool __pr = __get_decimal_integer(__s, __end, __t->tm_year);
429 __t->tm_year -= 1900;
430 __err = __pr ? ios_base::goodbit : ios_base::failbit;
432 __err |= ios_base::eofbit;
437 template <class _Ch, class _InIt>
439 time_get<_Ch, _InIt>::do_get_weekday(_InIt __s, _InIt __end,
440 ios_base& /* __str */,
441 ios_base::iostate& __err,
445 __get_short_or_long_dayname(__s, __end, _M_timeinfo, __t);
447 __err = ios_base::goodbit;
449 __err = ios_base::failbit;
451 __err |= ios_base::eofbit;
456 template <class _Ch, class _InIt>
458 time_get<_Ch, _InIt>::do_get_monthname(_InIt __s, _InIt __end,
459 ios_base& /* __str */,
460 ios_base::iostate& __err,
464 __get_short_or_long_monthname(__s, __end, _M_timeinfo, __t);
466 __err = ios_base::goodbit;
468 __err = ios_base::failbit;
470 __err |= ios_base::eofbit;
475 template<class _Ch, class _OutputIter>
477 time_put<_Ch,_OutputIter>::put(_OutputIter __s, ios_base& __f, _Ch __fill,
479 const _Ch* __pat, const _Ch* __pat_end) const
481 locale __loc = __f.getloc();
482 const ctype<_Ch>& _Ct = use_facet<ctype<_Ch> >(__loc);
483 // const ctype<_Ch>& _Ct = *(ctype<_Ch>*)__f._M_ctype_facet();
484 while (__pat != __pat_end) {
485 char __c = _Ct.narrow(*__pat, 0);
489 __c = _Ct.narrow(*__pat++, 0);
490 if(__c == '#') { // MS extension
492 __c = _Ct.narrow(*__pat++, 0);
494 __s = do_put(__s, __f, __fill, __tmb, __c, __mod);
502 template<class _Ch, class _OutputIter>
504 time_put<_Ch,_OutputIter>::do_put(_OutputIter __s, ios_base& __f, _Ch /* __fill */ ,
506 char __format, char __modifier ) const
509 char * __iend = __write_formatted_time(__buf, __format, __modifier,
511 // locale __loc = __f.getloc();
512 return __put_time(__buf, __iend, __s, __f, _Ch());
517 # endif /* defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) */
518 #endif /* _STLP_TIME_FACETS_C */