build/stlport/src/time_facets.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright (c) 1999
michael@0 3 * Silicon Graphics Computer Systems, Inc.
michael@0 4 *
michael@0 5 * Copyright (c) 1999
michael@0 6 * Boris Fomitchev
michael@0 7 *
michael@0 8 * This material is provided "as is", with absolutely no warranty expressed
michael@0 9 * or implied. Any use is at your own risk.
michael@0 10 *
michael@0 11 * Permission to use or copy this software for any purpose is hereby granted
michael@0 12 * without fee, provided the above notices are retained on all copies.
michael@0 13 * Permission to modify the code and to distribute modified code is granted,
michael@0 14 * provided the above notices are retained, and a notice that the code was
michael@0 15 * modified is included with the above copyright notice.
michael@0 16 *
michael@0 17 */
michael@0 18
michael@0 19 #include "stlport_prefix.h"
michael@0 20
michael@0 21 #include <cstdio>
michael@0 22 #include <locale>
michael@0 23 #include <istream>
michael@0 24
michael@0 25 #include "c_locale.h"
michael@0 26 #include "acquire_release.h"
michael@0 27
michael@0 28 _STLP_BEGIN_NAMESPACE
michael@0 29
michael@0 30 _STLP_MOVE_TO_PRIV_NAMESPACE
michael@0 31
michael@0 32 // default "C" values for month and day names
michael@0 33
michael@0 34 const char default_dayname[][14] = {
michael@0 35 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
michael@0 36 "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
michael@0 37 "Friday", "Saturday"};
michael@0 38
michael@0 39 const char default_monthname[][24] = {
michael@0 40 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
michael@0 41 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
michael@0 42 "January", "February", "March", "April", "May", "June",
michael@0 43 "July", "August", "September", "October", "November", "December"};
michael@0 44
michael@0 45 #ifndef _STLP_NO_WCHAR_T
michael@0 46 const wchar_t default_wdayname[][14] = {
michael@0 47 L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat",
michael@0 48 L"Sunday", L"Monday", L"Tuesday", L"Wednesday", L"Thursday",
michael@0 49 L"Friday", L"Saturday"};
michael@0 50
michael@0 51 const wchar_t default_wmonthname[][24] = {
michael@0 52 L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun",
michael@0 53 L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec",
michael@0 54 L"January", L"February", L"March", L"April", L"May", L"June",
michael@0 55 L"July", L"August", L"September", L"October", L"November", L"December"};
michael@0 56 #endif
michael@0 57
michael@0 58 #if defined (__BORLANDC__)
michael@0 59 _Time_Info time_init<char>::_M_timeinfo;
michael@0 60 # ifndef _STLP_NO_WCHAR_T
michael@0 61 _WTime_Info time_init<wchar_t>::_M_timeinfo;
michael@0 62 # endif
michael@0 63 #endif
michael@0 64
michael@0 65 // _Init_time_info: initialize table with
michael@0 66 // "C" values (note these are not defined in the C standard, so this
michael@0 67 // is somewhat arbitrary).
michael@0 68
michael@0 69 static void _Init_timeinfo_base(_Time_Info_Base& table) {
michael@0 70 table._M_time_format = "%H:%M:%S";
michael@0 71 table._M_date_format = "%m/%d/%y";
michael@0 72 table._M_date_time_format = "%m/%d/%y";
michael@0 73 }
michael@0 74
michael@0 75 static void _Init_timeinfo(_Time_Info& table) {
michael@0 76 int i;
michael@0 77 for (i = 0; i < 14; ++i)
michael@0 78 table._M_dayname[i] = default_dayname[i];
michael@0 79 for (i = 0; i < 24; ++i)
michael@0 80 table._M_monthname[i] = default_monthname[i];
michael@0 81 table._M_am_pm[0] = "AM";
michael@0 82 table._M_am_pm[1] = "PM";
michael@0 83 _Init_timeinfo_base(table);
michael@0 84 }
michael@0 85
michael@0 86 #ifndef _STLP_NO_WCHAR_T
michael@0 87 static void _Init_timeinfo(_WTime_Info& table) {
michael@0 88 int i;
michael@0 89 for (i = 0; i < 14; ++i)
michael@0 90 table._M_dayname[i] = default_wdayname[i];
michael@0 91 for (i = 0; i < 24; ++i)
michael@0 92 table._M_monthname[i] = default_wmonthname[i];
michael@0 93 table._M_am_pm[0] = L"AM";
michael@0 94 table._M_am_pm[1] = L"PM";
michael@0 95 _Init_timeinfo_base(table);
michael@0 96 }
michael@0 97 #endif
michael@0 98
michael@0 99 static void _Init_timeinfo_base(_Time_Info_Base& table, _Locale_time * time) {
michael@0 100 table._M_time_format = _Locale_t_fmt(time);
michael@0 101 if ( table._M_time_format == "%T" ) {
michael@0 102 table._M_time_format = "%H:%M:%S";
michael@0 103 } else if ( table._M_time_format == "%r" ) {
michael@0 104 table._M_time_format = "%I:%M:%S %p";
michael@0 105 } else if ( table._M_time_format == "%R" ) {
michael@0 106 table._M_time_format = "%H:%M";
michael@0 107 }
michael@0 108 table._M_date_format = _Locale_d_fmt(time);
michael@0 109 table._M_date_time_format = _Locale_d_t_fmt(time);
michael@0 110 table._M_long_date_format = _Locale_long_d_fmt(time);
michael@0 111 table._M_long_date_time_format = _Locale_long_d_t_fmt(time);
michael@0 112 }
michael@0 113
michael@0 114 static void _Init_timeinfo(_Time_Info& table, _Locale_time * time) {
michael@0 115 int i;
michael@0 116 for (i = 0; i < 7; ++i)
michael@0 117 table._M_dayname[i] = _Locale_abbrev_dayofweek(time, i);
michael@0 118 for (i = 0; i < 7; ++i)
michael@0 119 table._M_dayname[i+7] = _Locale_full_dayofweek(time, i);
michael@0 120 for (i = 0; i < 12; ++i)
michael@0 121 table._M_monthname[i] = _Locale_abbrev_monthname(time, i);
michael@0 122 for (i = 0; i < 12; ++i)
michael@0 123 table._M_monthname[i+12] = _Locale_full_monthname(time, i);
michael@0 124 table._M_am_pm[0] = _Locale_am_str(time);
michael@0 125 table._M_am_pm[1] = _Locale_pm_str(time);
michael@0 126 _Init_timeinfo_base(table, time);
michael@0 127 }
michael@0 128
michael@0 129 #ifndef _STLP_NO_WCHAR_T
michael@0 130 static void _Init_timeinfo(_WTime_Info& table, _Locale_time * time) {
michael@0 131 wchar_t buf[128];
michael@0 132 int i;
michael@0 133 for (i = 0; i < 7; ++i)
michael@0 134 table._M_dayname[i] = _WLocale_abbrev_dayofweek(time, i, _STLP_ARRAY_AND_SIZE(buf));
michael@0 135 for (i = 0; i < 7; ++i)
michael@0 136 table._M_dayname[i+7] = _WLocale_full_dayofweek(time, i, _STLP_ARRAY_AND_SIZE(buf));
michael@0 137 for (i = 0; i < 12; ++i)
michael@0 138 table._M_monthname[i] = _WLocale_abbrev_monthname(time, i, _STLP_ARRAY_AND_SIZE(buf));
michael@0 139 for (i = 0; i < 12; ++i)
michael@0 140 table._M_monthname[i+12] = _WLocale_full_monthname(time, i, _STLP_ARRAY_AND_SIZE(buf));
michael@0 141 table._M_am_pm[0] = _WLocale_am_str(time, _STLP_ARRAY_AND_SIZE(buf));
michael@0 142 table._M_am_pm[1] = _WLocale_pm_str(time, _STLP_ARRAY_AND_SIZE(buf));
michael@0 143 _Init_timeinfo_base(table, time);
michael@0 144 }
michael@0 145 #endif
michael@0 146
michael@0 147 template <class _Ch, class _TimeInfo>
michael@0 148 void __subformat(_STLP_BASIC_IOSTRING(_Ch) &buf, const ctype<_Ch>& ct,
michael@0 149 const string& format, const _TimeInfo& table, const tm* t) {
michael@0 150 const char * cp = format.data();
michael@0 151 const char * cp_end = cp + format.size();
michael@0 152 while (cp != cp_end) {
michael@0 153 if (*cp == '%') {
michael@0 154 char mod = 0;
michael@0 155 ++cp;
michael@0 156 if (*cp == '#') {
michael@0 157 mod = *cp; ++cp;
michael@0 158 }
michael@0 159 __write_formatted_timeT(buf, ct, *cp++, mod, table, t);
michael@0 160 } else
michael@0 161 buf.append(1, *cp++);
michael@0 162 }
michael@0 163 }
michael@0 164
michael@0 165 static void __append(__iostring &buf, const string& name)
michael@0 166 { buf.append(name.data(), name.data() + name.size()); }
michael@0 167
michael@0 168 static void __append(__iowstring &buf, const wstring& name)
michael@0 169 { buf.append(name.data(), name.data() + name.size()); }
michael@0 170
michael@0 171 static void __append(__iostring &buf, char *first, char *last, const ctype<char>& /* ct */)
michael@0 172 { buf.append(first, last); }
michael@0 173
michael@0 174 static void __append(__iowstring &buf, char *first, char *last, const ctype<wchar_t>& ct) {
michael@0 175 wchar_t _wbuf[64];
michael@0 176 ct.widen(first, last, _wbuf);
michael@0 177 buf.append(_wbuf, _wbuf + (last - first));
michael@0 178 }
michael@0 179
michael@0 180 #if defined (__GNUC__)
michael@0 181 /* The number of days from the first day of the first ISO week of this
michael@0 182 year to the year day YDAY with week day WDAY. ISO weeks start on
michael@0 183 Monday; the first ISO week has the year's first Thursday. YDAY may
michael@0 184 be as small as YDAY_MINIMUM. */
michael@0 185 # define __ISO_WEEK_START_WDAY 1 /* Monday */
michael@0 186 # define __ISO_WEEK1_WDAY 4 /* Thursday */
michael@0 187 # define __YDAY_MINIMUM (-366)
michael@0 188 # define __TM_YEAR_BASE 1900
michael@0 189 static int
michael@0 190 __iso_week_days(int yday, int wday) {
michael@0 191 /* Add enough to the first operand of % to make it nonnegative. */
michael@0 192 int big_enough_multiple_of_7 = (-__YDAY_MINIMUM / 7 + 2) * 7;
michael@0 193 return (yday
michael@0 194 - (yday - wday + __ISO_WEEK1_WDAY + big_enough_multiple_of_7) % 7
michael@0 195 + __ISO_WEEK1_WDAY - __ISO_WEEK_START_WDAY);
michael@0 196 }
michael@0 197
michael@0 198 # define __is_leap(year)\
michael@0 199 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
michael@0 200
michael@0 201 #endif
michael@0 202
michael@0 203 #define __hour12(hour) \
michael@0 204 (((hour) % 12 == 0) ? (12) : (hour) % 12)
michael@0 205
michael@0 206 #if !defined (_STLP_USE_SAFE_STRING_FUNCTIONS)
michael@0 207 # define _STLP_SPRINTF sprintf
michael@0 208 #else
michael@0 209 # define _STLP_SPRINTF sprintf_s
michael@0 210 #endif
michael@0 211
michael@0 212 template <class _Ch, class _TimeInfo>
michael@0 213 void _STLP_CALL __write_formatted_timeT(_STLP_BASIC_IOSTRING(_Ch) &buf,
michael@0 214 const ctype<_Ch>& ct,
michael@0 215 char format, char modifier,
michael@0 216 const _TimeInfo& table, const tm* t) {
michael@0 217 char _buf[64];
michael@0 218 char *_bend;
michael@0 219
michael@0 220 switch (format) {
michael@0 221 case 'a':
michael@0 222 __append(buf, table._M_dayname[t->tm_wday]);
michael@0 223 break;
michael@0 224
michael@0 225 case 'A':
michael@0 226 __append(buf, table._M_dayname[t->tm_wday + 7]);
michael@0 227 break;
michael@0 228
michael@0 229 case 'b':
michael@0 230 __append(buf, table._M_monthname[t->tm_mon]);
michael@0 231 break;
michael@0 232
michael@0 233 case 'B':
michael@0 234 __append(buf, table._M_monthname[t->tm_mon + 12]);
michael@0 235 break;
michael@0 236
michael@0 237 case 'c':
michael@0 238 __subformat(buf, ct, (modifier != '#') ? table._M_date_time_format
michael@0 239 : table._M_long_date_time_format, table, t);
michael@0 240 break;
michael@0 241
michael@0 242 case 'd':
michael@0 243 _STLP_SPRINTF(_buf, (modifier != '#') ? "%.2ld" : "%ld", (long)t->tm_mday);
michael@0 244 __append(buf, _buf, ((long)t->tm_mday < 10L && modifier == '#') ? _buf + 1 : _buf + 2, ct);
michael@0 245 break;
michael@0 246
michael@0 247 case 'e':
michael@0 248 _STLP_SPRINTF(_buf, "%2ld", (long)t->tm_mday);
michael@0 249 __append(buf, _buf, _buf + 2, ct);
michael@0 250 break;
michael@0 251
michael@0 252 case 'H':
michael@0 253 _STLP_SPRINTF(_buf, (modifier != '#') ? "%.2ld" : "%ld", (long)t->tm_hour);
michael@0 254 __append(buf, _buf, ((long)t->tm_hour < 10L && modifier == '#') ? _buf + 1 : _buf + 2, ct);
michael@0 255 break;
michael@0 256
michael@0 257 case 'I':
michael@0 258 _STLP_SPRINTF(_buf, (modifier != '#') ? "%.2ld" : "%ld", (long)__hour12(t->tm_hour));
michael@0 259 __append(buf, _buf, ((long)__hour12(t->tm_hour) < 10L && modifier == '#') ? _buf + 1 : _buf + 2, ct);
michael@0 260 break;
michael@0 261
michael@0 262 case 'j':
michael@0 263 _bend = __write_integer(_buf, 0, (long)((long)t->tm_yday + 1));
michael@0 264 __append(buf, _buf, _bend, ct);
michael@0 265 break;
michael@0 266
michael@0 267 case 'm':
michael@0 268 _STLP_SPRINTF(_buf, (modifier != '#') ? "%.2ld" : "%ld", (long)t->tm_mon + 1);
michael@0 269 __append(buf, _buf, ((long)(t->tm_mon + 1) < 10L && modifier == '#') ? _buf + 1 : _buf + 2, ct);
michael@0 270 break;
michael@0 271
michael@0 272 case 'M':
michael@0 273 _STLP_SPRINTF(_buf, (modifier != '#') ? "%.2ld" : "%ld", (long)t->tm_min);
michael@0 274 __append(buf, _buf, ((long)t->tm_min < 10L && modifier == '#') ? _buf + 1 : _buf + 2, ct);
michael@0 275 break;
michael@0 276
michael@0 277 case 'p':
michael@0 278 __append(buf, table._M_am_pm[t->tm_hour / 12]);
michael@0 279 break;
michael@0 280
michael@0 281 case 'S': // pad with zeros
michael@0 282 _STLP_SPRINTF(_buf, (modifier != '#') ? "%.2ld" : "%ld", (long)t->tm_sec);
michael@0 283 __append(buf, _buf, ((long)t->tm_sec < 10L && modifier == '#') ? _buf + 1 : _buf + 2, ct);
michael@0 284 break;
michael@0 285
michael@0 286 case 'U':
michael@0 287 _bend = __write_integer(_buf, 0, long((t->tm_yday - t->tm_wday + 7) / 7));
michael@0 288 __append(buf, _buf, _bend, ct);
michael@0 289 break;
michael@0 290
michael@0 291 case 'w':
michael@0 292 _bend = __write_integer(_buf, 0, (long)t->tm_wday);
michael@0 293 __append(buf, _buf, _bend, ct);
michael@0 294 break;
michael@0 295
michael@0 296 case 'W':
michael@0 297 _bend = __write_integer(_buf, 0,
michael@0 298 (long)(t->tm_wday == 0 ? (t->tm_yday + 1) / 7 :
michael@0 299 (t->tm_yday + 8 - t->tm_wday) / 7));
michael@0 300 __append(buf, _buf, _bend, ct);
michael@0 301 break;
michael@0 302
michael@0 303 case'x':
michael@0 304 __subformat(buf, ct, (modifier != '#') ? table._M_date_format
michael@0 305 : table._M_long_date_format, table, t);
michael@0 306 break;
michael@0 307
michael@0 308 case 'X':
michael@0 309 __subformat(buf, ct, table._M_time_format, table, t);
michael@0 310 break;
michael@0 311
michael@0 312 case 'y':
michael@0 313 _bend = __write_integer(_buf, 0, (long)((long)(t->tm_year + 1900) % 100));
michael@0 314 __append(buf, _buf, _bend, ct);
michael@0 315 break;
michael@0 316
michael@0 317 case 'Y':
michael@0 318 _bend = __write_integer(_buf, 0, (long)((long)t->tm_year + 1900));
michael@0 319 __append(buf, _buf, _bend, ct);
michael@0 320 break;
michael@0 321
michael@0 322 case '%':
michael@0 323 buf.append(1, ct.widen('%'));
michael@0 324 break;
michael@0 325
michael@0 326 #if defined (__GNUC__)
michael@0 327 // fbp : at least on SUN
michael@0 328 # if defined (_STLP_UNIX) && !defined (__linux__)
michael@0 329 # define __USE_BSD 1
michael@0 330 # endif
michael@0 331
michael@0 332 /*********************************************
michael@0 333 * JGS, handle various extensions *
michael@0 334 *********************************************/
michael@0 335
michael@0 336 case 'h': /* POSIX.2 extension */
michael@0 337 // same as 'b', abbrev month name
michael@0 338 __append(buf, table._M_monthname[t->tm_mon]);
michael@0 339 break;
michael@0 340 case 'C': /* POSIX.2 extension */
michael@0 341 // same as 'd', the day
michael@0 342 _STLP_SPRINTF(_buf, "%2ld", (long)t->tm_mday);
michael@0 343 __append(buf, _buf, _buf + 2, ct);
michael@0 344 break;
michael@0 345
michael@0 346 case 'D': /* POSIX.2 extension */
michael@0 347 // same as 'x'
michael@0 348 __subformat(buf, ct, table._M_date_format, table, t);
michael@0 349 break;
michael@0 350
michael@0 351 case 'k': /* GNU extension */
michael@0 352 _STLP_SPRINTF(_buf, "%2ld", (long)t->tm_hour);
michael@0 353 __append(buf, _buf, _buf + 2, ct);
michael@0 354 break;
michael@0 355
michael@0 356 case 'l': /* GNU extension */
michael@0 357 _STLP_SPRINTF(_buf, "%2ld", (long)t->tm_hour % 12);
michael@0 358 __append(buf, _buf, _buf + 2, ct);
michael@0 359 break;
michael@0 360
michael@0 361 case 'n': /* POSIX.2 extension */
michael@0 362 buf.append(1, ct.widen('\n'));
michael@0 363 break;
michael@0 364
michael@0 365 case 'R': /* GNU extension */
michael@0 366 __subformat(buf, ct, "%H:%M", table, t);
michael@0 367 break;
michael@0 368
michael@0 369 case 'r': /* POSIX.2 extension */
michael@0 370 __subformat(buf, ct, "%I:%M:%S %p", table, t);
michael@0 371 break;
michael@0 372
michael@0 373 case 'T': /* POSIX.2 extension. */
michael@0 374 __subformat(buf, ct, "%H:%M:%S", table, t);
michael@0 375 break;
michael@0 376
michael@0 377 case 't': /* POSIX.2 extension. */
michael@0 378 buf.append(1, ct.widen('\t'));
michael@0 379
michael@0 380 case 'u': /* POSIX.2 extension. */
michael@0 381 _bend = __write_integer(_buf, 0, long((t->tm_wday - 1 + 7)) % 7 + 1);
michael@0 382 __append(buf, _buf, _bend, ct);
michael@0 383 break;
michael@0 384
michael@0 385 case 's': {
michael@0 386 time_t __t = mktime(__CONST_CAST(tm*, t));
michael@0 387 _bend = __write_integer(_buf, 0, (long)__t );
michael@0 388 __append(buf, _buf, _bend, ct);
michael@0 389 break;
michael@0 390 }
michael@0 391 case 'g': /* GNU extension */
michael@0 392 case 'G': {
michael@0 393 int year = t->tm_year + __TM_YEAR_BASE;
michael@0 394 int days = __iso_week_days (t->tm_yday, t->tm_wday);
michael@0 395 if (days < 0) {
michael@0 396 /* This ISO week belongs to the previous year. */
michael@0 397 year--;
michael@0 398 days = __iso_week_days (t->tm_yday + (365 + __is_leap (year)), t->tm_wday);
michael@0 399 }
michael@0 400 else {
michael@0 401 int d = __iso_week_days (t->tm_yday - (365 + __is_leap (year)), t->tm_wday);
michael@0 402 if (0 <= d) {
michael@0 403 /* This ISO week belongs to the next year. */
michael@0 404 ++year;
michael@0 405 days = d;
michael@0 406 }
michael@0 407 }
michael@0 408 long val;
michael@0 409 switch (format) {
michael@0 410 case 'g':
michael@0 411 val = (long)(year % 100 + 100) % 100;
michael@0 412 break;
michael@0 413 case 'G':
michael@0 414 val = (long)year;
michael@0 415 break;
michael@0 416 default:
michael@0 417 val = (long)days / 7 + 1;
michael@0 418 break;
michael@0 419 }
michael@0 420 _bend = __write_integer(_buf, 0, val);
michael@0 421 __append(buf, _buf, _bend, ct);
michael@0 422 break;
michael@0 423 }
michael@0 424
michael@0 425 # if defined (_STLP_USE_GLIBC)
michael@0 426 case 'z': /* GNU extension. */
michael@0 427 if (t->tm_isdst < 0)
michael@0 428 break;
michael@0 429 {
michael@0 430 int diff;
michael@0 431 # if defined (__USE_BSD) || defined (__BEOS__)
michael@0 432 diff = t->tm_gmtoff;
michael@0 433 # else
michael@0 434 diff = t->__tm_gmtoff;
michael@0 435 # endif
michael@0 436 if (diff < 0) {
michael@0 437 buf.append(1, ct.widen('-'));
michael@0 438 diff = -diff;
michael@0 439 } else
michael@0 440 buf.append(1, ct.widen('+'));
michael@0 441 diff /= 60;
michael@0 442 _STLP_SPRINTF(_buf, "%.4d", (diff / 60) * 100 + diff % 60);
michael@0 443 __append(buf, _buf, _buf + 4, ct);
michael@0 444 break;
michael@0 445 }
michael@0 446 # endif /* __GLIBC__ */
michael@0 447 #endif /* __GNUC__ */
michael@0 448
michael@0 449 default:
michael@0 450 break;
michael@0 451 }
michael@0 452 }
michael@0 453
michael@0 454 void _STLP_CALL __write_formatted_time(__iostring &buf, const ctype<char>& ct,
michael@0 455 char format, char modifier,
michael@0 456 const _Time_Info& table, const tm* t)
michael@0 457 { __write_formatted_timeT(buf, ct, format, modifier, table, t); }
michael@0 458
michael@0 459 void _STLP_CALL __write_formatted_time(__iowstring &buf, const ctype<wchar_t>& ct,
michael@0 460 char format, char modifier,
michael@0 461 const _WTime_Info& table, const tm* t)
michael@0 462 { __write_formatted_timeT(buf, ct, format, modifier, table, t); }
michael@0 463
michael@0 464 static time_base::dateorder __get_date_order(_Locale_time* time) {
michael@0 465 const char * fmt = _Locale_d_fmt(time);
michael@0 466 char first, second, third;
michael@0 467
michael@0 468 while (*fmt != 0 && *fmt != '%') ++fmt;
michael@0 469 if (*fmt == 0)
michael@0 470 return time_base::no_order;
michael@0 471 first = *++fmt;
michael@0 472 while (*fmt != 0 && *fmt != '%') ++fmt;
michael@0 473 if (*fmt == 0)
michael@0 474 return time_base::no_order;
michael@0 475 second = *++fmt;
michael@0 476 while (*fmt != 0 && *fmt != '%') ++fmt;
michael@0 477 if (*fmt == 0)
michael@0 478 return time_base::no_order;
michael@0 479 third = *++fmt;
michael@0 480
michael@0 481 switch (first) {
michael@0 482 case 'd':
michael@0 483 return (second == 'm' && third == 'y') ? time_base::dmy
michael@0 484 : time_base::no_order;
michael@0 485 case 'm':
michael@0 486 return (second == 'd' && third == 'y') ? time_base::mdy
michael@0 487 : time_base::no_order;
michael@0 488 case 'y':
michael@0 489 switch (second) {
michael@0 490 case 'd':
michael@0 491 return third == 'm' ? time_base::ydm : time_base::no_order;
michael@0 492 case 'm':
michael@0 493 return third == 'd' ? time_base::ymd : time_base::no_order;
michael@0 494 default:
michael@0 495 return time_base::no_order;
michael@0 496 }
michael@0 497 default:
michael@0 498 return time_base::no_order;
michael@0 499 }
michael@0 500 }
michael@0 501
michael@0 502 time_init<char>::time_init()
michael@0 503 : _M_dateorder(time_base::no_order)
michael@0 504 { _Init_timeinfo(_M_timeinfo); }
michael@0 505
michael@0 506 time_init<char>::time_init(const char* __name) {
michael@0 507 if (!__name)
michael@0 508 locale::_M_throw_on_null_name();
michael@0 509
michael@0 510 int __err_code;
michael@0 511 char buf[_Locale_MAX_SIMPLE_NAME];
michael@0 512 _Locale_time *__time = __acquire_time(__name, buf, 0, &__err_code);
michael@0 513 if (!__time)
michael@0 514 locale::_M_throw_on_creation_failure(__err_code, __name, "time");
michael@0 515
michael@0 516 _Init_timeinfo(this->_M_timeinfo, __time);
michael@0 517 _M_dateorder = __get_date_order(__time);
michael@0 518 __release_time(__time);
michael@0 519 }
michael@0 520
michael@0 521 time_init<char>::time_init(_Locale_time *__time) {
michael@0 522 _Init_timeinfo(this->_M_timeinfo, __time);
michael@0 523 _M_dateorder = __get_date_order(__time);
michael@0 524 }
michael@0 525
michael@0 526 #ifndef _STLP_NO_WCHAR_T
michael@0 527 time_init<wchar_t>::time_init()
michael@0 528 : _M_dateorder(time_base::no_order)
michael@0 529 { _Init_timeinfo(_M_timeinfo); }
michael@0 530
michael@0 531 time_init<wchar_t>::time_init(const char* __name) {
michael@0 532 if (!__name)
michael@0 533 locale::_M_throw_on_null_name();
michael@0 534
michael@0 535 int __err_code;
michael@0 536 char buf[_Locale_MAX_SIMPLE_NAME];
michael@0 537 _Locale_time *__time = __acquire_time(__name, buf, 0, &__err_code);
michael@0 538 if (!__time)
michael@0 539 locale::_M_throw_on_creation_failure(__err_code, __name, "time");
michael@0 540
michael@0 541 _Init_timeinfo(this->_M_timeinfo, __time);
michael@0 542 _M_dateorder = __get_date_order(__time);
michael@0 543 __release_time(__time);
michael@0 544 }
michael@0 545
michael@0 546 time_init<wchar_t>::time_init(_Locale_time *__time) {
michael@0 547 _Init_timeinfo(this->_M_timeinfo, __time);
michael@0 548 _M_dateorder = __get_date_order(__time);
michael@0 549 }
michael@0 550 #endif
michael@0 551
michael@0 552 _STLP_MOVE_TO_STD_NAMESPACE
michael@0 553
michael@0 554 #if !defined (_STLP_NO_FORCE_INSTANTIATE)
michael@0 555 template class time_get<char, istreambuf_iterator<char, char_traits<char> > >;
michael@0 556 template class time_put<char, ostreambuf_iterator<char, char_traits<char> > >;
michael@0 557
michael@0 558 # ifndef _STLP_NO_WCHAR_T
michael@0 559 template class time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
michael@0 560 template class time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
michael@0 561 # endif
michael@0 562
michael@0 563 #endif
michael@0 564
michael@0 565 _STLP_END_NAMESPACE

mercurial