build/stlport/src/time_facets.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/build/stlport/src/time_facets.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,565 @@
     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 +
    1.22 +#include "stlport_prefix.h"
    1.23 +
    1.24 +#include <cstdio>
    1.25 +#include <locale>
    1.26 +#include <istream>
    1.27 +
    1.28 +#include "c_locale.h"
    1.29 +#include "acquire_release.h"
    1.30 +
    1.31 +_STLP_BEGIN_NAMESPACE
    1.32 +
    1.33 +_STLP_MOVE_TO_PRIV_NAMESPACE
    1.34 +
    1.35 +// default "C" values for month and day names
    1.36 +
    1.37 +const char default_dayname[][14] = {
    1.38 +  "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
    1.39 +  "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
    1.40 +  "Friday", "Saturday"};
    1.41 +
    1.42 +const char default_monthname[][24] = {
    1.43 +  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
    1.44 +  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
    1.45 +  "January", "February", "March", "April", "May", "June",
    1.46 +  "July", "August", "September", "October", "November", "December"};
    1.47 +
    1.48 +#ifndef _STLP_NO_WCHAR_T
    1.49 +const wchar_t default_wdayname[][14] = {
    1.50 +  L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat",
    1.51 +  L"Sunday", L"Monday", L"Tuesday", L"Wednesday", L"Thursday",
    1.52 +  L"Friday", L"Saturday"};
    1.53 +
    1.54 +const wchar_t default_wmonthname[][24] = {
    1.55 +  L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun",
    1.56 +  L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec",
    1.57 +  L"January", L"February", L"March", L"April", L"May", L"June",
    1.58 +  L"July", L"August", L"September", L"October", L"November", L"December"};
    1.59 +#endif
    1.60 +
    1.61 +#if defined (__BORLANDC__)
    1.62 +_Time_Info time_init<char>::_M_timeinfo;
    1.63 +#  ifndef _STLP_NO_WCHAR_T
    1.64 +_WTime_Info time_init<wchar_t>::_M_timeinfo;
    1.65 +#  endif
    1.66 +#endif
    1.67 +
    1.68 +// _Init_time_info: initialize table with
    1.69 +// "C" values (note these are not defined in the C standard, so this
    1.70 +// is somewhat arbitrary).
    1.71 +
    1.72 +static void _Init_timeinfo_base(_Time_Info_Base& table) {
    1.73 +  table._M_time_format = "%H:%M:%S";
    1.74 +  table._M_date_format = "%m/%d/%y";
    1.75 +  table._M_date_time_format = "%m/%d/%y";
    1.76 +}
    1.77 +
    1.78 +static void _Init_timeinfo(_Time_Info& table) {
    1.79 +  int i;
    1.80 +  for (i = 0; i < 14; ++i)
    1.81 +    table._M_dayname[i] = default_dayname[i];
    1.82 +  for (i = 0; i < 24; ++i)
    1.83 +    table._M_monthname[i] = default_monthname[i];
    1.84 +  table._M_am_pm[0] = "AM";
    1.85 +  table._M_am_pm[1] = "PM";
    1.86 +  _Init_timeinfo_base(table);
    1.87 +}
    1.88 +
    1.89 +#ifndef _STLP_NO_WCHAR_T
    1.90 +static void _Init_timeinfo(_WTime_Info& table) {
    1.91 +  int i;
    1.92 +  for (i = 0; i < 14; ++i)
    1.93 +    table._M_dayname[i] = default_wdayname[i];
    1.94 +  for (i = 0; i < 24; ++i)
    1.95 +    table._M_monthname[i] = default_wmonthname[i];
    1.96 +  table._M_am_pm[0] = L"AM";
    1.97 +  table._M_am_pm[1] = L"PM";
    1.98 +  _Init_timeinfo_base(table);
    1.99 +}
   1.100 +#endif
   1.101 +
   1.102 +static void _Init_timeinfo_base(_Time_Info_Base& table, _Locale_time * time) {
   1.103 +  table._M_time_format = _Locale_t_fmt(time);
   1.104 +  if ( table._M_time_format == "%T" ) {
   1.105 +    table._M_time_format = "%H:%M:%S";
   1.106 +  } else if ( table._M_time_format == "%r" ) {
   1.107 +    table._M_time_format = "%I:%M:%S %p";
   1.108 +  } else if ( table._M_time_format == "%R" ) {
   1.109 +    table._M_time_format = "%H:%M";
   1.110 +  }
   1.111 +  table._M_date_format = _Locale_d_fmt(time);
   1.112 +  table._M_date_time_format = _Locale_d_t_fmt(time);
   1.113 +  table._M_long_date_format = _Locale_long_d_fmt(time);
   1.114 +  table._M_long_date_time_format = _Locale_long_d_t_fmt(time);
   1.115 +}
   1.116 +
   1.117 +static void _Init_timeinfo(_Time_Info& table, _Locale_time * time) {
   1.118 +  int i;
   1.119 +  for (i = 0; i < 7; ++i)
   1.120 +    table._M_dayname[i] = _Locale_abbrev_dayofweek(time, i);
   1.121 +  for (i = 0; i < 7; ++i)
   1.122 +    table._M_dayname[i+7] = _Locale_full_dayofweek(time, i);
   1.123 +  for (i = 0; i < 12; ++i)
   1.124 +    table._M_monthname[i] = _Locale_abbrev_monthname(time, i);
   1.125 +  for (i = 0; i < 12; ++i)
   1.126 +    table._M_monthname[i+12] = _Locale_full_monthname(time, i);
   1.127 +  table._M_am_pm[0] = _Locale_am_str(time);
   1.128 +  table._M_am_pm[1] = _Locale_pm_str(time);
   1.129 +  _Init_timeinfo_base(table, time);
   1.130 +}
   1.131 +
   1.132 +#ifndef _STLP_NO_WCHAR_T
   1.133 +static void _Init_timeinfo(_WTime_Info& table, _Locale_time * time) {
   1.134 +  wchar_t buf[128];
   1.135 +  int i;
   1.136 +  for (i = 0; i < 7; ++i)
   1.137 +    table._M_dayname[i] = _WLocale_abbrev_dayofweek(time, i, _STLP_ARRAY_AND_SIZE(buf));
   1.138 +  for (i = 0; i < 7; ++i)
   1.139 +    table._M_dayname[i+7] = _WLocale_full_dayofweek(time, i, _STLP_ARRAY_AND_SIZE(buf));
   1.140 +  for (i = 0; i < 12; ++i)
   1.141 +    table._M_monthname[i] = _WLocale_abbrev_monthname(time, i, _STLP_ARRAY_AND_SIZE(buf));
   1.142 +  for (i = 0; i < 12; ++i)
   1.143 +    table._M_monthname[i+12] = _WLocale_full_monthname(time, i, _STLP_ARRAY_AND_SIZE(buf));
   1.144 +  table._M_am_pm[0] = _WLocale_am_str(time, _STLP_ARRAY_AND_SIZE(buf));
   1.145 +  table._M_am_pm[1] = _WLocale_pm_str(time, _STLP_ARRAY_AND_SIZE(buf));
   1.146 +  _Init_timeinfo_base(table, time);
   1.147 +}
   1.148 +#endif
   1.149 +
   1.150 +template <class _Ch, class _TimeInfo>
   1.151 +void __subformat(_STLP_BASIC_IOSTRING(_Ch) &buf, const ctype<_Ch>& ct,
   1.152 +                 const string& format, const _TimeInfo& table, const tm* t) {
   1.153 +  const char * cp = format.data();
   1.154 +  const char * cp_end = cp + format.size();
   1.155 +  while (cp != cp_end) {
   1.156 +    if (*cp == '%') {
   1.157 +      char mod = 0;
   1.158 +      ++cp;
   1.159 +      if (*cp == '#') {
   1.160 +        mod = *cp; ++cp;
   1.161 +      }
   1.162 +      __write_formatted_timeT(buf, ct, *cp++, mod, table, t);
   1.163 +    } else
   1.164 +      buf.append(1, *cp++);
   1.165 +  }
   1.166 +}
   1.167 +
   1.168 +static void __append(__iostring &buf, const string& name)
   1.169 +{ buf.append(name.data(), name.data() + name.size()); }
   1.170 +
   1.171 +static void __append(__iowstring &buf, const wstring& name)
   1.172 +{ buf.append(name.data(), name.data() + name.size()); }
   1.173 +
   1.174 +static void __append(__iostring &buf, char *first, char *last, const ctype<char>& /* ct */)
   1.175 +{ buf.append(first, last); }
   1.176 +
   1.177 +static void __append(__iowstring &buf, char *first, char *last, const ctype<wchar_t>& ct) {
   1.178 +  wchar_t _wbuf[64];
   1.179 +  ct.widen(first, last, _wbuf);
   1.180 +  buf.append(_wbuf, _wbuf + (last - first));
   1.181 +}
   1.182 +
   1.183 +#if defined (__GNUC__)
   1.184 +/* The number of days from the first day of the first ISO week of this
   1.185 +   year to the year day YDAY with week day WDAY.  ISO weeks start on
   1.186 +   Monday; the first ISO week has the year's first Thursday.  YDAY may
   1.187 +   be as small as YDAY_MINIMUM.  */
   1.188 +#  define __ISO_WEEK_START_WDAY 1 /* Monday */
   1.189 +#  define __ISO_WEEK1_WDAY 4 /* Thursday */
   1.190 +#  define __YDAY_MINIMUM (-366)
   1.191 +#  define __TM_YEAR_BASE 1900
   1.192 +static int
   1.193 +__iso_week_days(int yday, int wday) {
   1.194 +  /* Add enough to the first operand of % to make it nonnegative.  */
   1.195 +  int big_enough_multiple_of_7 = (-__YDAY_MINIMUM / 7 + 2) * 7;
   1.196 +  return (yday
   1.197 +          - (yday - wday + __ISO_WEEK1_WDAY + big_enough_multiple_of_7) % 7
   1.198 +          + __ISO_WEEK1_WDAY - __ISO_WEEK_START_WDAY);
   1.199 +}
   1.200 +
   1.201 +#  define __is_leap(year)\
   1.202 +  ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
   1.203 +
   1.204 +#endif
   1.205 +
   1.206 +#define __hour12(hour) \
   1.207 +  (((hour) % 12 == 0) ? (12) : (hour) % 12)
   1.208 +
   1.209 +#if !defined (_STLP_USE_SAFE_STRING_FUNCTIONS)
   1.210 +#  define _STLP_SPRINTF sprintf
   1.211 +#else
   1.212 +#  define _STLP_SPRINTF sprintf_s
   1.213 +#endif
   1.214 +
   1.215 +template <class _Ch, class _TimeInfo>
   1.216 +void _STLP_CALL __write_formatted_timeT(_STLP_BASIC_IOSTRING(_Ch) &buf,
   1.217 +                                        const ctype<_Ch>& ct,
   1.218 +                                        char format, char modifier,
   1.219 +                                        const _TimeInfo& table, const tm* t) {
   1.220 +  char _buf[64];
   1.221 +  char *_bend;
   1.222 +
   1.223 +  switch (format) {
   1.224 +    case 'a':
   1.225 +      __append(buf, table._M_dayname[t->tm_wday]);
   1.226 +      break;
   1.227 +
   1.228 +    case 'A':
   1.229 +      __append(buf, table._M_dayname[t->tm_wday + 7]);
   1.230 +      break;
   1.231 +
   1.232 +    case 'b':
   1.233 +      __append(buf, table._M_monthname[t->tm_mon]);
   1.234 +      break;
   1.235 +
   1.236 +    case 'B':
   1.237 +      __append(buf, table._M_monthname[t->tm_mon + 12]);
   1.238 +      break;
   1.239 +
   1.240 +    case 'c':
   1.241 +      __subformat(buf, ct, (modifier != '#') ? table._M_date_time_format
   1.242 +                                             : table._M_long_date_time_format, table, t);
   1.243 +      break;
   1.244 +
   1.245 +    case 'd':
   1.246 +      _STLP_SPRINTF(_buf, (modifier != '#') ? "%.2ld" : "%ld", (long)t->tm_mday);
   1.247 +      __append(buf, _buf, ((long)t->tm_mday < 10L && modifier == '#') ? _buf + 1 : _buf + 2, ct);
   1.248 +      break;
   1.249 +
   1.250 +    case 'e':
   1.251 +      _STLP_SPRINTF(_buf, "%2ld", (long)t->tm_mday);
   1.252 +      __append(buf, _buf, _buf + 2, ct);
   1.253 +      break;
   1.254 +
   1.255 +    case 'H':
   1.256 +      _STLP_SPRINTF(_buf, (modifier != '#') ? "%.2ld" : "%ld", (long)t->tm_hour);
   1.257 +      __append(buf, _buf, ((long)t->tm_hour < 10L && modifier == '#') ? _buf + 1 : _buf + 2, ct);
   1.258 +      break;
   1.259 +
   1.260 +    case 'I':
   1.261 +      _STLP_SPRINTF(_buf, (modifier != '#') ? "%.2ld" : "%ld", (long)__hour12(t->tm_hour));
   1.262 +      __append(buf, _buf, ((long)__hour12(t->tm_hour) < 10L && modifier == '#') ? _buf + 1 : _buf + 2, ct);
   1.263 +      break;
   1.264 +
   1.265 +    case 'j':
   1.266 +      _bend = __write_integer(_buf, 0, (long)((long)t->tm_yday + 1));
   1.267 +      __append(buf, _buf, _bend, ct);
   1.268 +      break;
   1.269 +
   1.270 +    case 'm':
   1.271 +      _STLP_SPRINTF(_buf, (modifier != '#') ? "%.2ld" : "%ld", (long)t->tm_mon + 1);
   1.272 +      __append(buf, _buf, ((long)(t->tm_mon + 1) < 10L && modifier == '#') ? _buf + 1 : _buf + 2, ct);
   1.273 +      break;
   1.274 +
   1.275 +    case 'M':
   1.276 +      _STLP_SPRINTF(_buf, (modifier != '#') ? "%.2ld" : "%ld", (long)t->tm_min);
   1.277 +      __append(buf, _buf, ((long)t->tm_min < 10L && modifier == '#') ? _buf + 1 : _buf + 2, ct);
   1.278 +      break;
   1.279 +
   1.280 +    case 'p':
   1.281 +      __append(buf, table._M_am_pm[t->tm_hour / 12]);
   1.282 +      break;
   1.283 +
   1.284 +    case 'S': // pad with zeros
   1.285 +       _STLP_SPRINTF(_buf, (modifier != '#') ? "%.2ld" : "%ld", (long)t->tm_sec);
   1.286 +       __append(buf, _buf, ((long)t->tm_sec < 10L && modifier == '#') ? _buf + 1 : _buf + 2, ct);
   1.287 +       break;
   1.288 +
   1.289 +    case 'U':
   1.290 +      _bend = __write_integer(_buf, 0, long((t->tm_yday - t->tm_wday + 7) / 7));
   1.291 +      __append(buf, _buf, _bend, ct);
   1.292 +      break;
   1.293 +
   1.294 +    case 'w':
   1.295 +      _bend = __write_integer(_buf, 0, (long)t->tm_wday);
   1.296 +      __append(buf, _buf, _bend, ct);
   1.297 +      break;
   1.298 +
   1.299 +    case 'W':
   1.300 +      _bend = __write_integer(_buf, 0,
   1.301 +                             (long)(t->tm_wday == 0 ? (t->tm_yday + 1) / 7 :
   1.302 +                                                      (t->tm_yday + 8 - t->tm_wday) / 7));
   1.303 +      __append(buf, _buf, _bend, ct);
   1.304 +      break;
   1.305 +
   1.306 +    case'x':
   1.307 +      __subformat(buf, ct, (modifier != '#') ? table._M_date_format
   1.308 +                                             : table._M_long_date_format, table, t);
   1.309 +      break;
   1.310 +
   1.311 +    case 'X':
   1.312 +      __subformat(buf, ct, table._M_time_format, table, t);
   1.313 +      break;
   1.314 +
   1.315 +    case 'y':
   1.316 +      _bend = __write_integer(_buf, 0, (long)((long)(t->tm_year + 1900) % 100));
   1.317 +      __append(buf, _buf, _bend, ct);
   1.318 +      break;
   1.319 +
   1.320 +    case 'Y':
   1.321 +      _bend = __write_integer(_buf, 0, (long)((long)t->tm_year + 1900));
   1.322 +      __append(buf, _buf, _bend, ct);
   1.323 +      break;
   1.324 +
   1.325 +    case '%':
   1.326 +      buf.append(1, ct.widen('%'));
   1.327 +      break;
   1.328 +
   1.329 +#if defined (__GNUC__)
   1.330 +      // fbp : at least on SUN
   1.331 +#  if defined (_STLP_UNIX) && !defined (__linux__)
   1.332 +#    define __USE_BSD 1
   1.333 +#  endif
   1.334 +
   1.335 +   /*********************************************
   1.336 +    *     JGS, handle various extensions        *
   1.337 +    *********************************************/
   1.338 +
   1.339 +    case 'h': /* POSIX.2 extension */
   1.340 +      // same as 'b', abbrev month name
   1.341 +      __append(buf, table._M_monthname[t->tm_mon]);
   1.342 +      break;
   1.343 +    case 'C': /* POSIX.2 extension */
   1.344 +      // same as 'd', the day
   1.345 +      _STLP_SPRINTF(_buf, "%2ld", (long)t->tm_mday);
   1.346 +      __append(buf, _buf, _buf + 2, ct);
   1.347 +      break;
   1.348 +
   1.349 +    case 'D': /* POSIX.2 extension */
   1.350 +      // same as 'x'
   1.351 +      __subformat(buf, ct, table._M_date_format, table, t);
   1.352 +      break;
   1.353 +
   1.354 +    case 'k': /* GNU extension */
   1.355 +      _STLP_SPRINTF(_buf, "%2ld", (long)t->tm_hour);
   1.356 +      __append(buf, _buf, _buf + 2, ct);
   1.357 +      break;
   1.358 +
   1.359 +    case 'l': /* GNU extension */
   1.360 +      _STLP_SPRINTF(_buf, "%2ld", (long)t->tm_hour % 12);
   1.361 +      __append(buf, _buf, _buf + 2, ct);
   1.362 +      break;
   1.363 +
   1.364 +    case 'n': /* POSIX.2 extension */
   1.365 +      buf.append(1, ct.widen('\n'));
   1.366 +      break;
   1.367 +
   1.368 +    case 'R': /* GNU extension */
   1.369 +      __subformat(buf, ct, "%H:%M", table, t);
   1.370 +      break;
   1.371 +
   1.372 +    case 'r': /* POSIX.2 extension */
   1.373 +      __subformat(buf, ct, "%I:%M:%S %p", table, t);
   1.374 +      break;
   1.375 +
   1.376 +    case 'T': /* POSIX.2 extension.  */
   1.377 +      __subformat(buf, ct, "%H:%M:%S", table, t);
   1.378 +      break;
   1.379 +
   1.380 +    case 't': /* POSIX.2 extension.  */
   1.381 +      buf.append(1, ct.widen('\t'));
   1.382 +
   1.383 +    case 'u': /* POSIX.2 extension.  */
   1.384 +      _bend = __write_integer(_buf, 0, long((t->tm_wday - 1 + 7)) % 7 + 1);
   1.385 +      __append(buf, _buf, _bend, ct);
   1.386 +      break;
   1.387 +
   1.388 +    case 's': {
   1.389 +      time_t __t = mktime(__CONST_CAST(tm*, t));
   1.390 +      _bend = __write_integer(_buf, 0, (long)__t );
   1.391 +      __append(buf, _buf, _bend, ct);
   1.392 +      break;
   1.393 +    }
   1.394 +    case 'g': /* GNU extension */
   1.395 +    case 'G': {
   1.396 +      int year = t->tm_year + __TM_YEAR_BASE;
   1.397 +      int days = __iso_week_days (t->tm_yday, t->tm_wday);
   1.398 +      if (days < 0) {
   1.399 +        /* This ISO week belongs to the previous year.  */
   1.400 +        year--;
   1.401 +        days = __iso_week_days (t->tm_yday + (365 + __is_leap (year)), t->tm_wday);
   1.402 +      }
   1.403 +      else {
   1.404 +        int d = __iso_week_days (t->tm_yday - (365 + __is_leap (year)), t->tm_wday);
   1.405 +        if (0 <= d) {
   1.406 +          /* This ISO week belongs to the next year.  */
   1.407 +          ++year;
   1.408 +          days = d;
   1.409 +        }
   1.410 +      }
   1.411 +      long val;
   1.412 +      switch (format) {
   1.413 +      case 'g':
   1.414 +        val = (long)(year % 100 + 100) % 100;
   1.415 +        break;
   1.416 +      case 'G':
   1.417 +        val = (long)year;
   1.418 +        break;
   1.419 +      default:
   1.420 +        val = (long)days / 7 + 1;
   1.421 +        break;
   1.422 +      }
   1.423 +      _bend = __write_integer(_buf, 0, val);
   1.424 +      __append(buf, _buf, _bend, ct);
   1.425 +      break;
   1.426 +    }
   1.427 +
   1.428 +#  if defined (_STLP_USE_GLIBC)
   1.429 +    case 'z':   /* GNU extension.  */
   1.430 +      if (t->tm_isdst < 0)
   1.431 +        break;
   1.432 +      {
   1.433 +        int diff;
   1.434 +#    if defined (__USE_BSD) || defined (__BEOS__)
   1.435 +        diff = t->tm_gmtoff;
   1.436 +#    else
   1.437 +        diff = t->__tm_gmtoff;
   1.438 +#    endif
   1.439 +        if (diff < 0) {
   1.440 +          buf.append(1, ct.widen('-'));
   1.441 +          diff = -diff;
   1.442 +        } else
   1.443 +          buf.append(1, ct.widen('+'));
   1.444 +        diff /= 60;
   1.445 +        _STLP_SPRINTF(_buf, "%.4d", (diff / 60) * 100 + diff % 60);
   1.446 +        __append(buf, _buf, _buf + 4, ct);
   1.447 +        break;
   1.448 +      }
   1.449 +#  endif /* __GLIBC__ */
   1.450 +#endif /* __GNUC__ */
   1.451 +
   1.452 +    default:
   1.453 +      break;
   1.454 +  }
   1.455 +}
   1.456 +
   1.457 +void _STLP_CALL __write_formatted_time(__iostring &buf, const ctype<char>& ct,
   1.458 +                                       char format, char modifier,
   1.459 +                                       const _Time_Info& table, const tm* t)
   1.460 +{ __write_formatted_timeT(buf, ct, format, modifier, table, t); }
   1.461 +
   1.462 +void _STLP_CALL __write_formatted_time(__iowstring &buf, const ctype<wchar_t>& ct,
   1.463 +                                       char format, char modifier,
   1.464 +                                       const _WTime_Info& table, const tm* t)
   1.465 +{ __write_formatted_timeT(buf, ct, format, modifier, table, t); }
   1.466 +
   1.467 +static time_base::dateorder __get_date_order(_Locale_time* time) {
   1.468 +  const char * fmt = _Locale_d_fmt(time);
   1.469 +  char first, second, third;
   1.470 +
   1.471 +  while (*fmt != 0 && *fmt != '%') ++fmt;
   1.472 +  if (*fmt == 0)
   1.473 +    return time_base::no_order;
   1.474 +  first = *++fmt;
   1.475 +  while (*fmt != 0 && *fmt != '%') ++fmt;
   1.476 +  if (*fmt == 0)
   1.477 +    return time_base::no_order;
   1.478 +  second = *++fmt;
   1.479 +  while (*fmt != 0 && *fmt != '%') ++fmt;
   1.480 +  if (*fmt == 0)
   1.481 +    return time_base::no_order;
   1.482 +  third = *++fmt;
   1.483 +
   1.484 +  switch (first) {
   1.485 +    case 'd':
   1.486 +      return (second == 'm' && third == 'y') ? time_base::dmy
   1.487 +                                             : time_base::no_order;
   1.488 +    case 'm':
   1.489 +      return (second == 'd' && third == 'y') ? time_base::mdy
   1.490 +                                             : time_base::no_order;
   1.491 +    case 'y':
   1.492 +      switch (second) {
   1.493 +        case 'd':
   1.494 +          return third == 'm' ? time_base::ydm : time_base::no_order;
   1.495 +        case 'm':
   1.496 +          return third == 'd' ? time_base::ymd : time_base::no_order;
   1.497 +        default:
   1.498 +          return time_base::no_order;
   1.499 +      }
   1.500 +    default:
   1.501 +      return time_base::no_order;
   1.502 +  }
   1.503 +}
   1.504 +
   1.505 +time_init<char>::time_init()
   1.506 +  : _M_dateorder(time_base::no_order)
   1.507 +{ _Init_timeinfo(_M_timeinfo); }
   1.508 +
   1.509 +time_init<char>::time_init(const char* __name) {
   1.510 +  if (!__name)
   1.511 +    locale::_M_throw_on_null_name();
   1.512 +
   1.513 +  int __err_code;
   1.514 +  char buf[_Locale_MAX_SIMPLE_NAME];
   1.515 +  _Locale_time *__time = __acquire_time(__name, buf, 0, &__err_code);
   1.516 +  if (!__time)
   1.517 +    locale::_M_throw_on_creation_failure(__err_code, __name, "time");
   1.518 +
   1.519 +  _Init_timeinfo(this->_M_timeinfo, __time);
   1.520 +  _M_dateorder = __get_date_order(__time);
   1.521 +  __release_time(__time);
   1.522 +}
   1.523 +
   1.524 +time_init<char>::time_init(_Locale_time *__time) {
   1.525 +  _Init_timeinfo(this->_M_timeinfo, __time);
   1.526 +  _M_dateorder = __get_date_order(__time);
   1.527 +}
   1.528 +
   1.529 +#ifndef _STLP_NO_WCHAR_T
   1.530 +time_init<wchar_t>::time_init()
   1.531 +  : _M_dateorder(time_base::no_order)
   1.532 +{ _Init_timeinfo(_M_timeinfo); }
   1.533 +
   1.534 +time_init<wchar_t>::time_init(const char* __name) {
   1.535 +  if (!__name)
   1.536 +    locale::_M_throw_on_null_name();
   1.537 +
   1.538 +  int __err_code;
   1.539 +  char buf[_Locale_MAX_SIMPLE_NAME];
   1.540 +  _Locale_time *__time = __acquire_time(__name, buf, 0, &__err_code);
   1.541 +  if (!__time)
   1.542 +    locale::_M_throw_on_creation_failure(__err_code, __name, "time");
   1.543 +
   1.544 +  _Init_timeinfo(this->_M_timeinfo, __time);
   1.545 +  _M_dateorder = __get_date_order(__time);
   1.546 +  __release_time(__time);
   1.547 +}
   1.548 +
   1.549 +time_init<wchar_t>::time_init(_Locale_time *__time) {
   1.550 +  _Init_timeinfo(this->_M_timeinfo, __time);
   1.551 +  _M_dateorder = __get_date_order(__time);
   1.552 +}
   1.553 +#endif
   1.554 +
   1.555 +_STLP_MOVE_TO_STD_NAMESPACE
   1.556 +
   1.557 +#if !defined (_STLP_NO_FORCE_INSTANTIATE)
   1.558 +template class time_get<char, istreambuf_iterator<char, char_traits<char> > >;
   1.559 +template class time_put<char, ostreambuf_iterator<char, char_traits<char> > >;
   1.560 +
   1.561 +#  ifndef _STLP_NO_WCHAR_T
   1.562 +template class time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
   1.563 +template class time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
   1.564 +#  endif
   1.565 +
   1.566 +#endif
   1.567 +
   1.568 +_STLP_END_NAMESPACE

mercurial