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