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