build/stlport/src/locale_impl.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 #include "stlport_prefix.h"
michael@0 19
michael@0 20 #include <locale>
michael@0 21 #include <algorithm>
michael@0 22 #include <typeinfo>
michael@0 23
michael@0 24 #include "c_locale.h"
michael@0 25 #include "aligned_buffer.h"
michael@0 26 #include "acquire_release.h"
michael@0 27 #include "locale_impl.h"
michael@0 28
michael@0 29 _STLP_BEGIN_NAMESPACE
michael@0 30
michael@0 31 static const char _Nameless[] = "*";
michael@0 32
michael@0 33 static inline bool is_C_locale_name (const char* name)
michael@0 34 { return ((name[0] == 'C') && (name[1] == 0)); }
michael@0 35
michael@0 36 locale::facet * _STLP_CALL _get_facet(locale::facet *f)
michael@0 37 {
michael@0 38 if (f != 0)
michael@0 39 f->_M_incr();
michael@0 40 return f;
michael@0 41 }
michael@0 42
michael@0 43 void _STLP_CALL _release_facet(locale::facet *&f)
michael@0 44 {
michael@0 45 if ((f != 0) && (f->_M_decr() == 0)) {
michael@0 46 delete f;
michael@0 47 f = 0;
michael@0 48 }
michael@0 49 }
michael@0 50
michael@0 51 size_t locale::id::_S_max = 27;
michael@0 52
michael@0 53 static void _Stl_loc_assign_ids();
michael@0 54
michael@0 55 static _Stl_aligned_buffer<_Locale_impl::Init> __Loc_init_buf;
michael@0 56
michael@0 57 _Locale_impl::Init::Init() {
michael@0 58 if (_M_count()._M_incr() == 1) {
michael@0 59 _Locale_impl::_S_initialize();
michael@0 60 }
michael@0 61 }
michael@0 62
michael@0 63 _Locale_impl::Init::~Init() {
michael@0 64 if (_M_count()._M_decr() == 0) {
michael@0 65 _Locale_impl::_S_uninitialize();
michael@0 66 }
michael@0 67 }
michael@0 68
michael@0 69 _Refcount_Base& _Locale_impl::Init::_M_count() const {
michael@0 70 static _Refcount_Base _S_count(0);
michael@0 71 return _S_count;
michael@0 72 }
michael@0 73
michael@0 74 _Locale_impl::_Locale_impl(const char* s)
michael@0 75 : _Refcount_Base(0), name(s), facets_vec() {
michael@0 76 facets_vec.reserve( locale::id::_S_max );
michael@0 77 new (&__Loc_init_buf) Init();
michael@0 78 }
michael@0 79
michael@0 80 _Locale_impl::_Locale_impl( _Locale_impl const& locimpl )
michael@0 81 : _Refcount_Base(0), name(locimpl.name), facets_vec() {
michael@0 82 for_each( locimpl.facets_vec.begin(), locimpl.facets_vec.end(), _get_facet);
michael@0 83 facets_vec = locimpl.facets_vec;
michael@0 84 new (&__Loc_init_buf) Init();
michael@0 85 }
michael@0 86
michael@0 87 _Locale_impl::_Locale_impl( size_t n, const char* s)
michael@0 88 : _Refcount_Base(0), name(s), facets_vec(n, 0) {
michael@0 89 new (&__Loc_init_buf) Init();
michael@0 90 }
michael@0 91
michael@0 92 _Locale_impl::~_Locale_impl() {
michael@0 93 (&__Loc_init_buf)->~Init();
michael@0 94 for_each( facets_vec.begin(), facets_vec.end(), _release_facet);
michael@0 95 }
michael@0 96
michael@0 97 // Initialization of the locale system. This must be called before
michael@0 98 // any locales are constructed. (Meaning that it must be called when
michael@0 99 // the I/O library itself is initialized.)
michael@0 100 void _STLP_CALL _Locale_impl::_S_initialize() {
michael@0 101 _Stl_loc_assign_ids();
michael@0 102 make_classic_locale();
michael@0 103 }
michael@0 104
michael@0 105 // Release of the classic locale ressources. Has to be called after the last
michael@0 106 // locale destruction and not only after the classic locale destruction as
michael@0 107 // the facets can be shared between different facets.
michael@0 108 void _STLP_CALL _Locale_impl::_S_uninitialize() {
michael@0 109 //Not necessary anymore as classic facets are now 'normal' dynamically allocated
michael@0 110 //facets with a reference counter telling to _release_facet when the facet can be
michael@0 111 //deleted.
michael@0 112 //free_classic_locale();
michael@0 113 }
michael@0 114
michael@0 115 // _Locale_impl non-inline member functions.
michael@0 116 void _STLP_CALL _Locale_impl::_M_throw_bad_cast() {
michael@0 117 _STLP_THROW(bad_cast());
michael@0 118 }
michael@0 119
michael@0 120 void _Locale_impl::insert(_Locale_impl *from, const locale::id& n) {
michael@0 121 if (n._M_index > 0 && n._M_index < from->size()) {
michael@0 122 this->insert(from->facets_vec[n._M_index], n);
michael@0 123 }
michael@0 124 }
michael@0 125
michael@0 126 locale::facet* _Locale_impl::insert(locale::facet *f, const locale::id& n) {
michael@0 127 if (f == 0 || n._M_index == 0)
michael@0 128 return 0;
michael@0 129
michael@0 130 if (n._M_index >= facets_vec.size()) {
michael@0 131 facets_vec.resize(n._M_index + 1);
michael@0 132 }
michael@0 133
michael@0 134 if (f != facets_vec[n._M_index])
michael@0 135 {
michael@0 136 _release_facet(facets_vec[n._M_index]);
michael@0 137 facets_vec[n._M_index] = _get_facet(f);
michael@0 138 }
michael@0 139
michael@0 140 return f;
michael@0 141 }
michael@0 142
michael@0 143 //
michael@0 144 // <locale> content which is dependent on the name
michael@0 145 //
michael@0 146
michael@0 147 /* Six functions, one for each category. Each of them takes a
michael@0 148 * a name, constructs that appropriate category facets by name,
michael@0 149 * and inserts them into the locale. */
michael@0 150 _Locale_name_hint* _Locale_impl::insert_ctype_facets(const char* &name, char *buf, _Locale_name_hint* hint) {
michael@0 151 if (name[0] == 0)
michael@0 152 name = _Locale_ctype_default(buf);
michael@0 153
michael@0 154 if (name == 0 || name[0] == 0 || is_C_locale_name(name)) {
michael@0 155 _Locale_impl* i2 = locale::classic()._M_impl;
michael@0 156 this->insert(i2, ctype<char>::id);
michael@0 157 this->insert(i2, codecvt<char, char, mbstate_t>::id);
michael@0 158 #ifndef _STLP_NO_WCHAR_T
michael@0 159 this->insert(i2, ctype<wchar_t>::id);
michael@0 160 this->insert(i2, codecvt<wchar_t, char, mbstate_t>::id);
michael@0 161 #endif
michael@0 162 } else {
michael@0 163 locale::facet* ct = 0;
michael@0 164 locale::facet* cvt = 0;
michael@0 165 #ifndef _STLP_NO_WCHAR_T
michael@0 166 locale::facet* wct = 0;
michael@0 167 locale::facet* wcvt = 0;
michael@0 168 #endif
michael@0 169 int __err_code;
michael@0 170 _Locale_ctype *__lct = _STLP_PRIV __acquire_ctype(name, buf, hint, &__err_code);
michael@0 171 if (!__lct) {
michael@0 172 locale::_M_throw_on_creation_failure(__err_code, name, "ctype");
michael@0 173 return hint;
michael@0 174 }
michael@0 175
michael@0 176 if (hint == 0) hint = _Locale_get_ctype_hint(__lct);
michael@0 177
michael@0 178 _STLP_TRY {
michael@0 179 ct = new ctype_byname<char>(__lct);
michael@0 180 }
michael@0 181 _STLP_UNWIND(_STLP_PRIV __release_ctype(__lct));
michael@0 182
michael@0 183 _STLP_TRY {
michael@0 184 cvt = new codecvt_byname<char, char, mbstate_t>(name);
michael@0 185 }
michael@0 186 _STLP_UNWIND(delete ct);
michael@0 187
michael@0 188 #ifndef _STLP_NO_WCHAR_T
michael@0 189 _STLP_TRY {
michael@0 190 _Locale_ctype *__lwct = _STLP_PRIV __acquire_ctype(name, buf, hint, &__err_code);
michael@0 191 if (!__lwct) {
michael@0 192 locale::_M_throw_on_creation_failure(__err_code, name, "ctype");
michael@0 193 return hint;
michael@0 194 }
michael@0 195
michael@0 196 _STLP_TRY {
michael@0 197 wct = new ctype_byname<wchar_t>(__lwct);
michael@0 198 }
michael@0 199 _STLP_UNWIND(_STLP_PRIV __release_ctype(__lwct));
michael@0 200
michael@0 201 _Locale_codecvt *__lwcvt = _STLP_PRIV __acquire_codecvt(name, buf, hint, &__err_code);
michael@0 202 if (__lwcvt) {
michael@0 203 _STLP_TRY {
michael@0 204 wcvt = new codecvt_byname<wchar_t, char, mbstate_t>(__lwcvt);
michael@0 205 }
michael@0 206 _STLP_UNWIND(_STLP_PRIV __release_codecvt(__lwcvt); delete wct);
michael@0 207 }
michael@0 208 }
michael@0 209 _STLP_UNWIND(delete cvt; delete ct);
michael@0 210 #endif
michael@0 211
michael@0 212 this->insert(ct, ctype<char>::id);
michael@0 213 this->insert(cvt, codecvt<char, char, mbstate_t>::id);
michael@0 214 #ifndef _STLP_NO_WCHAR_T
michael@0 215 this->insert(wct, ctype<wchar_t>::id);
michael@0 216 if (wcvt) this->insert(wcvt, codecvt<wchar_t, char, mbstate_t>::id);
michael@0 217 #endif
michael@0 218 }
michael@0 219 return hint;
michael@0 220 }
michael@0 221
michael@0 222 _Locale_name_hint* _Locale_impl::insert_numeric_facets(const char* &name, char *buf, _Locale_name_hint* hint) {
michael@0 223 if (name[0] == 0)
michael@0 224 name = _Locale_numeric_default(buf);
michael@0 225
michael@0 226 _Locale_impl* i2 = locale::classic()._M_impl;
michael@0 227
michael@0 228 // We first insert name independant facets taken from the classic locale instance:
michael@0 229 this->insert(i2,
michael@0 230 num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
michael@0 231 this->insert(i2,
michael@0 232 num_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
michael@0 233 #ifndef _STLP_NO_WCHAR_T
michael@0 234 this->insert(i2,
michael@0 235 num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
michael@0 236 this->insert(i2,
michael@0 237 num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
michael@0 238 #endif
michael@0 239
michael@0 240 if (name == 0 || name[0] == 0 || is_C_locale_name(name)) {
michael@0 241 this->insert(i2, numpunct<char>::id);
michael@0 242 #ifndef _STLP_NO_WCHAR_T
michael@0 243 this->insert(i2, numpunct<wchar_t>::id);
michael@0 244 #endif
michael@0 245 }
michael@0 246 else {
michael@0 247 locale::facet* punct = 0;
michael@0 248 #ifndef _STLP_NO_WCHAR_T
michael@0 249 locale::facet* wpunct = 0;
michael@0 250 #endif
michael@0 251
michael@0 252 int __err_code;
michael@0 253 _Locale_numeric *__lpunct = _STLP_PRIV __acquire_numeric(name, buf, hint, &__err_code);
michael@0 254 if (!__lpunct) {
michael@0 255 locale::_M_throw_on_creation_failure(__err_code, name, "numpunct");
michael@0 256 return hint;
michael@0 257 }
michael@0 258
michael@0 259 if (hint == 0) hint = _Locale_get_numeric_hint(__lpunct);
michael@0 260 _STLP_TRY {
michael@0 261 punct = new numpunct_byname<char>(__lpunct);
michael@0 262 }
michael@0 263 _STLP_UNWIND(_STLP_PRIV __release_numeric(__lpunct));
michael@0 264
michael@0 265 #ifndef _STLP_NO_WCHAR_T
michael@0 266 _Locale_numeric *__lwpunct = _STLP_PRIV __acquire_numeric(name, buf, hint, &__err_code);
michael@0 267 if (!__lwpunct) {
michael@0 268 delete punct;
michael@0 269 locale::_M_throw_on_creation_failure(__err_code, name, "numpunct");
michael@0 270 return hint;
michael@0 271 }
michael@0 272 if (__lwpunct) {
michael@0 273 _STLP_TRY {
michael@0 274 wpunct = new numpunct_byname<wchar_t>(__lwpunct);
michael@0 275 }
michael@0 276 _STLP_UNWIND(_STLP_PRIV __release_numeric(__lwpunct); delete punct);
michael@0 277 }
michael@0 278 #endif
michael@0 279
michael@0 280 this->insert(punct, numpunct<char>::id);
michael@0 281 #ifndef _STLP_NO_WCHAR_T
michael@0 282 this->insert(wpunct, numpunct<wchar_t>::id);
michael@0 283 #endif
michael@0 284 }
michael@0 285 return hint;
michael@0 286 }
michael@0 287
michael@0 288 _Locale_name_hint* _Locale_impl::insert_time_facets(const char* &name, char *buf, _Locale_name_hint* hint) {
michael@0 289 if (name[0] == 0)
michael@0 290 name = _Locale_time_default(buf);
michael@0 291
michael@0 292 if (name == 0 || name[0] == 0 || is_C_locale_name(name)) {
michael@0 293 _Locale_impl* i2 = locale::classic()._M_impl;
michael@0 294 this->insert(i2,
michael@0 295 time_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
michael@0 296 this->insert(i2,
michael@0 297 time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
michael@0 298 #ifndef _STLP_NO_WCHAR_T
michael@0 299 this->insert(i2,
michael@0 300 time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
michael@0 301 this->insert(i2,
michael@0 302 time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
michael@0 303 #endif
michael@0 304 } else {
michael@0 305 locale::facet *get = 0;
michael@0 306 locale::facet *put = 0;
michael@0 307 #ifndef _STLP_NO_WCHAR_T
michael@0 308 locale::facet *wget = 0;
michael@0 309 locale::facet *wput = 0;
michael@0 310 #endif
michael@0 311
michael@0 312 int __err_code;
michael@0 313 _Locale_time *__time = _STLP_PRIV __acquire_time(name, buf, hint, &__err_code);
michael@0 314 if (!__time) {
michael@0 315 // time facets category is not mandatory for correct stream behavior so if platform
michael@0 316 // do not support it we do not generate a runtime_error exception.
michael@0 317 if (__err_code == _STLP_LOC_NO_MEMORY) {
michael@0 318 _STLP_THROW_BAD_ALLOC;
michael@0 319 }
michael@0 320 return hint;
michael@0 321 }
michael@0 322
michael@0 323 if (!hint) hint = _Locale_get_time_hint(__time);
michael@0 324 _STLP_TRY {
michael@0 325 get = new time_get_byname<char, istreambuf_iterator<char, char_traits<char> > >(__time);
michael@0 326 put = new time_put_byname<char, ostreambuf_iterator<char, char_traits<char> > >(__time);
michael@0 327 #ifndef _STLP_NO_WCHAR_T
michael@0 328 wget = new time_get_byname<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(__time);
michael@0 329 wput = new time_put_byname<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(__time);
michael@0 330 #endif
michael@0 331 }
michael@0 332 #ifndef _STLP_NO_WCHAR_T
michael@0 333 _STLP_UNWIND(delete wget; delete put; delete get; _STLP_PRIV __release_time(__time));
michael@0 334 #else
michael@0 335 _STLP_UNWIND(delete get; _STLP_PRIV __release_time(__time));
michael@0 336 #endif
michael@0 337
michael@0 338 _STLP_PRIV __release_time(__time);
michael@0 339
michael@0 340 this->insert(get, time_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
michael@0 341 this->insert(put, time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
michael@0 342 #ifndef _STLP_NO_WCHAR_T
michael@0 343 this->insert(wget, time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
michael@0 344 this->insert(wput, time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
michael@0 345 #endif
michael@0 346 }
michael@0 347 return hint;
michael@0 348 }
michael@0 349
michael@0 350 _Locale_name_hint* _Locale_impl::insert_collate_facets(const char* &name, char *buf, _Locale_name_hint* hint) {
michael@0 351 if (name[0] == 0)
michael@0 352 name = _Locale_collate_default(buf);
michael@0 353
michael@0 354 if (name == 0 || name[0] == 0 || is_C_locale_name(name)) {
michael@0 355 _Locale_impl* i2 = locale::classic()._M_impl;
michael@0 356 this->insert(i2, collate<char>::id);
michael@0 357 #ifndef _STLP_NO_WCHAR_T
michael@0 358 this->insert(i2, collate<wchar_t>::id);
michael@0 359 #endif
michael@0 360 }
michael@0 361 else {
michael@0 362 locale::facet *col = 0;
michael@0 363 #ifndef _STLP_NO_WCHAR_T
michael@0 364 locale::facet *wcol = 0;
michael@0 365 #endif
michael@0 366
michael@0 367 int __err_code;
michael@0 368 _Locale_collate *__coll = _STLP_PRIV __acquire_collate(name, buf, hint, &__err_code);
michael@0 369 if (!__coll) {
michael@0 370 if (__err_code == _STLP_LOC_NO_MEMORY) {
michael@0 371 _STLP_THROW_BAD_ALLOC;
michael@0 372 }
michael@0 373 return hint;
michael@0 374 }
michael@0 375
michael@0 376 if (hint == 0) hint = _Locale_get_collate_hint(__coll);
michael@0 377 _STLP_TRY {
michael@0 378 col = new collate_byname<char>(__coll);
michael@0 379 }
michael@0 380 _STLP_UNWIND(_STLP_PRIV __release_collate(__coll));
michael@0 381
michael@0 382 #ifndef _STLP_NO_WCHAR_T
michael@0 383 _Locale_collate *__wcoll = _STLP_PRIV __acquire_collate(name, buf, hint, &__err_code);
michael@0 384 if (!__wcoll) {
michael@0 385 if (__err_code == _STLP_LOC_NO_MEMORY) {
michael@0 386 delete col;
michael@0 387 _STLP_THROW_BAD_ALLOC;
michael@0 388 }
michael@0 389 }
michael@0 390 if (__wcoll) {
michael@0 391 _STLP_TRY {
michael@0 392 wcol = new collate_byname<wchar_t>(__wcoll);
michael@0 393 }
michael@0 394 _STLP_UNWIND(_STLP_PRIV __release_collate(__wcoll); delete col);
michael@0 395 }
michael@0 396 #endif
michael@0 397
michael@0 398 this->insert(col, collate<char>::id);
michael@0 399 #ifndef _STLP_NO_WCHAR_T
michael@0 400 if (wcol) this->insert(wcol, collate<wchar_t>::id);
michael@0 401 #endif
michael@0 402 }
michael@0 403 return hint;
michael@0 404 }
michael@0 405
michael@0 406 _Locale_name_hint* _Locale_impl::insert_monetary_facets(const char* &name, char *buf, _Locale_name_hint* hint) {
michael@0 407 if (name[0] == 0)
michael@0 408 name = _Locale_monetary_default(buf);
michael@0 409
michael@0 410 _Locale_impl* i2 = locale::classic()._M_impl;
michael@0 411
michael@0 412 // We first insert name independant facets taken from the classic locale instance:
michael@0 413 this->insert(i2, money_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
michael@0 414 this->insert(i2, money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
michael@0 415 #ifndef _STLP_NO_WCHAR_T
michael@0 416 this->insert(i2, money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
michael@0 417 this->insert(i2, money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
michael@0 418 #endif
michael@0 419
michael@0 420 if (name == 0 || name[0] == 0 || is_C_locale_name(name)) {
michael@0 421 this->insert(i2, moneypunct<char, false>::id);
michael@0 422 this->insert(i2, moneypunct<char, true>::id);
michael@0 423 #ifndef _STLP_NO_WCHAR_T
michael@0 424 this->insert(i2, moneypunct<wchar_t, false>::id);
michael@0 425 this->insert(i2, moneypunct<wchar_t, true>::id);
michael@0 426 #endif
michael@0 427 }
michael@0 428 else {
michael@0 429 locale::facet *punct = 0;
michael@0 430 locale::facet *ipunct = 0;
michael@0 431
michael@0 432 #ifndef _STLP_NO_WCHAR_T
michael@0 433 locale::facet* wpunct = 0;
michael@0 434 locale::facet* wipunct = 0;
michael@0 435 #endif
michael@0 436
michael@0 437 int __err_code;
michael@0 438 _Locale_monetary *__mon = _STLP_PRIV __acquire_monetary(name, buf, hint, &__err_code);
michael@0 439 if (!__mon) {
michael@0 440 if (__err_code == _STLP_LOC_NO_MEMORY) {
michael@0 441 _STLP_THROW_BAD_ALLOC;
michael@0 442 }
michael@0 443 return hint;
michael@0 444 }
michael@0 445
michael@0 446 if (hint == 0) hint = _Locale_get_monetary_hint(__mon);
michael@0 447
michael@0 448 _STLP_TRY {
michael@0 449 punct = new moneypunct_byname<char, false>(__mon);
michael@0 450 }
michael@0 451 _STLP_UNWIND(_STLP_PRIV __release_monetary(__mon));
michael@0 452
michael@0 453 _Locale_monetary *__imon = _STLP_PRIV __acquire_monetary(name, buf, hint, &__err_code);
michael@0 454 if (!__imon) {
michael@0 455 delete punct;
michael@0 456 if (__err_code == _STLP_LOC_NO_MEMORY) {
michael@0 457 _STLP_THROW_BAD_ALLOC;
michael@0 458 }
michael@0 459 return hint;
michael@0 460 }
michael@0 461
michael@0 462 _STLP_TRY {
michael@0 463 ipunct = new moneypunct_byname<char, true>(__imon);
michael@0 464 }
michael@0 465 _STLP_UNWIND(_STLP_PRIV __release_monetary(__imon); delete punct);
michael@0 466
michael@0 467 #ifndef _STLP_NO_WCHAR_T
michael@0 468 _STLP_TRY {
michael@0 469 _Locale_monetary *__wmon = _STLP_PRIV __acquire_monetary(name, buf, hint, &__err_code);
michael@0 470 if (!__wmon) {
michael@0 471 if (__err_code == _STLP_LOC_NO_MEMORY) {
michael@0 472 _STLP_THROW_BAD_ALLOC;
michael@0 473 }
michael@0 474 }
michael@0 475
michael@0 476 if (__wmon) {
michael@0 477 _STLP_TRY {
michael@0 478 wpunct = new moneypunct_byname<wchar_t, false>(__wmon);
michael@0 479 }
michael@0 480 _STLP_UNWIND(_STLP_PRIV __release_monetary(__wmon));
michael@0 481
michael@0 482 _Locale_monetary *__wimon = _STLP_PRIV __acquire_monetary(name, buf, hint, &__err_code);
michael@0 483 if (!__wimon) {
michael@0 484 delete wpunct;
michael@0 485 if (__err_code == _STLP_LOC_NO_MEMORY) {
michael@0 486 _STLP_THROW_BAD_ALLOC;
michael@0 487 }
michael@0 488 wpunct = 0;
michael@0 489 }
michael@0 490 else {
michael@0 491 _STLP_TRY {
michael@0 492 wipunct = new moneypunct_byname<wchar_t, true>(__wimon);
michael@0 493 }
michael@0 494 _STLP_UNWIND(_STLP_PRIV __release_monetary(__wimon); delete wpunct);
michael@0 495 }
michael@0 496 }
michael@0 497 }
michael@0 498 _STLP_UNWIND(delete ipunct; delete punct);
michael@0 499 #endif
michael@0 500
michael@0 501 this->insert(punct, moneypunct<char, false>::id);
michael@0 502 this->insert(ipunct, moneypunct<char, true>::id);
michael@0 503 #ifndef _STLP_NO_WCHAR_T
michael@0 504 if (wpunct) this->insert(wpunct, moneypunct<wchar_t, false>::id);
michael@0 505 if (wipunct) this->insert(wipunct, moneypunct<wchar_t, true>::id);
michael@0 506 #endif
michael@0 507 }
michael@0 508 return hint;
michael@0 509 }
michael@0 510
michael@0 511 _Locale_name_hint* _Locale_impl::insert_messages_facets(const char* &name, char *buf, _Locale_name_hint* hint) {
michael@0 512 if (name[0] == 0)
michael@0 513 name = _Locale_messages_default(buf);
michael@0 514
michael@0 515 if (name == 0 || name[0] == 0 || is_C_locale_name(name)) {
michael@0 516 _Locale_impl* i2 = locale::classic()._M_impl;
michael@0 517 this->insert(i2, messages<char>::id);
michael@0 518 #ifndef _STLP_NO_WCHAR_T
michael@0 519 this->insert(i2, messages<wchar_t>::id);
michael@0 520 #endif
michael@0 521 }
michael@0 522 else {
michael@0 523 locale::facet *msg = 0;
michael@0 524 #ifndef _STLP_NO_WCHAR_T
michael@0 525 locale::facet *wmsg = 0;
michael@0 526 #endif
michael@0 527
michael@0 528 int __err_code;
michael@0 529 _Locale_messages *__msg = _STLP_PRIV __acquire_messages(name, buf, hint, &__err_code);
michael@0 530 if (!__msg) {
michael@0 531 if (__err_code == _STLP_LOC_NO_MEMORY) {
michael@0 532 _STLP_THROW_BAD_ALLOC;
michael@0 533 }
michael@0 534 return hint;
michael@0 535 }
michael@0 536
michael@0 537 _STLP_TRY {
michael@0 538 msg = new messages_byname<char>(__msg);
michael@0 539 }
michael@0 540 _STLP_UNWIND(_STLP_PRIV __release_messages(__msg));
michael@0 541
michael@0 542 #ifndef _STLP_NO_WCHAR_T
michael@0 543 _STLP_TRY {
michael@0 544 _Locale_messages *__wmsg = _STLP_PRIV __acquire_messages(name, buf, hint, &__err_code);
michael@0 545 if (!__wmsg) {
michael@0 546 if (__err_code == _STLP_LOC_NO_MEMORY) {
michael@0 547 _STLP_THROW_BAD_ALLOC;
michael@0 548 }
michael@0 549 }
michael@0 550
michael@0 551 if (__wmsg) {
michael@0 552 _STLP_TRY {
michael@0 553 wmsg = new messages_byname<wchar_t>(__wmsg);
michael@0 554 }
michael@0 555 _STLP_UNWIND(_STLP_PRIV __release_messages(__wmsg));
michael@0 556 }
michael@0 557 }
michael@0 558 _STLP_UNWIND(delete msg);
michael@0 559 #endif
michael@0 560
michael@0 561 this->insert(msg, messages<char>::id);
michael@0 562 #ifndef _STLP_NO_WCHAR_T
michael@0 563 if (wmsg) this->insert(wmsg, messages<wchar_t>::id);
michael@0 564 #endif
michael@0 565 }
michael@0 566 return hint;
michael@0 567 }
michael@0 568
michael@0 569 static void _Stl_loc_assign_ids() {
michael@0 570 // This assigns ids to every facet that is a member of a category,
michael@0 571 // and also to money_get/put, num_get/put, and time_get/put
michael@0 572 // instantiated using ordinary pointers as the input/output
michael@0 573 // iterators. (The default is [io]streambuf_iterator.)
michael@0 574
michael@0 575 money_get<char, istreambuf_iterator<char, char_traits<char> > >::id._M_index = 8;
michael@0 576 money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id._M_index = 9;
michael@0 577 num_get<char, istreambuf_iterator<char, char_traits<char> > >::id._M_index = 10;
michael@0 578 num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id._M_index = 11;
michael@0 579 time_get<char, istreambuf_iterator<char, char_traits<char> > >::id._M_index = 12;
michael@0 580 time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id._M_index = 13;
michael@0 581
michael@0 582 #ifndef _STLP_NO_WCHAR_T
michael@0 583 money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 21;
michael@0 584 money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 22;
michael@0 585 num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 23;
michael@0 586 num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > ::id._M_index = 24;
michael@0 587 time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 25;
michael@0 588 time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 26;
michael@0 589 #endif
michael@0 590 // locale::id::_S_max = 27;
michael@0 591 }
michael@0 592
michael@0 593 // To access those static instance use the getter below, they guaranty
michael@0 594 // a correct initialization.
michael@0 595 static locale *_Stl_classic_locale = 0;
michael@0 596 static locale *_Stl_global_locale = 0;
michael@0 597
michael@0 598 locale* _Stl_get_classic_locale() {
michael@0 599 static _Locale_impl::Init init;
michael@0 600 return _Stl_classic_locale;
michael@0 601 }
michael@0 602
michael@0 603 locale* _Stl_get_global_locale() {
michael@0 604 static _Locale_impl::Init init;
michael@0 605 return _Stl_global_locale;
michael@0 606 }
michael@0 607
michael@0 608 #if defined (_STLP_MSVC) || defined (__ICL) || defined (__ISCPP__) || defined (__DMC__)
michael@0 609 /*
michael@0 610 * The following static variable needs to be initialized before STLport
michael@0 611 * users static variable in order for him to be able to use Standard
michael@0 612 * streams in its variable initialization.
michael@0 613 * This variable is here because MSVC do not allow to change the initialization
michael@0 614 * segment in a given translation unit, iostream.cpp already contains an
michael@0 615 * initialization segment specification.
michael@0 616 */
michael@0 617 # pragma warning (disable : 4073)
michael@0 618 # pragma init_seg(lib)
michael@0 619 #endif
michael@0 620
michael@0 621 static ios_base::Init _IosInit;
michael@0 622
michael@0 623 void _Locale_impl::make_classic_locale() {
michael@0 624 // This funcion will be called once: during build classic _Locale_impl
michael@0 625
michael@0 626 // The classic locale contains every facet that belongs to a category.
michael@0 627 static _Stl_aligned_buffer<_Locale_impl> _Locale_classic_impl_buf;
michael@0 628 _Locale_impl *classic = new(&_Locale_classic_impl_buf) _Locale_impl("C");
michael@0 629
michael@0 630 locale::facet* classic_facets[] = {
michael@0 631 0,
michael@0 632 new collate<char>(1),
michael@0 633 new ctype<char>(0, false, 1),
michael@0 634 new codecvt<char, char, mbstate_t>(1),
michael@0 635 new moneypunct<char, true>(1),
michael@0 636 new moneypunct<char, false>(1),
michael@0 637 new numpunct<char>(1),
michael@0 638 new messages<char>(1),
michael@0 639 new money_get<char, istreambuf_iterator<char, char_traits<char> > >(1),
michael@0 640 new money_put<char, ostreambuf_iterator<char, char_traits<char> > >(1),
michael@0 641 new num_get<char, istreambuf_iterator<char, char_traits<char> > >(1),
michael@0 642 new num_put<char, ostreambuf_iterator<char, char_traits<char> > >(1),
michael@0 643 new time_get<char, istreambuf_iterator<char, char_traits<char> > >(1),
michael@0 644 new time_put<char, ostreambuf_iterator<char, char_traits<char> > >(1),
michael@0 645 #ifndef _STLP_NO_WCHAR_T
michael@0 646 new collate<wchar_t>(1),
michael@0 647 new ctype<wchar_t>(1),
michael@0 648 new codecvt<wchar_t, char, mbstate_t>(1),
michael@0 649 new moneypunct<wchar_t, true>(1),
michael@0 650 new moneypunct<wchar_t, false>(1),
michael@0 651 new numpunct<wchar_t>(1),
michael@0 652 new messages<wchar_t>(1),
michael@0 653 new money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
michael@0 654 new money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
michael@0 655 new num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
michael@0 656 new num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
michael@0 657 new time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
michael@0 658 new time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
michael@0 659 #endif
michael@0 660 0
michael@0 661 };
michael@0 662
michael@0 663 const size_t nb_classic_facets = sizeof(classic_facets) / sizeof(locale::facet *);
michael@0 664 classic->facets_vec.reserve(nb_classic_facets);
michael@0 665 classic->facets_vec.assign(&classic_facets[0], &classic_facets[0] + nb_classic_facets);
michael@0 666
michael@0 667 static locale _Locale_classic(classic);
michael@0 668 _Stl_classic_locale = &_Locale_classic;
michael@0 669
michael@0 670 static locale _Locale_global(classic);
michael@0 671 _Stl_global_locale = &_Locale_global;
michael@0 672 }
michael@0 673
michael@0 674 // Declarations of (non-template) facets' static data members
michael@0 675 // size_t locale::id::_S_max = 27; // made before
michael@0 676
michael@0 677 locale::id collate<char>::id = { 1 };
michael@0 678 locale::id ctype<char>::id = { 2 };
michael@0 679 locale::id codecvt<char, char, mbstate_t>::id = { 3 };
michael@0 680 locale::id moneypunct<char, true>::id = { 4 };
michael@0 681 locale::id moneypunct<char, false>::id = { 5 };
michael@0 682 locale::id numpunct<char>::id = { 6 } ;
michael@0 683 locale::id messages<char>::id = { 7 };
michael@0 684
michael@0 685 #ifndef _STLP_NO_WCHAR_T
michael@0 686 locale::id collate<wchar_t>::id = { 14 };
michael@0 687 locale::id ctype<wchar_t>::id = { 15 };
michael@0 688 locale::id codecvt<wchar_t, char, mbstate_t>::id = { 16 };
michael@0 689 locale::id moneypunct<wchar_t, true>::id = { 17 } ;
michael@0 690 locale::id moneypunct<wchar_t, false>::id = { 18 } ;
michael@0 691 locale::id numpunct<wchar_t>::id = { 19 };
michael@0 692 locale::id messages<wchar_t>::id = { 20 };
michael@0 693 #endif
michael@0 694
michael@0 695 _STLP_DECLSPEC _Locale_impl* _STLP_CALL _get_Locale_impl(_Locale_impl *loc)
michael@0 696 {
michael@0 697 _STLP_ASSERT( loc != 0 );
michael@0 698 loc->_M_incr();
michael@0 699 return loc;
michael@0 700 }
michael@0 701
michael@0 702 void _STLP_CALL _release_Locale_impl(_Locale_impl *& loc)
michael@0 703 {
michael@0 704 _STLP_ASSERT( loc != 0 );
michael@0 705 if (loc->_M_decr() == 0) {
michael@0 706 if (*loc != *_Stl_classic_locale)
michael@0 707 delete loc;
michael@0 708 else
michael@0 709 loc->~_Locale_impl();
michael@0 710 loc = 0;
michael@0 711 }
michael@0 712 }
michael@0 713
michael@0 714 _STLP_DECLSPEC _Locale_impl* _STLP_CALL _copy_Nameless_Locale_impl(_Locale_impl *loc)
michael@0 715 {
michael@0 716 _STLP_ASSERT( loc != 0 );
michael@0 717 _Locale_impl *loc_new = new _Locale_impl(*loc);
michael@0 718 loc_new->name = _Nameless;
michael@0 719 return loc_new;
michael@0 720 }
michael@0 721
michael@0 722 /* _GetFacetId implementation have to be here in order to be in the same translation unit
michael@0 723 * as where id are initialize (in _Stl_loc_assign_ids) */
michael@0 724 _STLP_MOVE_TO_PRIV_NAMESPACE
michael@0 725
michael@0 726 _STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const money_get<char, istreambuf_iterator<char, char_traits<char> > >*)
michael@0 727 { return money_get<char, istreambuf_iterator<char, char_traits<char> > >::id; }
michael@0 728 _STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const money_put<char, ostreambuf_iterator<char, char_traits<char> > >*)
michael@0 729 { return money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id; }
michael@0 730 #ifndef _STLP_NO_WCHAR_T
michael@0 731 _STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >*)
michael@0 732 { return money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id; }
michael@0 733 _STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >*)
michael@0 734 { return money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id; }
michael@0 735 #endif
michael@0 736
michael@0 737 _STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const num_get<char, istreambuf_iterator<char, char_traits<char> > >*)
michael@0 738 { return num_get<char, istreambuf_iterator<char, char_traits<char> > >::id; }
michael@0 739 #ifndef _STLP_NO_WCHAR_T
michael@0 740 _STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >*)
michael@0 741 { return num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id; }
michael@0 742 #endif
michael@0 743
michael@0 744 _STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const num_put<char, ostreambuf_iterator<char, char_traits<char> > >*)
michael@0 745 { return num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id; }
michael@0 746 #ifndef _STLP_NO_WCHAR_T
michael@0 747 _STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >*)
michael@0 748 { return num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id; }
michael@0 749 #endif
michael@0 750
michael@0 751 _STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const time_get<char, istreambuf_iterator<char, char_traits<char> > >*)
michael@0 752 { return time_get<char, istreambuf_iterator<char, char_traits<char> > >::id; }
michael@0 753 _STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const time_put<char, ostreambuf_iterator<char, char_traits<char> > >*)
michael@0 754 { return time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id; }
michael@0 755 #ifndef _STLP_NO_WCHAR_T
michael@0 756 _STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >*)
michael@0 757 { return time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id; }
michael@0 758 _STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >*)
michael@0 759 { return time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id; }
michael@0 760 #endif
michael@0 761
michael@0 762 _STLP_MOVE_TO_STD_NAMESPACE
michael@0 763
michael@0 764 _STLP_END_NAMESPACE
michael@0 765

mercurial