1.1 --- a/epoc32/include/stdapis/stlport/stl/_time_facets.c Tue Mar 16 16:12:26 2010 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,522 +0,0 @@
1.4 -/*
1.5 - * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
1.6 - *
1.7 - * Copyright (c) 1999
1.8 - * Silicon Graphics Computer Systems, Inc.
1.9 - *
1.10 - * Copyright (c) 1999
1.11 - * Boris Fomitchev
1.12 - *
1.13 - * This material is provided "as is", with absolutely no warranty expressed
1.14 - * or implied. Any use is at your own risk.
1.15 - *
1.16 - * Permission to use or copy this software for any purpose is hereby granted
1.17 - * without fee, provided the above notices are retained on all copies.
1.18 - * Permission to modify the code and to distribute modified code is granted,
1.19 - * provided the above notices are retained, and a notice that the code was
1.20 - * modified is included with the above copyright notice.
1.21 - *
1.22 - */
1.23 -#ifndef _STLP_TIME_FACETS_C
1.24 -#define _STLP_TIME_FACETS_C
1.25 -
1.26 -#ifndef _STLP_INTERNAL_TIME_FACETS_H
1.27 -# include <stl/_time_facets.h>
1.28 -#endif
1.29 -
1.30 -#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
1.31 -
1.32 -#ifndef _STLP_INTERNAL_NUM_PUT_H
1.33 -# include <stl/_num_put.h>
1.34 -#endif
1.35 -
1.36 -#ifndef _STLP_INTERNAL_NUM_GET_H
1.37 -# include <stl/_num_get.h>
1.38 -#endif
1.39 -
1.40 -_STLP_BEGIN_NAMESPACE
1.41 -
1.42 -//----------------------------------------------------------------------
1.43 -// Declarations of static template members.
1.44 -# if ( _STLP_STATIC_TEMPLATE_DATA > 0 )
1.45 -# if !defined(__LIBSTD_CPP_SYMBIAN32_WSD__) && !defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
1.46 -template <class _CharT, class _InputIterator>
1.47 -locale::id time_get<_CharT, _InputIterator>::id;
1.48 -
1.49 -template <class _CharT, class _OutputIterator>
1.50 -locale::id time_put<_CharT, _OutputIterator>::id;
1.51 -#endif
1.52 -
1.53 -# else /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
1.54 -
1.55 -typedef time_get<char, const char*> time_get_char;
1.56 -typedef time_get<char, char*> time_get_char_2;
1.57 -typedef time_get<char, istreambuf_iterator<char, char_traits<char> > > time_get_char_3;
1.58 -typedef time_put<char, const char*> time_put_char;
1.59 -typedef time_put<char, char*> time_put_char_2;
1.60 -typedef time_put<char, ostreambuf_iterator<char, char_traits<char> > > time_put_char_3;
1.61 -
1.62 -#ifndef __SYMBIAN32__
1.63 -__DECLARE_INSTANCE(locale::id, time_get_char::id, );
1.64 -__DECLARE_INSTANCE(locale::id, time_get_char_2::id, );
1.65 -__DECLARE_INSTANCE(locale::id, time_get_char_3::id, );
1.66 -__DECLARE_INSTANCE(locale::id, time_put_char::id, );
1.67 -__DECLARE_INSTANCE(locale::id, time_put_char_2::id, );
1.68 -__DECLARE_INSTANCE(locale::id, time_put_char_3::id, );
1.69 -#endif
1.70 -
1.71 -# ifndef _STLP_NO_WCHAR_T
1.72 -
1.73 -typedef time_get<wchar_t, const wchar_t*> time_get_wchar_t;
1.74 -typedef time_get<wchar_t, wchar_t*> time_get_wchar_t_2;
1.75 -typedef time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > > time_get_wchar_t_3;
1.76 -typedef time_put<wchar_t, const wchar_t*> time_put_wchar_t;
1.77 -typedef time_put<wchar_t, wchar_t*> time_put_wchar_t_2;
1.78 -typedef time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > time_put_wchar_t_3;
1.79 -
1.80 -#ifndef __SYMBIAN32__
1.81 -__DECLARE_INSTANCE(locale::id, time_get_wchar_t::id, );
1.82 -__DECLARE_INSTANCE(locale::id, time_get_wchar_t_2::id, );
1.83 -__DECLARE_INSTANCE(locale::id, time_get_wchar_t_3::id, );
1.84 -__DECLARE_INSTANCE(locale::id, time_put_wchar_t::id, );
1.85 -__DECLARE_INSTANCE(locale::id, time_put_wchar_t_2::id, );
1.86 -__DECLARE_INSTANCE(locale::id, time_put_wchar_t_3::id, );
1.87 -#endif
1.88 -
1.89 -# endif
1.90 -
1.91 -# endif /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
1.92 -
1.93 -template <class _InIt, class _RAIt, class _DiffType>
1.94 -_RAIt _STLP_CALL
1.95 -__match(_InIt& __first, _InIt& __last, _RAIt __name, _RAIt __name_end, _DiffType*) {
1.96 - typedef _DiffType difference_type;
1.97 - difference_type __n = __name_end - __name;
1.98 - size_t __max_pos = 0;
1.99 - difference_type __i;
1.100 - difference_type __pos = 0;
1.101 - difference_type __check_count = __n;
1.102 - bool __do_check[_MAXNAMES];
1.103 - _RAIt __matching_name[_MAX_NAME_LENGTH];
1.104 -
1.105 - for (__i = 0; __i < __n; ++__i)
1.106 - __max_pos = (max)(__max_pos, __name[__i].size());
1.107 -
1.108 - for (__i = 0; __i < _MAXNAMES; ++__i)
1.109 - __do_check[__i] = true;
1.110 -
1.111 -
1.112 -
1.113 - for (__i = 0; __i < _MAX_NAME_LENGTH; ++__i)
1.114 - __matching_name[__i] = __name_end;
1.115 -
1.116 - while (__first != __last) {
1.117 - for (__i = 0; __i < __n; ++__i)
1.118 - if (__do_check[__i])
1.119 - if (*__first == __name[__i][__pos]) {
1.120 - if (__pos == _DiffType(__name[__i].size()) - 1) {
1.121 - __do_check[__i] = 0;
1.122 - __matching_name[__pos+1] = __name + __i;
1.123 - --__check_count;
1.124 - if (__check_count == 0) {
1.125 - ++__first;
1.126 - return __name + __i;
1.127 - }
1.128 - }
1.129 - }
1.130 - else {
1.131 - __do_check[__i] = 0;
1.132 - --__check_count;
1.133 - if (__check_count == 0)
1.134 - return __matching_name[__pos];
1.135 - }
1.136 -
1.137 - ++__first; ++__pos;
1.138 - }
1.139 -
1.140 - return __matching_name[__pos];
1.141 -}
1.142 -
1.143 -template <class _InIt, class _RAIt>
1.144 -_RAIt _STLP_CALL
1.145 -__match(_InIt& __first, _InIt& __last, _RAIt __name, _RAIt __name_end) {
1.146 - return __match((_InIt&)__first, (_InIt&)__last, __name, __name_end, _STLP_DISTANCE_TYPE(__name, _InIt));
1.147 -}
1.148 -
1.149 -// __get_formatted_time reads input that is assumed to be formatted
1.150 -// according to the rules for the C strftime function (C standard,
1.151 -// 7.12.3.5). This function is used to implement the do_get_time
1.152 -// and do_get_date virtual functions, which depend on the locale
1.153 -// specifications for the time and day formats respectively.
1.154 -// Note the catchall default case, intended mainly for the '%Z'
1.155 -// format designator, which does not make sense here since the
1.156 -// representation of timezones is not part of the locale.
1.157 -//
1.158 -// The case branches are implemented either by doing a match using
1.159 -// the appopriate name table or by doing a __get_integer_nogroup.
1.160 -//
1.161 -// 'y' format is assumed to mean that the input represents years
1.162 -// since 1900. That is, 2002 should be represented as 102. There
1.163 -// is no century-guessing.
1.164 -//
1.165 -// The match is successful if and only if the second component of the
1.166 -// return value is format_end.
1.167 -
1.168 -// Note that the antepenultimate parameter is being used only to determine
1.169 -// the correct overloading for the calls to __get_integer_nogroup.
1.170 -
1.171 -template <class _InIt1, class _InIt2 /* , class _Ch */ >
1.172 -_InIt2 _STLP_CALL
1.173 -__get_formatted_time _STLP_WEAK (_InIt1 __first, _InIt1 __last,
1.174 - _InIt2 __format, _InIt2 __format_end,
1.175 - /* _Ch, */ const _Time_Info& __table,
1.176 - ios_base::iostate& __err,
1.177 - tm* __t) {
1.178 - while(__first != __last && __format != __format_end) {
1.179 - if (*__format == '%') {
1.180 - ++__format;
1.181 - char __c = *__format;
1.182 - switch (__c) {
1.183 - case 'a': {
1.184 - const string* __pr =
1.185 - __match(__first, __last,
1.186 - (string*)__table._M_dayname + 0 , (string*)__table._M_dayname + 7);
1.187 - if (__pr == (string*)__table._M_dayname + 7)
1.188 - return __format;
1.189 - __t->tm_wday = (int)(__pr - (string*)__table._M_dayname);
1.190 - break;
1.191 - }
1.192 -
1.193 - case 'A': {
1.194 - const string* __pr =
1.195 - __match(__first, __last,
1.196 - (string*)__table._M_dayname + 7, (string*)__table._M_dayname + 14);
1.197 - if (__pr == (string*)__table._M_dayname + 14)
1.198 - return __format;
1.199 - __t->tm_wday = (int)(__pr - (string*)__table._M_dayname - 7);
1.200 - break;
1.201 - }
1.202 -
1.203 - case 'b': {
1.204 - const string* __pr =
1.205 - __match(__first, __last,
1.206 - (string*)__table._M_monthname + 0, (string*)__table._M_monthname + 12);
1.207 - if (__pr == (string*)__table._M_monthname + 12)
1.208 - return __format;
1.209 - __t->tm_mon = (int)(__pr - (string*)__table._M_monthname);
1.210 - break;
1.211 - }
1.212 -
1.213 - case 'B': {
1.214 - const string* __pr =
1.215 - __match(__first, __last,
1.216 - (string*)__table._M_monthname + 12, (string*)__table._M_monthname + 24);
1.217 - if (__pr == (string*)__table._M_monthname + 24)
1.218 - return __format;
1.219 - __t->tm_mon = (int)(__pr - (string*)__table._M_monthname - 12);
1.220 - break;
1.221 - }
1.222 -
1.223 - case 'd': {
1.224 - bool __pr =
1.225 - __get_decimal_integer(__first, __last, __t->tm_mday);
1.226 - if (!__pr || __t->tm_mday < 1 || __t->tm_mday > 31) {
1.227 - __err |= ios_base::failbit;
1.228 - return __format;
1.229 - }
1.230 - break;
1.231 - }
1.232 -
1.233 - case 'H': case 'I': {
1.234 - bool __pr =
1.235 - __get_decimal_integer(__first, __last, __t->tm_hour);
1.236 - if (!__pr)
1.237 - return __format;
1.238 - break;
1.239 - }
1.240 -
1.241 - case 'j': {
1.242 - bool __pr =
1.243 - __get_decimal_integer(__first, __last, __t->tm_yday);
1.244 - if (!__pr)
1.245 - return __format;
1.246 - break;
1.247 - }
1.248 -
1.249 - case 'm': {
1.250 - bool __pr =
1.251 - __get_decimal_integer(__first, __last, __t->tm_mon);
1.252 - --__t->tm_mon;
1.253 - if (!__pr || __t->tm_mon < 0 || __t->tm_mon > 11) {
1.254 - __err |= ios_base::failbit;
1.255 - return __format;
1.256 - }
1.257 - break;
1.258 - }
1.259 -
1.260 - case 'M': {
1.261 - bool __pr =
1.262 - __get_decimal_integer(__first, __last, __t->tm_min);
1.263 - if (!__pr)
1.264 - return __format;
1.265 - break;
1.266 - }
1.267 -
1.268 - case 'p': {
1.269 - const string* __pr =
1.270 - __match(__first, __last, (string*)__table._M_am_pm + 0, (string*)__table._M_am_pm + 2);
1.271 - if (__pr == (string*)__table._M_am_pm + 2)
1.272 - return __format;
1.273 - if (__pr == (string*)__table._M_am_pm + 1)
1.274 - __t->tm_hour += 12;
1.275 - break;
1.276 - }
1.277 -
1.278 - case 'S': {
1.279 - bool __pr =
1.280 - __get_decimal_integer(__first, __last, __t->tm_sec);
1.281 - if (!__pr)
1.282 - return __format;
1.283 - break;
1.284 - }
1.285 -
1.286 - case 'y': {
1.287 - bool __pr =
1.288 - __get_decimal_integer(__first, __last, __t->tm_year);
1.289 - if (!__pr)
1.290 - return __format;
1.291 - break;
1.292 - }
1.293 -
1.294 - case 'Y': {
1.295 - bool __pr =
1.296 - __get_decimal_integer(__first, __last, __t->tm_year);
1.297 - __t->tm_year -= 1900;
1.298 - if (!__pr)
1.299 - return __format;
1.300 - break;
1.301 - }
1.302 -
1.303 - default:
1.304 - break;
1.305 - }
1.306 -
1.307 - }
1.308 - else {
1.309 - if (*__first != *__format)
1.310 - break;
1.311 - __first++;
1.312 - }
1.313 -
1.314 - ++__format;
1.315 - }
1.316 -
1.317 - return __format;
1.318 -}
1.319 -
1.320 -template <class _InIt>
1.321 -bool _STLP_CALL
1.322 -__get_short_or_long_dayname(_InIt& __first, _InIt& __last,
1.323 - const _Time_Info& __table, tm* __t) {
1.324 - const string* __pr =
1.325 - __match(__first, __last, __table._M_dayname + 0, __table._M_dayname + 14);
1.326 - __t->tm_wday = (int)(__pr - __table._M_dayname) % 7;
1.327 - return __pr != __table._M_dayname + 14;
1.328 -}
1.329 -
1.330 -template <class _InIt>
1.331 -bool _STLP_CALL
1.332 -__get_short_or_long_monthname(_InIt& __first, _InIt& __last,
1.333 - const _Time_Info& __table, tm* __t) {
1.334 - const string* __pr =
1.335 - __match(__first, __last, (string*)__table._M_monthname + 0, (string*)__table._M_monthname + 24);
1.336 - __t->tm_mon = (int)(__pr - __table._M_monthname) % 12;
1.337 - return __pr != __table._M_monthname + 24;
1.338 -}
1.339 -
1.340 -# ifndef _STLP_NO_WCHAR_T
1.341 -template <class _OuIt>
1.342 -_OuIt _STLP_CALL
1.343 -__put_time(char * __first, char * __last, _OuIt __stl_out,
1.344 - const ios_base& __s, wchar_t) {
1.345 - //const ctype<wchar_t>& __ct = *(ctype<wchar_t>*)__s._M_ctype_facet();
1.346 - const ctype<wchar_t>& __ct = use_facet< ctype<wchar_t> >(__s.getloc());
1.347 - wchar_t __wbuf[64];
1.348 - __ct.widen(__first, __last, __wbuf);
1.349 - ptrdiff_t __len = __last - __first;
1.350 - wchar_t * __eend = __wbuf + __len;
1.351 - return copy((wchar_t*)__wbuf, __eend, __stl_out);
1.352 -}
1.353 -# endif
1.354 -
1.355 -#ifdef __SYMBIAN32__
1.356 -template <class _CharT, class _OuIt>
1.357 -_OuIt _STLP_CALL
1.358 -__put_time(char * __first, char * __last, _OuIt __stl_out,
1.359 - const ios_base& __s, _CharT) {
1.360 - //const ctype<wchar_t>& __ct = *(ctype<wchar_t>*)__s._M_ctype_facet();
1.361 - const ctype<_CharT>& __ct = use_facet< ctype<_CharT> >(__s.getloc());
1.362 - _CharT __wbuf[64];
1.363 - __ct.widen(__first, __last, __wbuf);
1.364 - ptrdiff_t __len = __last - __first;
1.365 - _CharT * __eend = __wbuf + __len;
1.366 - return copy((_CharT*)__wbuf, __eend, __stl_out);
1.367 -}
1.368 -
1.369 -#endif
1.370 -template <class _Ch, class _InIt>
1.371 -_InIt
1.372 -time_get<_Ch, _InIt>::do_get_date(_InIt __s, _InIt __end,
1.373 - ios_base& /* __str */, ios_base::iostate& __err,
1.374 - tm* __t) const
1.375 -{
1.376 - typedef string::const_iterator string_iterator;
1.377 -
1.378 - string_iterator __format
1.379 - = _M_timeinfo._M_date_format.begin();
1.380 - string_iterator __format_end
1.381 - = _M_timeinfo._M_date_format.end();
1.382 -
1.383 - string_iterator __result
1.384 - = __get_formatted_time(__s, __end, __format, __format_end,
1.385 - /* _Ch() ,*/ _M_timeinfo, __err, __t);
1.386 - if (__result == __format_end)
1.387 - __err = ios_base::goodbit;
1.388 - else {
1.389 - __err = ios_base::failbit;
1.390 - if (__s == __end)
1.391 - __err |= ios_base::eofbit;
1.392 - }
1.393 - return __s;
1.394 -}
1.395 -
1.396 -template <class _Ch, class _InIt>
1.397 -_InIt
1.398 -time_get<_Ch, _InIt>::do_get_time(_InIt __s, _InIt __end,
1.399 - ios_base& /* __str */, ios_base::iostate& __err,
1.400 - tm* __t) const
1.401 -{
1.402 - typedef string::const_iterator string_iterator;
1.403 - string_iterator __format
1.404 - = _M_timeinfo._M_time_format.begin();
1.405 - string_iterator __format_end
1.406 - = _M_timeinfo._M_time_format.end();
1.407 -
1.408 - string_iterator __result
1.409 - = __get_formatted_time(__s, __end, __format, __format_end,
1.410 - /* _Ch() , */ _M_timeinfo, __err, __t);
1.411 - __err = __result == __format_end ? ios_base::goodbit
1.412 - : ios_base::failbit;
1.413 - if (__s == __end)
1.414 - __err |= ios_base::eofbit;
1.415 - return __s;
1.416 -}
1.417 -
1.418 -template <class _Ch, class _InIt>
1.419 -_InIt
1.420 -time_get<_Ch, _InIt>::do_get_year(_InIt __s, _InIt __end,
1.421 - ios_base&,
1.422 - ios_base::iostate& __err,
1.423 - tm* __t) const
1.424 -{
1.425 -
1.426 - if (__s == __end) {
1.427 - __err = ios_base::failbit | ios_base::eofbit;
1.428 - return __s;
1.429 - }
1.430 -
1.431 - bool __pr = __get_decimal_integer(__s, __end, __t->tm_year);
1.432 - __t->tm_year -= 1900;
1.433 - __err = __pr ? ios_base::goodbit : ios_base::failbit;
1.434 - if (__s == __end)
1.435 - __err |= ios_base::eofbit;
1.436 -
1.437 - return __s;
1.438 -}
1.439 -
1.440 -template <class _Ch, class _InIt>
1.441 -_InIt
1.442 -time_get<_Ch, _InIt>::do_get_weekday(_InIt __s, _InIt __end,
1.443 - ios_base& /* __str */,
1.444 - ios_base::iostate& __err,
1.445 - tm* __t) const
1.446 -{
1.447 - bool __result =
1.448 - __get_short_or_long_dayname(__s, __end, _M_timeinfo, __t);
1.449 - if (__result)
1.450 - __err = ios_base::goodbit;
1.451 - else {
1.452 - __err = ios_base::failbit;
1.453 - if (__s == __end)
1.454 - __err |= ios_base::eofbit;
1.455 - }
1.456 - return __s;
1.457 -}
1.458 -
1.459 -template <class _Ch, class _InIt>
1.460 -_InIt
1.461 -time_get<_Ch, _InIt>::do_get_monthname(_InIt __s, _InIt __end,
1.462 - ios_base& /* __str */,
1.463 - ios_base::iostate& __err,
1.464 - tm* __t) const
1.465 -{
1.466 - bool __result =
1.467 - __get_short_or_long_monthname(__s, __end, _M_timeinfo, __t);
1.468 - if (__result)
1.469 - __err = ios_base::goodbit;
1.470 - else {
1.471 - __err = ios_base::failbit;
1.472 - if (__s == __end)
1.473 - __err |= ios_base::eofbit;
1.474 - }
1.475 - return __s;
1.476 -}
1.477 -
1.478 -template<class _Ch, class _OutputIter>
1.479 -_OutputIter
1.480 -time_put<_Ch,_OutputIter>::put(_OutputIter __s, ios_base& __f, _Ch __fill,
1.481 - const tm* __tmb,
1.482 - const _Ch* __pat, const _Ch* __pat_end) const
1.483 -{
1.484 - locale __loc = __f.getloc();
1.485 - const ctype<_Ch>& _Ct = use_facet<ctype<_Ch> >(__loc);
1.486 - // const ctype<_Ch>& _Ct = *(ctype<_Ch>*)__f._M_ctype_facet();
1.487 - while (__pat != __pat_end) {
1.488 - char __c = _Ct.narrow(*__pat, 0);
1.489 - if (__c == '%') {
1.490 - char __mod = 0;
1.491 - ++__pat;
1.492 - __c = _Ct.narrow(*__pat++, 0);
1.493 - if(__c == '#') { // MS extension
1.494 - __mod = __c;
1.495 - __c = _Ct.narrow(*__pat++, 0);
1.496 - }
1.497 - __s = do_put(__s, __f, __fill, __tmb, __c, __mod);
1.498 - }
1.499 - else
1.500 - *__s++ = *__pat++;
1.501 - }
1.502 - return __s;
1.503 -}
1.504 -
1.505 -template<class _Ch, class _OutputIter>
1.506 -_OutputIter
1.507 -time_put<_Ch,_OutputIter>::do_put(_OutputIter __s, ios_base& __f, _Ch /* __fill */ ,
1.508 - const tm* __tmb,
1.509 - char __format, char __modifier ) const
1.510 -{
1.511 - char __buf[64];
1.512 - char * __iend = __write_formatted_time(__buf, __format, __modifier,
1.513 - _M_timeinfo, __tmb);
1.514 - // locale __loc = __f.getloc();
1.515 - return __put_time(__buf, __iend, __s, __f, _Ch());
1.516 -}
1.517 -
1.518 -_STLP_END_NAMESPACE
1.519 -
1.520 -# endif /* defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) */
1.521 -#endif /* _STLP_TIME_FACETS_C */
1.522 -
1.523 -// Local Variables:
1.524 -// mode:C++
1.525 -// End: