1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/build/stlport/src/locale_impl.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,765 @@ 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 +#include "stlport_prefix.h" 1.22 + 1.23 +#include <locale> 1.24 +#include <algorithm> 1.25 +#include <typeinfo> 1.26 + 1.27 +#include "c_locale.h" 1.28 +#include "aligned_buffer.h" 1.29 +#include "acquire_release.h" 1.30 +#include "locale_impl.h" 1.31 + 1.32 +_STLP_BEGIN_NAMESPACE 1.33 + 1.34 +static const char _Nameless[] = "*"; 1.35 + 1.36 +static inline bool is_C_locale_name (const char* name) 1.37 +{ return ((name[0] == 'C') && (name[1] == 0)); } 1.38 + 1.39 +locale::facet * _STLP_CALL _get_facet(locale::facet *f) 1.40 +{ 1.41 + if (f != 0) 1.42 + f->_M_incr(); 1.43 + return f; 1.44 +} 1.45 + 1.46 +void _STLP_CALL _release_facet(locale::facet *&f) 1.47 +{ 1.48 + if ((f != 0) && (f->_M_decr() == 0)) { 1.49 + delete f; 1.50 + f = 0; 1.51 + } 1.52 +} 1.53 + 1.54 +size_t locale::id::_S_max = 27; 1.55 + 1.56 +static void _Stl_loc_assign_ids(); 1.57 + 1.58 +static _Stl_aligned_buffer<_Locale_impl::Init> __Loc_init_buf; 1.59 + 1.60 +_Locale_impl::Init::Init() { 1.61 + if (_M_count()._M_incr() == 1) { 1.62 + _Locale_impl::_S_initialize(); 1.63 + } 1.64 +} 1.65 + 1.66 +_Locale_impl::Init::~Init() { 1.67 + if (_M_count()._M_decr() == 0) { 1.68 + _Locale_impl::_S_uninitialize(); 1.69 + } 1.70 +} 1.71 + 1.72 +_Refcount_Base& _Locale_impl::Init::_M_count() const { 1.73 + static _Refcount_Base _S_count(0); 1.74 + return _S_count; 1.75 +} 1.76 + 1.77 +_Locale_impl::_Locale_impl(const char* s) 1.78 + : _Refcount_Base(0), name(s), facets_vec() { 1.79 + facets_vec.reserve( locale::id::_S_max ); 1.80 + new (&__Loc_init_buf) Init(); 1.81 +} 1.82 + 1.83 +_Locale_impl::_Locale_impl( _Locale_impl const& locimpl ) 1.84 + : _Refcount_Base(0), name(locimpl.name), facets_vec() { 1.85 + for_each( locimpl.facets_vec.begin(), locimpl.facets_vec.end(), _get_facet); 1.86 + facets_vec = locimpl.facets_vec; 1.87 + new (&__Loc_init_buf) Init(); 1.88 +} 1.89 + 1.90 +_Locale_impl::_Locale_impl( size_t n, const char* s) 1.91 + : _Refcount_Base(0), name(s), facets_vec(n, 0) { 1.92 + new (&__Loc_init_buf) Init(); 1.93 +} 1.94 + 1.95 +_Locale_impl::~_Locale_impl() { 1.96 + (&__Loc_init_buf)->~Init(); 1.97 + for_each( facets_vec.begin(), facets_vec.end(), _release_facet); 1.98 +} 1.99 + 1.100 +// Initialization of the locale system. This must be called before 1.101 +// any locales are constructed. (Meaning that it must be called when 1.102 +// the I/O library itself is initialized.) 1.103 +void _STLP_CALL _Locale_impl::_S_initialize() { 1.104 + _Stl_loc_assign_ids(); 1.105 + make_classic_locale(); 1.106 +} 1.107 + 1.108 +// Release of the classic locale ressources. Has to be called after the last 1.109 +// locale destruction and not only after the classic locale destruction as 1.110 +// the facets can be shared between different facets. 1.111 +void _STLP_CALL _Locale_impl::_S_uninitialize() { 1.112 + //Not necessary anymore as classic facets are now 'normal' dynamically allocated 1.113 + //facets with a reference counter telling to _release_facet when the facet can be 1.114 + //deleted. 1.115 + //free_classic_locale(); 1.116 +} 1.117 + 1.118 +// _Locale_impl non-inline member functions. 1.119 +void _STLP_CALL _Locale_impl::_M_throw_bad_cast() { 1.120 + _STLP_THROW(bad_cast()); 1.121 +} 1.122 + 1.123 +void _Locale_impl::insert(_Locale_impl *from, const locale::id& n) { 1.124 + if (n._M_index > 0 && n._M_index < from->size()) { 1.125 + this->insert(from->facets_vec[n._M_index], n); 1.126 + } 1.127 +} 1.128 + 1.129 +locale::facet* _Locale_impl::insert(locale::facet *f, const locale::id& n) { 1.130 + if (f == 0 || n._M_index == 0) 1.131 + return 0; 1.132 + 1.133 + if (n._M_index >= facets_vec.size()) { 1.134 + facets_vec.resize(n._M_index + 1); 1.135 + } 1.136 + 1.137 + if (f != facets_vec[n._M_index]) 1.138 + { 1.139 + _release_facet(facets_vec[n._M_index]); 1.140 + facets_vec[n._M_index] = _get_facet(f); 1.141 + } 1.142 + 1.143 + return f; 1.144 +} 1.145 + 1.146 +// 1.147 +// <locale> content which is dependent on the name 1.148 +// 1.149 + 1.150 +/* Six functions, one for each category. Each of them takes a 1.151 + * a name, constructs that appropriate category facets by name, 1.152 + * and inserts them into the locale. */ 1.153 +_Locale_name_hint* _Locale_impl::insert_ctype_facets(const char* &name, char *buf, _Locale_name_hint* hint) { 1.154 + if (name[0] == 0) 1.155 + name = _Locale_ctype_default(buf); 1.156 + 1.157 + if (name == 0 || name[0] == 0 || is_C_locale_name(name)) { 1.158 + _Locale_impl* i2 = locale::classic()._M_impl; 1.159 + this->insert(i2, ctype<char>::id); 1.160 + this->insert(i2, codecvt<char, char, mbstate_t>::id); 1.161 +#ifndef _STLP_NO_WCHAR_T 1.162 + this->insert(i2, ctype<wchar_t>::id); 1.163 + this->insert(i2, codecvt<wchar_t, char, mbstate_t>::id); 1.164 +#endif 1.165 + } else { 1.166 + locale::facet* ct = 0; 1.167 + locale::facet* cvt = 0; 1.168 +#ifndef _STLP_NO_WCHAR_T 1.169 + locale::facet* wct = 0; 1.170 + locale::facet* wcvt = 0; 1.171 +#endif 1.172 + int __err_code; 1.173 + _Locale_ctype *__lct = _STLP_PRIV __acquire_ctype(name, buf, hint, &__err_code); 1.174 + if (!__lct) { 1.175 + locale::_M_throw_on_creation_failure(__err_code, name, "ctype"); 1.176 + return hint; 1.177 + } 1.178 + 1.179 + if (hint == 0) hint = _Locale_get_ctype_hint(__lct); 1.180 + 1.181 + _STLP_TRY { 1.182 + ct = new ctype_byname<char>(__lct); 1.183 + } 1.184 + _STLP_UNWIND(_STLP_PRIV __release_ctype(__lct)); 1.185 + 1.186 + _STLP_TRY { 1.187 + cvt = new codecvt_byname<char, char, mbstate_t>(name); 1.188 + } 1.189 + _STLP_UNWIND(delete ct); 1.190 + 1.191 +#ifndef _STLP_NO_WCHAR_T 1.192 + _STLP_TRY { 1.193 + _Locale_ctype *__lwct = _STLP_PRIV __acquire_ctype(name, buf, hint, &__err_code); 1.194 + if (!__lwct) { 1.195 + locale::_M_throw_on_creation_failure(__err_code, name, "ctype"); 1.196 + return hint; 1.197 + } 1.198 + 1.199 + _STLP_TRY { 1.200 + wct = new ctype_byname<wchar_t>(__lwct); 1.201 + } 1.202 + _STLP_UNWIND(_STLP_PRIV __release_ctype(__lwct)); 1.203 + 1.204 + _Locale_codecvt *__lwcvt = _STLP_PRIV __acquire_codecvt(name, buf, hint, &__err_code); 1.205 + if (__lwcvt) { 1.206 + _STLP_TRY { 1.207 + wcvt = new codecvt_byname<wchar_t, char, mbstate_t>(__lwcvt); 1.208 + } 1.209 + _STLP_UNWIND(_STLP_PRIV __release_codecvt(__lwcvt); delete wct); 1.210 + } 1.211 + } 1.212 + _STLP_UNWIND(delete cvt; delete ct); 1.213 +#endif 1.214 + 1.215 + this->insert(ct, ctype<char>::id); 1.216 + this->insert(cvt, codecvt<char, char, mbstate_t>::id); 1.217 +#ifndef _STLP_NO_WCHAR_T 1.218 + this->insert(wct, ctype<wchar_t>::id); 1.219 + if (wcvt) this->insert(wcvt, codecvt<wchar_t, char, mbstate_t>::id); 1.220 +#endif 1.221 + } 1.222 + return hint; 1.223 +} 1.224 + 1.225 +_Locale_name_hint* _Locale_impl::insert_numeric_facets(const char* &name, char *buf, _Locale_name_hint* hint) { 1.226 + if (name[0] == 0) 1.227 + name = _Locale_numeric_default(buf); 1.228 + 1.229 + _Locale_impl* i2 = locale::classic()._M_impl; 1.230 + 1.231 + // We first insert name independant facets taken from the classic locale instance: 1.232 + this->insert(i2, 1.233 + num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id); 1.234 + this->insert(i2, 1.235 + num_get<char, istreambuf_iterator<char, char_traits<char> > >::id); 1.236 +#ifndef _STLP_NO_WCHAR_T 1.237 + this->insert(i2, 1.238 + num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id); 1.239 + this->insert(i2, 1.240 + num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id); 1.241 +#endif 1.242 + 1.243 + if (name == 0 || name[0] == 0 || is_C_locale_name(name)) { 1.244 + this->insert(i2, numpunct<char>::id); 1.245 +#ifndef _STLP_NO_WCHAR_T 1.246 + this->insert(i2, numpunct<wchar_t>::id); 1.247 +#endif 1.248 + } 1.249 + else { 1.250 + locale::facet* punct = 0; 1.251 +#ifndef _STLP_NO_WCHAR_T 1.252 + locale::facet* wpunct = 0; 1.253 +#endif 1.254 + 1.255 + int __err_code; 1.256 + _Locale_numeric *__lpunct = _STLP_PRIV __acquire_numeric(name, buf, hint, &__err_code); 1.257 + if (!__lpunct) { 1.258 + locale::_M_throw_on_creation_failure(__err_code, name, "numpunct"); 1.259 + return hint; 1.260 + } 1.261 + 1.262 + if (hint == 0) hint = _Locale_get_numeric_hint(__lpunct); 1.263 + _STLP_TRY { 1.264 + punct = new numpunct_byname<char>(__lpunct); 1.265 + } 1.266 + _STLP_UNWIND(_STLP_PRIV __release_numeric(__lpunct)); 1.267 + 1.268 +#ifndef _STLP_NO_WCHAR_T 1.269 + _Locale_numeric *__lwpunct = _STLP_PRIV __acquire_numeric(name, buf, hint, &__err_code); 1.270 + if (!__lwpunct) { 1.271 + delete punct; 1.272 + locale::_M_throw_on_creation_failure(__err_code, name, "numpunct"); 1.273 + return hint; 1.274 + } 1.275 + if (__lwpunct) { 1.276 + _STLP_TRY { 1.277 + wpunct = new numpunct_byname<wchar_t>(__lwpunct); 1.278 + } 1.279 + _STLP_UNWIND(_STLP_PRIV __release_numeric(__lwpunct); delete punct); 1.280 + } 1.281 +#endif 1.282 + 1.283 + this->insert(punct, numpunct<char>::id); 1.284 +#ifndef _STLP_NO_WCHAR_T 1.285 + this->insert(wpunct, numpunct<wchar_t>::id); 1.286 +#endif 1.287 + } 1.288 + return hint; 1.289 +} 1.290 + 1.291 +_Locale_name_hint* _Locale_impl::insert_time_facets(const char* &name, char *buf, _Locale_name_hint* hint) { 1.292 + if (name[0] == 0) 1.293 + name = _Locale_time_default(buf); 1.294 + 1.295 + if (name == 0 || name[0] == 0 || is_C_locale_name(name)) { 1.296 + _Locale_impl* i2 = locale::classic()._M_impl; 1.297 + this->insert(i2, 1.298 + time_get<char, istreambuf_iterator<char, char_traits<char> > >::id); 1.299 + this->insert(i2, 1.300 + time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id); 1.301 +#ifndef _STLP_NO_WCHAR_T 1.302 + this->insert(i2, 1.303 + time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id); 1.304 + this->insert(i2, 1.305 + time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id); 1.306 +#endif 1.307 + } else { 1.308 + locale::facet *get = 0; 1.309 + locale::facet *put = 0; 1.310 +#ifndef _STLP_NO_WCHAR_T 1.311 + locale::facet *wget = 0; 1.312 + locale::facet *wput = 0; 1.313 +#endif 1.314 + 1.315 + int __err_code; 1.316 + _Locale_time *__time = _STLP_PRIV __acquire_time(name, buf, hint, &__err_code); 1.317 + if (!__time) { 1.318 + // time facets category is not mandatory for correct stream behavior so if platform 1.319 + // do not support it we do not generate a runtime_error exception. 1.320 + if (__err_code == _STLP_LOC_NO_MEMORY) { 1.321 + _STLP_THROW_BAD_ALLOC; 1.322 + } 1.323 + return hint; 1.324 + } 1.325 + 1.326 + if (!hint) hint = _Locale_get_time_hint(__time); 1.327 + _STLP_TRY { 1.328 + get = new time_get_byname<char, istreambuf_iterator<char, char_traits<char> > >(__time); 1.329 + put = new time_put_byname<char, ostreambuf_iterator<char, char_traits<char> > >(__time); 1.330 +#ifndef _STLP_NO_WCHAR_T 1.331 + wget = new time_get_byname<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(__time); 1.332 + wput = new time_put_byname<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(__time); 1.333 +#endif 1.334 + } 1.335 +#ifndef _STLP_NO_WCHAR_T 1.336 + _STLP_UNWIND(delete wget; delete put; delete get; _STLP_PRIV __release_time(__time)); 1.337 +#else 1.338 + _STLP_UNWIND(delete get; _STLP_PRIV __release_time(__time)); 1.339 +#endif 1.340 + 1.341 + _STLP_PRIV __release_time(__time); 1.342 + 1.343 + this->insert(get, time_get<char, istreambuf_iterator<char, char_traits<char> > >::id); 1.344 + this->insert(put, time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id); 1.345 +#ifndef _STLP_NO_WCHAR_T 1.346 + this->insert(wget, time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id); 1.347 + this->insert(wput, time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id); 1.348 +#endif 1.349 + } 1.350 + return hint; 1.351 +} 1.352 + 1.353 +_Locale_name_hint* _Locale_impl::insert_collate_facets(const char* &name, char *buf, _Locale_name_hint* hint) { 1.354 + if (name[0] == 0) 1.355 + name = _Locale_collate_default(buf); 1.356 + 1.357 + if (name == 0 || name[0] == 0 || is_C_locale_name(name)) { 1.358 + _Locale_impl* i2 = locale::classic()._M_impl; 1.359 + this->insert(i2, collate<char>::id); 1.360 +#ifndef _STLP_NO_WCHAR_T 1.361 + this->insert(i2, collate<wchar_t>::id); 1.362 +#endif 1.363 + } 1.364 + else { 1.365 + locale::facet *col = 0; 1.366 +#ifndef _STLP_NO_WCHAR_T 1.367 + locale::facet *wcol = 0; 1.368 +#endif 1.369 + 1.370 + int __err_code; 1.371 + _Locale_collate *__coll = _STLP_PRIV __acquire_collate(name, buf, hint, &__err_code); 1.372 + if (!__coll) { 1.373 + if (__err_code == _STLP_LOC_NO_MEMORY) { 1.374 + _STLP_THROW_BAD_ALLOC; 1.375 + } 1.376 + return hint; 1.377 + } 1.378 + 1.379 + if (hint == 0) hint = _Locale_get_collate_hint(__coll); 1.380 + _STLP_TRY { 1.381 + col = new collate_byname<char>(__coll); 1.382 + } 1.383 + _STLP_UNWIND(_STLP_PRIV __release_collate(__coll)); 1.384 + 1.385 +#ifndef _STLP_NO_WCHAR_T 1.386 + _Locale_collate *__wcoll = _STLP_PRIV __acquire_collate(name, buf, hint, &__err_code); 1.387 + if (!__wcoll) { 1.388 + if (__err_code == _STLP_LOC_NO_MEMORY) { 1.389 + delete col; 1.390 + _STLP_THROW_BAD_ALLOC; 1.391 + } 1.392 + } 1.393 + if (__wcoll) { 1.394 + _STLP_TRY { 1.395 + wcol = new collate_byname<wchar_t>(__wcoll); 1.396 + } 1.397 + _STLP_UNWIND(_STLP_PRIV __release_collate(__wcoll); delete col); 1.398 + } 1.399 +#endif 1.400 + 1.401 + this->insert(col, collate<char>::id); 1.402 +#ifndef _STLP_NO_WCHAR_T 1.403 + if (wcol) this->insert(wcol, collate<wchar_t>::id); 1.404 +#endif 1.405 + } 1.406 + return hint; 1.407 +} 1.408 + 1.409 +_Locale_name_hint* _Locale_impl::insert_monetary_facets(const char* &name, char *buf, _Locale_name_hint* hint) { 1.410 + if (name[0] == 0) 1.411 + name = _Locale_monetary_default(buf); 1.412 + 1.413 + _Locale_impl* i2 = locale::classic()._M_impl; 1.414 + 1.415 + // We first insert name independant facets taken from the classic locale instance: 1.416 + this->insert(i2, money_get<char, istreambuf_iterator<char, char_traits<char> > >::id); 1.417 + this->insert(i2, money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id); 1.418 +#ifndef _STLP_NO_WCHAR_T 1.419 + this->insert(i2, money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id); 1.420 + this->insert(i2, money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id); 1.421 +#endif 1.422 + 1.423 + if (name == 0 || name[0] == 0 || is_C_locale_name(name)) { 1.424 + this->insert(i2, moneypunct<char, false>::id); 1.425 + this->insert(i2, moneypunct<char, true>::id); 1.426 +#ifndef _STLP_NO_WCHAR_T 1.427 + this->insert(i2, moneypunct<wchar_t, false>::id); 1.428 + this->insert(i2, moneypunct<wchar_t, true>::id); 1.429 +#endif 1.430 + } 1.431 + else { 1.432 + locale::facet *punct = 0; 1.433 + locale::facet *ipunct = 0; 1.434 + 1.435 +#ifndef _STLP_NO_WCHAR_T 1.436 + locale::facet* wpunct = 0; 1.437 + locale::facet* wipunct = 0; 1.438 +#endif 1.439 + 1.440 + int __err_code; 1.441 + _Locale_monetary *__mon = _STLP_PRIV __acquire_monetary(name, buf, hint, &__err_code); 1.442 + if (!__mon) { 1.443 + if (__err_code == _STLP_LOC_NO_MEMORY) { 1.444 + _STLP_THROW_BAD_ALLOC; 1.445 + } 1.446 + return hint; 1.447 + } 1.448 + 1.449 + if (hint == 0) hint = _Locale_get_monetary_hint(__mon); 1.450 + 1.451 + _STLP_TRY { 1.452 + punct = new moneypunct_byname<char, false>(__mon); 1.453 + } 1.454 + _STLP_UNWIND(_STLP_PRIV __release_monetary(__mon)); 1.455 + 1.456 + _Locale_monetary *__imon = _STLP_PRIV __acquire_monetary(name, buf, hint, &__err_code); 1.457 + if (!__imon) { 1.458 + delete punct; 1.459 + if (__err_code == _STLP_LOC_NO_MEMORY) { 1.460 + _STLP_THROW_BAD_ALLOC; 1.461 + } 1.462 + return hint; 1.463 + } 1.464 + 1.465 + _STLP_TRY { 1.466 + ipunct = new moneypunct_byname<char, true>(__imon); 1.467 + } 1.468 + _STLP_UNWIND(_STLP_PRIV __release_monetary(__imon); delete punct); 1.469 + 1.470 +#ifndef _STLP_NO_WCHAR_T 1.471 + _STLP_TRY { 1.472 + _Locale_monetary *__wmon = _STLP_PRIV __acquire_monetary(name, buf, hint, &__err_code); 1.473 + if (!__wmon) { 1.474 + if (__err_code == _STLP_LOC_NO_MEMORY) { 1.475 + _STLP_THROW_BAD_ALLOC; 1.476 + } 1.477 + } 1.478 + 1.479 + if (__wmon) { 1.480 + _STLP_TRY { 1.481 + wpunct = new moneypunct_byname<wchar_t, false>(__wmon); 1.482 + } 1.483 + _STLP_UNWIND(_STLP_PRIV __release_monetary(__wmon)); 1.484 + 1.485 + _Locale_monetary *__wimon = _STLP_PRIV __acquire_monetary(name, buf, hint, &__err_code); 1.486 + if (!__wimon) { 1.487 + delete wpunct; 1.488 + if (__err_code == _STLP_LOC_NO_MEMORY) { 1.489 + _STLP_THROW_BAD_ALLOC; 1.490 + } 1.491 + wpunct = 0; 1.492 + } 1.493 + else { 1.494 + _STLP_TRY { 1.495 + wipunct = new moneypunct_byname<wchar_t, true>(__wimon); 1.496 + } 1.497 + _STLP_UNWIND(_STLP_PRIV __release_monetary(__wimon); delete wpunct); 1.498 + } 1.499 + } 1.500 + } 1.501 + _STLP_UNWIND(delete ipunct; delete punct); 1.502 +#endif 1.503 + 1.504 + this->insert(punct, moneypunct<char, false>::id); 1.505 + this->insert(ipunct, moneypunct<char, true>::id); 1.506 +#ifndef _STLP_NO_WCHAR_T 1.507 + if (wpunct) this->insert(wpunct, moneypunct<wchar_t, false>::id); 1.508 + if (wipunct) this->insert(wipunct, moneypunct<wchar_t, true>::id); 1.509 +#endif 1.510 + } 1.511 + return hint; 1.512 +} 1.513 + 1.514 +_Locale_name_hint* _Locale_impl::insert_messages_facets(const char* &name, char *buf, _Locale_name_hint* hint) { 1.515 + if (name[0] == 0) 1.516 + name = _Locale_messages_default(buf); 1.517 + 1.518 + if (name == 0 || name[0] == 0 || is_C_locale_name(name)) { 1.519 + _Locale_impl* i2 = locale::classic()._M_impl; 1.520 + this->insert(i2, messages<char>::id); 1.521 +#ifndef _STLP_NO_WCHAR_T 1.522 + this->insert(i2, messages<wchar_t>::id); 1.523 +#endif 1.524 + } 1.525 + else { 1.526 + locale::facet *msg = 0; 1.527 +#ifndef _STLP_NO_WCHAR_T 1.528 + locale::facet *wmsg = 0; 1.529 +#endif 1.530 + 1.531 + int __err_code; 1.532 + _Locale_messages *__msg = _STLP_PRIV __acquire_messages(name, buf, hint, &__err_code); 1.533 + if (!__msg) { 1.534 + if (__err_code == _STLP_LOC_NO_MEMORY) { 1.535 + _STLP_THROW_BAD_ALLOC; 1.536 + } 1.537 + return hint; 1.538 + } 1.539 + 1.540 + _STLP_TRY { 1.541 + msg = new messages_byname<char>(__msg); 1.542 + } 1.543 + _STLP_UNWIND(_STLP_PRIV __release_messages(__msg)); 1.544 + 1.545 +#ifndef _STLP_NO_WCHAR_T 1.546 + _STLP_TRY { 1.547 + _Locale_messages *__wmsg = _STLP_PRIV __acquire_messages(name, buf, hint, &__err_code); 1.548 + if (!__wmsg) { 1.549 + if (__err_code == _STLP_LOC_NO_MEMORY) { 1.550 + _STLP_THROW_BAD_ALLOC; 1.551 + } 1.552 + } 1.553 + 1.554 + if (__wmsg) { 1.555 + _STLP_TRY { 1.556 + wmsg = new messages_byname<wchar_t>(__wmsg); 1.557 + } 1.558 + _STLP_UNWIND(_STLP_PRIV __release_messages(__wmsg)); 1.559 + } 1.560 + } 1.561 + _STLP_UNWIND(delete msg); 1.562 +#endif 1.563 + 1.564 + this->insert(msg, messages<char>::id); 1.565 +#ifndef _STLP_NO_WCHAR_T 1.566 + if (wmsg) this->insert(wmsg, messages<wchar_t>::id); 1.567 +#endif 1.568 + } 1.569 + return hint; 1.570 +} 1.571 + 1.572 +static void _Stl_loc_assign_ids() { 1.573 + // This assigns ids to every facet that is a member of a category, 1.574 + // and also to money_get/put, num_get/put, and time_get/put 1.575 + // instantiated using ordinary pointers as the input/output 1.576 + // iterators. (The default is [io]streambuf_iterator.) 1.577 + 1.578 + money_get<char, istreambuf_iterator<char, char_traits<char> > >::id._M_index = 8; 1.579 + money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id._M_index = 9; 1.580 + num_get<char, istreambuf_iterator<char, char_traits<char> > >::id._M_index = 10; 1.581 + num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id._M_index = 11; 1.582 + time_get<char, istreambuf_iterator<char, char_traits<char> > >::id._M_index = 12; 1.583 + time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id._M_index = 13; 1.584 + 1.585 +#ifndef _STLP_NO_WCHAR_T 1.586 + money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 21; 1.587 + money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 22; 1.588 + num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 23; 1.589 + num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > ::id._M_index = 24; 1.590 + time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 25; 1.591 + time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 26; 1.592 +#endif 1.593 + // locale::id::_S_max = 27; 1.594 +} 1.595 + 1.596 +// To access those static instance use the getter below, they guaranty 1.597 +// a correct initialization. 1.598 +static locale *_Stl_classic_locale = 0; 1.599 +static locale *_Stl_global_locale = 0; 1.600 + 1.601 +locale* _Stl_get_classic_locale() { 1.602 + static _Locale_impl::Init init; 1.603 + return _Stl_classic_locale; 1.604 +} 1.605 + 1.606 +locale* _Stl_get_global_locale() { 1.607 + static _Locale_impl::Init init; 1.608 + return _Stl_global_locale; 1.609 +} 1.610 + 1.611 +#if defined (_STLP_MSVC) || defined (__ICL) || defined (__ISCPP__) || defined (__DMC__) 1.612 +/* 1.613 + * The following static variable needs to be initialized before STLport 1.614 + * users static variable in order for him to be able to use Standard 1.615 + * streams in its variable initialization. 1.616 + * This variable is here because MSVC do not allow to change the initialization 1.617 + * segment in a given translation unit, iostream.cpp already contains an 1.618 + * initialization segment specification. 1.619 + */ 1.620 +# pragma warning (disable : 4073) 1.621 +# pragma init_seg(lib) 1.622 +#endif 1.623 + 1.624 +static ios_base::Init _IosInit; 1.625 + 1.626 +void _Locale_impl::make_classic_locale() { 1.627 + // This funcion will be called once: during build classic _Locale_impl 1.628 + 1.629 + // The classic locale contains every facet that belongs to a category. 1.630 + static _Stl_aligned_buffer<_Locale_impl> _Locale_classic_impl_buf; 1.631 + _Locale_impl *classic = new(&_Locale_classic_impl_buf) _Locale_impl("C"); 1.632 + 1.633 + locale::facet* classic_facets[] = { 1.634 + 0, 1.635 + new collate<char>(1), 1.636 + new ctype<char>(0, false, 1), 1.637 + new codecvt<char, char, mbstate_t>(1), 1.638 + new moneypunct<char, true>(1), 1.639 + new moneypunct<char, false>(1), 1.640 + new numpunct<char>(1), 1.641 + new messages<char>(1), 1.642 + new money_get<char, istreambuf_iterator<char, char_traits<char> > >(1), 1.643 + new money_put<char, ostreambuf_iterator<char, char_traits<char> > >(1), 1.644 + new num_get<char, istreambuf_iterator<char, char_traits<char> > >(1), 1.645 + new num_put<char, ostreambuf_iterator<char, char_traits<char> > >(1), 1.646 + new time_get<char, istreambuf_iterator<char, char_traits<char> > >(1), 1.647 + new time_put<char, ostreambuf_iterator<char, char_traits<char> > >(1), 1.648 +#ifndef _STLP_NO_WCHAR_T 1.649 + new collate<wchar_t>(1), 1.650 + new ctype<wchar_t>(1), 1.651 + new codecvt<wchar_t, char, mbstate_t>(1), 1.652 + new moneypunct<wchar_t, true>(1), 1.653 + new moneypunct<wchar_t, false>(1), 1.654 + new numpunct<wchar_t>(1), 1.655 + new messages<wchar_t>(1), 1.656 + new money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1), 1.657 + new money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1), 1.658 + new num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1), 1.659 + new num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1), 1.660 + new time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1), 1.661 + new time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1), 1.662 +#endif 1.663 + 0 1.664 + }; 1.665 + 1.666 + const size_t nb_classic_facets = sizeof(classic_facets) / sizeof(locale::facet *); 1.667 + classic->facets_vec.reserve(nb_classic_facets); 1.668 + classic->facets_vec.assign(&classic_facets[0], &classic_facets[0] + nb_classic_facets); 1.669 + 1.670 + static locale _Locale_classic(classic); 1.671 + _Stl_classic_locale = &_Locale_classic; 1.672 + 1.673 + static locale _Locale_global(classic); 1.674 + _Stl_global_locale = &_Locale_global; 1.675 +} 1.676 + 1.677 +// Declarations of (non-template) facets' static data members 1.678 +// size_t locale::id::_S_max = 27; // made before 1.679 + 1.680 +locale::id collate<char>::id = { 1 }; 1.681 +locale::id ctype<char>::id = { 2 }; 1.682 +locale::id codecvt<char, char, mbstate_t>::id = { 3 }; 1.683 +locale::id moneypunct<char, true>::id = { 4 }; 1.684 +locale::id moneypunct<char, false>::id = { 5 }; 1.685 +locale::id numpunct<char>::id = { 6 } ; 1.686 +locale::id messages<char>::id = { 7 }; 1.687 + 1.688 +#ifndef _STLP_NO_WCHAR_T 1.689 +locale::id collate<wchar_t>::id = { 14 }; 1.690 +locale::id ctype<wchar_t>::id = { 15 }; 1.691 +locale::id codecvt<wchar_t, char, mbstate_t>::id = { 16 }; 1.692 +locale::id moneypunct<wchar_t, true>::id = { 17 } ; 1.693 +locale::id moneypunct<wchar_t, false>::id = { 18 } ; 1.694 +locale::id numpunct<wchar_t>::id = { 19 }; 1.695 +locale::id messages<wchar_t>::id = { 20 }; 1.696 +#endif 1.697 + 1.698 +_STLP_DECLSPEC _Locale_impl* _STLP_CALL _get_Locale_impl(_Locale_impl *loc) 1.699 +{ 1.700 + _STLP_ASSERT( loc != 0 ); 1.701 + loc->_M_incr(); 1.702 + return loc; 1.703 +} 1.704 + 1.705 +void _STLP_CALL _release_Locale_impl(_Locale_impl *& loc) 1.706 +{ 1.707 + _STLP_ASSERT( loc != 0 ); 1.708 + if (loc->_M_decr() == 0) { 1.709 + if (*loc != *_Stl_classic_locale) 1.710 + delete loc; 1.711 + else 1.712 + loc->~_Locale_impl(); 1.713 + loc = 0; 1.714 + } 1.715 +} 1.716 + 1.717 +_STLP_DECLSPEC _Locale_impl* _STLP_CALL _copy_Nameless_Locale_impl(_Locale_impl *loc) 1.718 +{ 1.719 + _STLP_ASSERT( loc != 0 ); 1.720 + _Locale_impl *loc_new = new _Locale_impl(*loc); 1.721 + loc_new->name = _Nameless; 1.722 + return loc_new; 1.723 +} 1.724 + 1.725 +/* _GetFacetId implementation have to be here in order to be in the same translation unit 1.726 + * as where id are initialize (in _Stl_loc_assign_ids) */ 1.727 +_STLP_MOVE_TO_PRIV_NAMESPACE 1.728 + 1.729 +_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const money_get<char, istreambuf_iterator<char, char_traits<char> > >*) 1.730 +{ return money_get<char, istreambuf_iterator<char, char_traits<char> > >::id; } 1.731 +_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const money_put<char, ostreambuf_iterator<char, char_traits<char> > >*) 1.732 +{ return money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id; } 1.733 +#ifndef _STLP_NO_WCHAR_T 1.734 +_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >*) 1.735 +{ return money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id; } 1.736 +_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >*) 1.737 +{ return money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id; } 1.738 +#endif 1.739 + 1.740 +_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const num_get<char, istreambuf_iterator<char, char_traits<char> > >*) 1.741 +{ return num_get<char, istreambuf_iterator<char, char_traits<char> > >::id; } 1.742 +#ifndef _STLP_NO_WCHAR_T 1.743 +_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >*) 1.744 +{ return num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id; } 1.745 +#endif 1.746 + 1.747 +_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const num_put<char, ostreambuf_iterator<char, char_traits<char> > >*) 1.748 +{ return num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id; } 1.749 +#ifndef _STLP_NO_WCHAR_T 1.750 +_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >*) 1.751 +{ return num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id; } 1.752 +#endif 1.753 + 1.754 +_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const time_get<char, istreambuf_iterator<char, char_traits<char> > >*) 1.755 +{ return time_get<char, istreambuf_iterator<char, char_traits<char> > >::id; } 1.756 +_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const time_put<char, ostreambuf_iterator<char, char_traits<char> > >*) 1.757 +{ return time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id; } 1.758 +#ifndef _STLP_NO_WCHAR_T 1.759 +_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >*) 1.760 +{ return time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id; } 1.761 +_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >*) 1.762 +{ return time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id; } 1.763 +#endif 1.764 + 1.765 +_STLP_MOVE_TO_STD_NAMESPACE 1.766 + 1.767 +_STLP_END_NAMESPACE 1.768 +