1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/src/facets_byname.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1143 @@
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 <hash_map>
1.24 +#include <vector>
1.25 +
1.26 +#include <locale>
1.27 +#include <istream>
1.28 +
1.29 +#include <algorithm>
1.30 +#include <functional>
1.31 +
1.32 +#include "c_locale.h"
1.33 +#include "locale_impl.h"
1.34 +#include "acquire_release.h"
1.35 +
1.36 +_STLP_BEGIN_NAMESPACE
1.37 +
1.38 +//----------------------------------------------------------------------
1.39 +// ctype_byname<char>
1.40 +
1.41 +_STLP_DECLSPEC ctype_byname<char>::ctype_byname(const char* name, size_t refs, _Locale_name_hint* hint) :
1.42 + ctype<char>( 0, false, refs),
1.43 + _M_ctype(_STLP_PRIV __acquire_ctype(name, hint)) {
1.44 + ctype<char>::_M_ctype_table = _M_byname_table;
1.45 + if (!_M_ctype)
1.46 + locale::_M_throw_runtime_error();
1.47 +
1.48 + // We have to do this, instead of just pointer twiddling, because
1.49 + // ctype_base::mask isn't the same type as _Locale_mask_t.
1.50 +
1.51 + const _Locale_mask_t* p = _Locale_ctype_table(_M_ctype);
1.52 +
1.53 + if (!p)
1.54 + locale::_M_throw_runtime_error();
1.55 +
1.56 + for (size_t i = 0; i < table_size; ++i) {
1.57 + _Locale_mask_t __m = p[i];
1.58 + if (__m & (upper | lower))
1.59 + __m |= alpha;
1.60 + _M_byname_table[i] = ctype_base::mask(__m);
1.61 + }
1.62 +}
1.63 +
1.64 +_STLP_DECLSPEC ctype_byname<char>::~ctype_byname()
1.65 +{ _STLP_PRIV __release_ctype(_M_ctype); }
1.66 +
1.67 +_STLP_DECLSPEC char ctype_byname<char>::do_toupper(char c) const
1.68 +{ return (char)_Locale_toupper(_M_ctype, c); }
1.69 +
1.70 +_STLP_DECLSPEC char ctype_byname<char>::do_tolower(char c) const
1.71 +{ return (char)_Locale_tolower(_M_ctype, c); }
1.72 +
1.73 +_STLP_DECLSPEC const char*
1.74 +ctype_byname<char>::do_toupper(char* first, const char* last) const {
1.75 + for ( ; first != last ; ++first)
1.76 + *first = (char)_Locale_toupper(_M_ctype, *first);
1.77 + return last;
1.78 +}
1.79 +
1.80 +_STLP_DECLSPEC const char*
1.81 +ctype_byname<char>::do_tolower(char* first, const char* last) const {
1.82 + for ( ; first != last ; ++first)
1.83 + *first = (char)_Locale_tolower(_M_ctype, *first);
1.84 + return last;
1.85 +}
1.86 +
1.87 +
1.88 +// Some helper functions used in ctype<>::scan_is and scan_is_not.
1.89 +#if !defined (_STLP_NO_WCHAR_T)
1.90 +
1.91 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.92 +
1.93 +// ctype_byname<wchar_t>
1.94 +
1.95 +struct _Ctype_byname_w_is_mask {
1.96 + typedef wchar_t argument_type;
1.97 + typedef bool result_type;
1.98 +
1.99 + /* ctype_base::mask*/ int M;
1.100 + _Locale_ctype* M_ctp;
1.101 +
1.102 + _Ctype_byname_w_is_mask(/* ctype_base::mask */ int m, _Locale_ctype* c) : M((int)m), M_ctp(c) {}
1.103 + bool operator()(wchar_t c) const
1.104 + { return (M & _Locale_wchar_ctype(M_ctp, c, M)) != 0; }
1.105 +};
1.106 +
1.107 +_STLP_MOVE_TO_STD_NAMESPACE
1.108 +
1.109 +_STLP_DECLSPEC ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs, _Locale_name_hint* hint)
1.110 + : ctype<wchar_t>(refs),
1.111 + _M_ctype(_STLP_PRIV __acquire_ctype(name, hint)) {
1.112 + if (!_M_ctype)
1.113 + locale::_M_throw_runtime_error();
1.114 +}
1.115 +
1.116 +_STLP_DECLSPEC ctype_byname<wchar_t>::~ctype_byname()
1.117 +{ _STLP_PRIV __release_ctype(_M_ctype); }
1.118 +
1.119 +_STLP_DECLSPEC bool ctype_byname<wchar_t>::do_is(ctype_base::mask m, wchar_t c) const
1.120 +{ return (m & _Locale_wchar_ctype(_M_ctype, c, m)) != 0; }
1.121 +
1.122 +_STLP_DECLSPEC const wchar_t*
1.123 +ctype_byname<wchar_t>::do_is(const wchar_t* low, const wchar_t* high,
1.124 + ctype_base::mask * m) const {
1.125 + ctype_base::mask all_bits = ctype_base::mask(
1.126 + ctype_base::space |
1.127 + ctype_base::print |
1.128 + ctype_base::cntrl |
1.129 + ctype_base::upper |
1.130 + ctype_base::lower |
1.131 + ctype_base::alpha |
1.132 + ctype_base::digit |
1.133 + ctype_base::punct |
1.134 + ctype_base::xdigit);
1.135 +
1.136 + for ( ; low < high; ++low, ++m)
1.137 + *m = ctype_base::mask (_Locale_wchar_ctype(_M_ctype, *low, all_bits));
1.138 + return high;
1.139 +}
1.140 +
1.141 +_STLP_DECLSPEC const wchar_t*
1.142 +ctype_byname<wchar_t>
1.143 + ::do_scan_is(ctype_base::mask m, const wchar_t* low, const wchar_t* high) const
1.144 +{ return find_if(low, high, _STLP_PRIV _Ctype_byname_w_is_mask(m, _M_ctype)); }
1.145 +
1.146 +_STLP_DECLSPEC const wchar_t*
1.147 +ctype_byname<wchar_t>
1.148 + ::do_scan_not(ctype_base::mask m, const wchar_t* low, const wchar_t* high) const
1.149 +{ return find_if(low, high, not1(_STLP_PRIV _Ctype_byname_w_is_mask(m, _M_ctype))); }
1.150 +
1.151 +_STLP_DECLSPEC wchar_t ctype_byname<wchar_t>::do_toupper(wchar_t c) const
1.152 +{ return _Locale_wchar_toupper(_M_ctype, c); }
1.153 +
1.154 +_STLP_DECLSPEC const wchar_t*
1.155 +ctype_byname<wchar_t>::do_toupper(wchar_t* low, const wchar_t* high) const {
1.156 + for ( ; low < high; ++low)
1.157 + *low = _Locale_wchar_toupper(_M_ctype, *low);
1.158 + return high;
1.159 +}
1.160 +
1.161 +_STLP_DECLSPEC wchar_t ctype_byname<wchar_t>::do_tolower(wchar_t c) const
1.162 +{ return _Locale_wchar_tolower(_M_ctype, c); }
1.163 +
1.164 +_STLP_DECLSPEC const wchar_t*
1.165 +ctype_byname<wchar_t>::do_tolower(wchar_t* low, const wchar_t* high) const {
1.166 + for ( ; low < high; ++low)
1.167 + *low = _Locale_wchar_tolower(_M_ctype, *low);
1.168 + return high;
1.169 +}
1.170 +
1.171 +#endif /* WCHAR_T */
1.172 +
1.173 +// collate_byname<char>
1.174 +_STLP_DECLSPEC collate_byname<char>::collate_byname(const char* name, size_t refs, _Locale_name_hint* hint)
1.175 + : collate<char>(refs),
1.176 + _M_collate(_STLP_PRIV __acquire_collate(name, hint)) {
1.177 + if (!_M_collate)
1.178 + locale::_M_throw_runtime_error();
1.179 +}
1.180 +
1.181 +_STLP_DECLSPEC collate_byname<char>::~collate_byname()
1.182 +{ _STLP_PRIV __release_collate(_M_collate); }
1.183 +
1.184 +_STLP_DECLSPEC int collate_byname<char>::do_compare(const char* __low1,
1.185 + const char* __high1,
1.186 + const char* __low2,
1.187 + const char* __high2) const {
1.188 + return _Locale_strcmp(_M_collate,
1.189 + __low1, __high1 - __low1,
1.190 + __low2, __high2 - __low2);
1.191 +}
1.192 +
1.193 +_STLP_DECLSPEC collate_byname<char>::string_type
1.194 +collate_byname<char>::do_transform(const char* low, const char* high) const {
1.195 + if (low == high)
1.196 + return string_type();
1.197 +
1.198 + size_t n = _Locale_strxfrm(_M_collate, NULL, 0, low, high - low);
1.199 +
1.200 + // NOT PORTABLE. What we're doing relies on internal details of the
1.201 + // string implementation. (Contiguity of string elements and presence
1.202 + // of trailing zero.)
1.203 + string_type buf(n, 0);
1.204 + _Locale_strxfrm(_M_collate, &(*buf.begin()), n + 1, low, high - low);
1.205 + return buf;
1.206 +}
1.207 +
1.208 +
1.209 +#if !defined (_STLP_NO_WCHAR_T)
1.210 +
1.211 +// collate_byname<wchar_t>
1.212 +
1.213 +_STLP_DECLSPEC collate_byname<wchar_t>::collate_byname(const char* name, size_t refs, _Locale_name_hint* hint)
1.214 + : collate<wchar_t>(refs),
1.215 + _M_collate(_STLP_PRIV __acquire_collate(name, hint)) {
1.216 + if (!_M_collate)
1.217 + locale::_M_throw_runtime_error();
1.218 +}
1.219 +
1.220 +_STLP_DECLSPEC collate_byname<wchar_t>::~collate_byname()
1.221 +{ _STLP_PRIV __release_collate(_M_collate); }
1.222 +
1.223 +_STLP_DECLSPEC int collate_byname<wchar_t>::do_compare(const wchar_t* low1,
1.224 + const wchar_t* high1,
1.225 + const wchar_t* low2,
1.226 + const wchar_t* high2) const {
1.227 + return _Locale_strwcmp(_M_collate,
1.228 + low1, high1 - low1,
1.229 + low2, high2 - low2);
1.230 +}
1.231 +
1.232 +_STLP_DECLSPEC collate_byname<wchar_t>::string_type
1.233 +collate_byname<wchar_t>::do_transform(const wchar_t* low,
1.234 + const wchar_t* high) const {
1.235 + if (low == high)
1.236 + return string_type();
1.237 +
1.238 + size_t n = _Locale_strwxfrm(_M_collate, NULL, 0, low, high - low);
1.239 +
1.240 + // NOT PORTABLE. What we're doing relies on internal details of the
1.241 + // string implementation. (Contiguity of string elements and presence
1.242 + // of trailing zero.)
1.243 + string_type buf(n, 0);
1.244 + _Locale_strwxfrm(_M_collate, &(*buf.begin()), n + 1, low, high - low);
1.245 + return buf;
1.246 +}
1.247 +
1.248 +#endif /* _STLP_NO_WCHAR_T */
1.249 +
1.250 +_STLP_END_NAMESPACE
1.251 +
1.252 +#if !defined (_STLP_NO_MBSTATE_T)
1.253 +
1.254 +_STLP_BEGIN_NAMESPACE
1.255 +
1.256 +//----------------------------------------------------------------------
1.257 +// codecvt_byname<char>
1.258 +
1.259 +_STLP_DECLSPEC codecvt_byname<char, char, mbstate_t>
1.260 + ::codecvt_byname(const char* /* name */, size_t refs)
1.261 + : codecvt<char, char, mbstate_t>(refs) {}
1.262 +
1.263 +_STLP_DECLSPEC codecvt_byname<char, char, mbstate_t>::~codecvt_byname() {}
1.264 +
1.265 +
1.266 +# if !defined (_STLP_NO_WCHAR_T)
1.267 +
1.268 +//----------------------------------------------------------------------
1.269 +// codecvt_byname<wchar_t>
1.270 +_STLP_DECLSPEC codecvt_byname<wchar_t, char, mbstate_t>
1.271 + ::codecvt_byname(const char* name, size_t refs, _Locale_name_hint* hint)
1.272 + : codecvt<wchar_t, char, mbstate_t>(refs),
1.273 + _M_ctype(_STLP_PRIV __acquire_ctype(name, hint)) {
1.274 + if (!_M_ctype)
1.275 + locale::_M_throw_runtime_error();
1.276 +}
1.277 +
1.278 +_STLP_DECLSPEC codecvt_byname<wchar_t, char, mbstate_t>::~codecvt_byname()
1.279 +{ _STLP_PRIV __release_ctype(_M_ctype); }
1.280 +
1.281 +_STLP_DECLSPEC codecvt<wchar_t, char, mbstate_t>::result
1.282 +codecvt_byname<wchar_t, char, mbstate_t>
1.283 + ::do_out(state_type& state,
1.284 + const wchar_t* from,
1.285 + const wchar_t* from_end,
1.286 + const wchar_t*& from_next,
1.287 + char* to,
1.288 + char* to_limit,
1.289 + char*& to_next) const {
1.290 + while (from != from_end) {
1.291 + size_t chars_stored = _Locale_wctomb(_M_ctype,
1.292 + to, to_limit - to, *from,
1.293 + &state);
1.294 + if (chars_stored == (size_t) -1) {
1.295 + from_next = from;
1.296 + to_next = to;
1.297 + return error;
1.298 + }
1.299 + else if (chars_stored == (size_t) -2) {
1.300 + from_next = from;
1.301 + to_next = to;
1.302 + return partial;
1.303 + }
1.304 +
1.305 + ++from;
1.306 + to += chars_stored;
1.307 + }
1.308 +
1.309 + from_next = from;
1.310 + to_next = to;
1.311 + return ok;
1.312 +}
1.313 +
1.314 + _STLP_DECLSPEC codecvt<wchar_t, char, mbstate_t>::result
1.315 +codecvt_byname<wchar_t, char, mbstate_t>
1.316 + ::do_in(state_type& state,
1.317 + const extern_type* from,
1.318 + const extern_type* from_end,
1.319 + const extern_type*& from_next,
1.320 + intern_type* to,
1.321 + intern_type* ,
1.322 + intern_type*& to_next) const {
1.323 + while (from != from_end) {
1.324 + size_t chars_read = _Locale_mbtowc(_M_ctype,
1.325 + to, from, from_end - from,
1.326 + &state);
1.327 + if (chars_read == (size_t) -1) {
1.328 + from_next = from;
1.329 + to_next = to;
1.330 + return error;
1.331 + }
1.332 +
1.333 + if (chars_read == (size_t) -2) {
1.334 + from_next = from;
1.335 + to_next = to;
1.336 + return partial;
1.337 + }
1.338 +
1.339 + from += chars_read;
1.340 + to++;
1.341 + }
1.342 +
1.343 + from_next = from;
1.344 + to_next = to;
1.345 + return ok;
1.346 +}
1.347 +
1.348 +_STLP_DECLSPEC codecvt<wchar_t, char, mbstate_t>::result
1.349 +codecvt_byname<wchar_t, char, mbstate_t>
1.350 + ::do_unshift(state_type& state,
1.351 + extern_type* to,
1.352 + extern_type* to_limit,
1.353 + extern_type*& to_next) const {
1.354 + to_next = to;
1.355 + size_t result = _Locale_unshift(_M_ctype, &state,
1.356 + to, to_limit - to, &to_next);
1.357 + if (result == (size_t) -1)
1.358 + return error;
1.359 + else if (result == (size_t) -2)
1.360 + return partial;
1.361 + else
1.362 +# if defined (__ISCPP__)
1.363 + return /*to_next == to ? noconv :*/ ok;
1.364 +# else
1.365 + return to_next == to ? noconv : ok;
1.366 +# endif
1.367 +}
1.368 +
1.369 +_STLP_DECLSPEC int
1.370 +codecvt_byname<wchar_t, char, mbstate_t>::do_encoding() const _STLP_NOTHROW {
1.371 + if (_Locale_is_stateless(_M_ctype)) {
1.372 + int max_width = _Locale_mb_cur_max(_M_ctype);
1.373 + int min_width = _Locale_mb_cur_min(_M_ctype);
1.374 + return min_width == max_width ? min_width : 0;
1.375 + }
1.376 + else
1.377 + return -1;
1.378 +}
1.379 +
1.380 +_STLP_DECLSPEC bool codecvt_byname<wchar_t, char, mbstate_t>
1.381 + ::do_always_noconv() const _STLP_NOTHROW {
1.382 + return false;
1.383 +}
1.384 +
1.385 +_STLP_DECLSPEC int
1.386 +codecvt_byname<wchar_t, char, mbstate_t>::do_length(const state_type&,
1.387 + const extern_type* from, const extern_type* end,
1.388 + size_t mx) const
1.389 +{ return (int)(min) ((size_t) (end - from), mx); }
1.390 +
1.391 +_STLP_DECLSPEC int
1.392 +codecvt_byname<wchar_t, char, mbstate_t>::do_max_length() const _STLP_NOTHROW
1.393 +{ return _Locale_mb_cur_max(_M_ctype); }
1.394 +# endif
1.395 +
1.396 +_STLP_END_NAMESPACE
1.397 +
1.398 +#endif /* MBSTATE_T */
1.399 +
1.400 +_STLP_BEGIN_NAMESPACE
1.401 +
1.402 +// numpunct_byname<char>
1.403 +_STLP_DECLSPEC numpunct_byname<char>::numpunct_byname(const char* name, size_t refs, _Locale_name_hint* hint)
1.404 + : numpunct<char>(refs),
1.405 + _M_numeric(_STLP_PRIV __acquire_numeric(name, hint)) {
1.406 + if (!_M_numeric)
1.407 + locale::_M_throw_runtime_error();
1.408 +
1.409 + _M_truename = _Locale_true(_M_numeric);
1.410 + _M_falsename = _Locale_false(_M_numeric);
1.411 +}
1.412 +
1.413 +_STLP_DECLSPEC numpunct_byname<char>::~numpunct_byname()
1.414 +{ _STLP_PRIV __release_numeric(_M_numeric); }
1.415 +
1.416 +_STLP_DECLSPEC char numpunct_byname<char>::do_decimal_point() const
1.417 +{ return _Locale_decimal_point(_M_numeric); }
1.418 +
1.419 +_STLP_DECLSPEC char numpunct_byname<char>::do_thousands_sep() const
1.420 +{ return _Locale_thousands_sep(_M_numeric); }
1.421 +
1.422 +_STLP_DECLSPEC string numpunct_byname<char>::do_grouping() const {
1.423 + const char * __grouping = _Locale_grouping(_M_numeric);
1.424 + if (__grouping != NULL && __grouping[0] == CHAR_MAX)
1.425 + __grouping = "";
1.426 + return __grouping;
1.427 +}
1.428 +
1.429 +//----------------------------------------------------------------------
1.430 +// numpunct<wchar_t>
1.431 +
1.432 +#if !defined (_STLP_NO_WCHAR_T)
1.433 +
1.434 +// numpunct_byname<wchar_t>
1.435 +
1.436 +_STLP_DECLSPEC numpunct_byname<wchar_t>::numpunct_byname(const char* name, size_t refs, _Locale_name_hint* hint)
1.437 + : numpunct<wchar_t>(refs),
1.438 + _M_numeric(_STLP_PRIV __acquire_numeric(name, hint)) {
1.439 + if (!_M_numeric)
1.440 + locale::_M_throw_runtime_error();
1.441 +
1.442 + const char* truename = _Locale_true(_M_numeric);
1.443 + const char* falsename = _Locale_false(_M_numeric);
1.444 + _M_truename.resize(strlen(truename));
1.445 + _M_falsename.resize(strlen(falsename));
1.446 + copy(truename, truename + strlen(truename), _M_truename.begin());
1.447 + copy(falsename, falsename + strlen(falsename), _M_falsename.begin());
1.448 +}
1.449 +
1.450 +_STLP_DECLSPEC numpunct_byname<wchar_t>::~numpunct_byname()
1.451 +{ _STLP_PRIV __release_numeric(_M_numeric); }
1.452 +
1.453 +_STLP_DECLSPEC wchar_t numpunct_byname<wchar_t>::do_decimal_point() const
1.454 +{ return (wchar_t) _Locale_decimal_point(_M_numeric); }
1.455 +
1.456 +_STLP_DECLSPEC wchar_t numpunct_byname<wchar_t>::do_thousands_sep() const
1.457 +{ return (wchar_t) _Locale_thousands_sep(_M_numeric); }
1.458 +
1.459 +_STLP_DECLSPEC string numpunct_byname<wchar_t>::do_grouping() const {
1.460 + const char * __grouping = _Locale_grouping(_M_numeric);
1.461 + if (__grouping != NULL && __grouping[0] == CHAR_MAX)
1.462 + __grouping = "";
1.463 + return __grouping;
1.464 +}
1.465 +
1.466 +#endif
1.467 +
1.468 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.469 +
1.470 +static void _Init_monetary_formats(money_base::pattern& pos_format,
1.471 + money_base::pattern& neg_format,
1.472 + _Locale_monetary * monetary) {
1.473 + switch (_Locale_p_sign_posn(monetary)) {
1.474 + case 0: // Parentheses surround the quantity and currency_symbol
1.475 + case 1: // The sign string precedes the quantity and currency_symbol
1.476 + pos_format.field[0] = (char) money_base::sign;
1.477 + if (_Locale_p_cs_precedes(monetary)) {
1.478 + // 1 if currency_symbol precedes a positive value
1.479 + pos_format.field[1] = (char) money_base::symbol;
1.480 + if (_Locale_p_sep_by_space(monetary)) {
1.481 + // a space separates currency_symbol from a positive value.
1.482 + pos_format.field[2] = (char) money_base::space;
1.483 + pos_format.field[3] = (char) money_base::value;
1.484 + } else {
1.485 + // a space not separates currency_symbol from a positive value.
1.486 + pos_format.field[2] = (char) money_base::value;
1.487 + pos_format.field[3] = (char) money_base::none;
1.488 + }
1.489 + } else {
1.490 + // 0 if currency_symbol succeeds a positive value
1.491 + pos_format.field[1] = (char) money_base::value;
1.492 + if (_Locale_p_sep_by_space(monetary)) {
1.493 + // a space separates currency_symbol from a positive value.
1.494 + pos_format.field[2] = (char) money_base::space;
1.495 + pos_format.field[3] = (char) money_base::symbol;
1.496 + } else {
1.497 + // a space not separates currency_symbol from a positive value.
1.498 + pos_format.field[2] = (char) money_base::symbol;
1.499 + pos_format.field[3] = (char) money_base::none;
1.500 + }
1.501 + }
1.502 + break;
1.503 + case 2: // The sign string succeeds the quantity and currency_symbol.
1.504 + if (_Locale_p_cs_precedes(monetary)) {
1.505 + // 1 if currency_symbol precedes a positive value
1.506 + pos_format.field[0] = (char) money_base::symbol;
1.507 + if (_Locale_p_sep_by_space(monetary)) {
1.508 + // a space separates currency_symbol from a positive value.
1.509 + pos_format.field[1] = (char) money_base::space;
1.510 + pos_format.field[2] = (char) money_base::value;
1.511 + pos_format.field[3] = (char) money_base::sign;
1.512 + } else {
1.513 + // a space not separates currency_symbol from a positive value.
1.514 + pos_format.field[1] = (char) money_base::value;
1.515 + pos_format.field[2] = (char) money_base::sign;
1.516 + pos_format.field[3] = (char) money_base::none;
1.517 + }
1.518 + } else {
1.519 + // 0 if currency_symbol succeeds a positive value
1.520 + pos_format.field[0] = (char) money_base::value;
1.521 + if (_Locale_p_sep_by_space(monetary)) {
1.522 + // a space separates currency_symbol from a positive value.
1.523 + pos_format.field[1] = (char) money_base::space;
1.524 + pos_format.field[2] = (char) money_base::symbol;
1.525 + pos_format.field[3] = (char) money_base::sign;
1.526 + } else {
1.527 + // a space not separates currency_symbol from a positive value.
1.528 + pos_format.field[1] = (char) money_base::symbol;
1.529 + pos_format.field[2] = (char) money_base::sign;
1.530 + pos_format.field[3] = (char) money_base::none;
1.531 + }
1.532 + }
1.533 + break;
1.534 + case 3: // The sign string immediately precedes the currency_symbol.
1.535 + if (_Locale_p_cs_precedes(monetary)) {
1.536 + // 1 if currency_symbol precedes a positive value
1.537 + pos_format.field[0] = (char) money_base::sign;
1.538 + pos_format.field[1] = (char) money_base::symbol;
1.539 + if (_Locale_p_sep_by_space(monetary)) {
1.540 + // a space separates currency_symbol from a positive value.
1.541 + pos_format.field[2] = (char) money_base::space;
1.542 + pos_format.field[3] = (char) money_base::value;
1.543 + } else {
1.544 + // a space not separates currency_symbol from a positive value.
1.545 + pos_format.field[2] = (char) money_base::value;
1.546 + pos_format.field[3] = (char) money_base::none;
1.547 + }
1.548 + } else {
1.549 + // 0 if currency_symbol succeeds a positive value
1.550 + pos_format.field[0] = (char) money_base::value;
1.551 + pos_format.field[1] = (char) money_base::sign;
1.552 + pos_format.field[2] = (char) money_base::symbol;
1.553 + pos_format.field[3] = (char) money_base::none;
1.554 + }
1.555 + break;
1.556 + case 4: // The sign string immediately succeeds the currency_symbol.
1.557 + default:
1.558 + if (_Locale_p_cs_precedes(monetary)) {
1.559 + // 1 if currency_symbol precedes a positive value
1.560 + pos_format.field[0] = (char) money_base::symbol;
1.561 + pos_format.field[1] = (char) money_base::sign;
1.562 + pos_format.field[2] = (char) money_base::value;
1.563 + pos_format.field[3] = (char) money_base::none;
1.564 + } else {
1.565 + // 0 if currency_symbol succeeds a positive value
1.566 + pos_format.field[0] = (char) money_base::value;
1.567 + if (_Locale_p_sep_by_space(monetary)) {
1.568 + // a space separates currency_symbol from a positive value.
1.569 + pos_format.field[1] = (char) money_base::space;
1.570 + pos_format.field[2] = (char) money_base::symbol;
1.571 + pos_format.field[3] = (char) money_base::sign;
1.572 + } else {
1.573 + // a space not separates currency_symbol from a positive value.
1.574 + pos_format.field[1] = (char) money_base::symbol;
1.575 + pos_format.field[2] = (char) money_base::sign;
1.576 + pos_format.field[3] = (char) money_base::none;
1.577 + }
1.578 + }
1.579 + break;
1.580 + }
1.581 +
1.582 + switch (_Locale_n_sign_posn(monetary)) {
1.583 + case 0: // Parentheses surround the quantity and currency_symbol
1.584 + case 1: // The sign string precedes the quantity and currency_symbol
1.585 + neg_format.field[0] = (char) money_base::sign;
1.586 + if (_Locale_n_cs_precedes(monetary)) {
1.587 + // 1 if currency_symbol precedes a negative value
1.588 + neg_format.field[1] = (char) money_base::symbol;
1.589 + if (_Locale_n_sep_by_space(monetary)) {
1.590 + // a space separates currency_symbol from a negative value.
1.591 + neg_format.field[2] = (char) money_base::space;
1.592 + neg_format.field[3] = (char) money_base::value;
1.593 + } else {
1.594 + // a space not separates currency_symbol from a negative value.
1.595 + neg_format.field[2] = (char) money_base::value;
1.596 + neg_format.field[3] = (char) money_base::none;
1.597 + }
1.598 + } else {
1.599 + // 0 if currency_symbol succeeds a negative value
1.600 + neg_format.field[1] = (char) money_base::value;
1.601 + if (_Locale_n_sep_by_space(monetary)) {
1.602 + // a space separates currency_symbol from a negative value.
1.603 + neg_format.field[2] = (char) money_base::space;
1.604 + neg_format.field[3] = (char) money_base::symbol;
1.605 + } else {
1.606 + // a space not separates currency_symbol from a negative value.
1.607 + neg_format.field[2] = (char) money_base::symbol;
1.608 + neg_format.field[3] = (char) money_base::none;
1.609 + }
1.610 + }
1.611 + break;
1.612 + case 2: // The sign string succeeds the quantity and currency_symbol.
1.613 + if (_Locale_n_cs_precedes(monetary)) {
1.614 + // 1 if currency_symbol precedes a negative value
1.615 + neg_format.field[0] = (char) money_base::symbol;
1.616 + if (_Locale_n_sep_by_space(monetary)) {
1.617 + // a space separates currency_symbol from a negative value.
1.618 + neg_format.field[1] = (char) money_base::space;
1.619 + neg_format.field[2] = (char) money_base::value;
1.620 + neg_format.field[3] = (char) money_base::sign;
1.621 + } else {
1.622 + // a space not separates currency_symbol from a negative value.
1.623 + neg_format.field[1] = (char) money_base::value;
1.624 + neg_format.field[2] = (char) money_base::sign;
1.625 + neg_format.field[3] = (char) money_base::none;
1.626 + }
1.627 + } else {
1.628 + // 0 if currency_symbol succeeds a negative value
1.629 + neg_format.field[0] = (char) money_base::value;
1.630 + if (_Locale_n_sep_by_space(monetary)) {
1.631 + // a space separates currency_symbol from a negative value.
1.632 + neg_format.field[1] = (char) money_base::space;
1.633 + neg_format.field[2] = (char) money_base::symbol;
1.634 + neg_format.field[3] = (char) money_base::sign;
1.635 + } else {
1.636 + // a space not separates currency_symbol from a negative value.
1.637 + neg_format.field[1] = (char) money_base::symbol;
1.638 + neg_format.field[2] = (char) money_base::sign;
1.639 + neg_format.field[3] = (char) money_base::none;
1.640 + }
1.641 + }
1.642 + break;
1.643 + case 3: // The sign string immediately precedes the currency_symbol.
1.644 + if (_Locale_n_cs_precedes(monetary)) {
1.645 + // 1 if currency_symbol precedes a negative value
1.646 + neg_format.field[0] = (char) money_base::sign;
1.647 + neg_format.field[1] = (char) money_base::symbol;
1.648 + if (_Locale_n_sep_by_space(monetary)) {
1.649 + // a space separates currency_symbol from a negative value.
1.650 + neg_format.field[2] = (char) money_base::space;
1.651 + neg_format.field[3] = (char) money_base::value;
1.652 + } else {
1.653 + // a space not separates currency_symbol from a negative value.
1.654 + neg_format.field[2] = (char) money_base::value;
1.655 + neg_format.field[3] = (char) money_base::none;
1.656 + }
1.657 + } else {
1.658 + // 0 if currency_symbol succeeds a negative value
1.659 + neg_format.field[0] = (char) money_base::value;
1.660 + neg_format.field[1] = (char) money_base::sign;
1.661 + neg_format.field[2] = (char) money_base::symbol;
1.662 + neg_format.field[3] = (char) money_base::none;
1.663 + }
1.664 + break;
1.665 + case 4: // The sign string immediately succeeds the currency_symbol.
1.666 + default:
1.667 + if (_Locale_n_cs_precedes(monetary)) {
1.668 + // 1 if currency_symbol precedes a negative value
1.669 + neg_format.field[0] = (char) money_base::symbol;
1.670 + neg_format.field[1] = (char) money_base::sign;
1.671 + neg_format.field[2] = (char) money_base::value;
1.672 + neg_format.field[3] = (char) money_base::none;
1.673 + } else {
1.674 + // 0 if currency_symbol succeeds a negative value
1.675 + neg_format.field[0] = (char) money_base::value;
1.676 + if (_Locale_n_sep_by_space(monetary)) {
1.677 + // a space separates currency_symbol from a negative value.
1.678 + neg_format.field[1] = (char) money_base::space;
1.679 + neg_format.field[2] = (char) money_base::symbol;
1.680 + neg_format.field[3] = (char) money_base::sign;
1.681 + } else {
1.682 + // a space not separates currency_symbol from a negative value.
1.683 + neg_format.field[1] = (char) money_base::symbol;
1.684 + neg_format.field[2] = (char) money_base::sign;
1.685 + neg_format.field[3] = (char) money_base::none;
1.686 + }
1.687 + }
1.688 + break;
1.689 + }
1.690 +}
1.691 +
1.692 +// international variant of monetary
1.693 +
1.694 +/*
1.695 + * int_curr_symbol
1.696 + *
1.697 + * The international currency symbol. The operand is a four-character
1.698 + * string, with the first three characters containing the alphabetic
1.699 + * international currency symbol in accordance with those specified
1.700 + * in the ISO 4217 specification. The fourth character is the character used
1.701 + * to separate the international currency symbol from the monetary quantity.
1.702 + *
1.703 + * (http://www.opengroup.org/onlinepubs/7990989775/xbd/locale.html)
1.704 + */
1.705 +
1.706 +/*
1.707 + * Standards are unclear in the usage of international currency
1.708 + * and monetary formats.
1.709 + * But I am expect that international currency symbol should be the first
1.710 + * (not depends upon where currency symbol situated in the national
1.711 + * format).
1.712 + *
1.713 + * If this isn't so, let's see:
1.714 + * 1 234.56 RUR
1.715 + * GBP 1,234.56
1.716 + * USD 1,234.56
1.717 + * The situation really is worse than you see above:
1.718 + * RUR typed wrong here---it prints '1 234.56 RUR ' (see space after RUR).
1.719 + * This is due to intl_fmp.curr_symbol() == "RUR ". (see reference in comments
1.720 + * above).
1.721 + *
1.722 + */
1.723 +
1.724 +static void _Init_monetary_formats_int(money_base::pattern& pos_format,
1.725 + money_base::pattern& neg_format,
1.726 + _Locale_monetary * monetary)
1.727 +{
1.728 + pos_format.field[0] = (char) money_base::symbol;
1.729 + // pos_format.field[1] = (char) money_base::space;
1.730 +
1.731 + switch (_Locale_p_sign_posn(monetary)) {
1.732 + case 0: // Parentheses surround the quantity and currency_symbol
1.733 + case 1: // The sign string precedes the quantity and currency_symbol
1.734 + pos_format.field[1] = (char) money_base::sign;
1.735 + pos_format.field[2] = (char) money_base::value;
1.736 + break;
1.737 + case 2: // The sign string succeeds the quantity and currency_symbol.
1.738 + pos_format.field[1] = (char) money_base::value;
1.739 + pos_format.field[2] = (char) money_base::sign;
1.740 + break;
1.741 + case 3: // The sign string immediately precedes the currency_symbol.
1.742 + case 4: // The sign string immediately succeeds the currency_symbol.
1.743 + default:
1.744 + if (_Locale_p_cs_precedes(monetary)) {
1.745 + // 1 if currency_symbol precedes a positive value
1.746 + pos_format.field[1] = (char) money_base::sign;
1.747 + pos_format.field[2] = (char) money_base::value;
1.748 + } else {
1.749 + // 0 if currency_symbol succeeds a positive value
1.750 + pos_format.field[1] = (char) money_base::value;
1.751 + pos_format.field[2] = (char) money_base::sign;
1.752 + }
1.753 + break;
1.754 + }
1.755 + pos_format.field[3] = (char) money_base::none;
1.756 +
1.757 + neg_format.field[0] = (char) money_base::symbol;
1.758 + // neg_format.field[1] = (char) money_base::space;
1.759 +
1.760 + switch (_Locale_n_sign_posn(monetary)) {
1.761 + case 0: // Parentheses surround the quantity and currency_symbol
1.762 + case 1: // The sign string precedes the quantity and currency_symbol
1.763 + neg_format.field[1] = (char) money_base::sign;
1.764 + neg_format.field[2] = (char) money_base::value;
1.765 + break;
1.766 + case 2: // The sign string succeeds the quantity and currency_symbol.
1.767 + neg_format.field[1] = (char) money_base::value;
1.768 + neg_format.field[2] = (char) money_base::sign;
1.769 + break;
1.770 + case 3: // The sign string immediately precedes the currency_symbol.
1.771 + case 4: // The sign string immediately succeeds the currency_symbol.
1.772 + default:
1.773 + if (_Locale_n_cs_precedes(monetary)) {
1.774 + // 1 if currency_symbol precedes a negative value
1.775 + neg_format.field[1] = (char) money_base::sign;
1.776 + neg_format.field[2] = (char) money_base::value;
1.777 + } else {
1.778 + // 0 if currency_symbol succeeds a negative value
1.779 + neg_format.field[1] = (char) money_base::value;
1.780 + neg_format.field[2] = (char) money_base::sign;
1.781 + }
1.782 + break;
1.783 + }
1.784 + neg_format.field[3] = (char) money_base::none;
1.785 +}
1.786 +
1.787 +_STLP_MOVE_TO_STD_NAMESPACE
1.788 +
1.789 +//
1.790 +// moneypunct_byname<>
1.791 +//
1.792 +_STLP_DECLSPEC moneypunct_byname<char, true>::moneypunct_byname(const char * name,
1.793 + size_t refs, _Locale_name_hint* hint):
1.794 + moneypunct<char, true>(refs), _M_monetary(_STLP_PRIV __acquire_monetary(name, hint)) {
1.795 + if (!_M_monetary)
1.796 + locale::_M_throw_runtime_error();
1.797 + _STLP_PRIV _Init_monetary_formats_int(_M_pos_format, _M_neg_format, _M_monetary);
1.798 +}
1.799 +
1.800 +_STLP_DECLSPEC moneypunct_byname<char, true>::~moneypunct_byname()
1.801 +{ _STLP_PRIV __release_monetary(_M_monetary); }
1.802 +
1.803 +_STLP_DECLSPEC char moneypunct_byname<char, true>::do_decimal_point() const
1.804 +{ return _Locale_mon_decimal_point(_M_monetary); }
1.805 +
1.806 +_STLP_DECLSPEC char moneypunct_byname<char, true>::do_thousands_sep() const
1.807 +{ return _Locale_mon_thousands_sep(_M_monetary); }
1.808 +
1.809 +_STLP_DECLSPEC string moneypunct_byname<char, true>::do_grouping() const
1.810 +{ return _Locale_mon_grouping(_M_monetary); }
1.811 +
1.812 +_STLP_DECLSPEC string moneypunct_byname<char, true>::do_curr_symbol() const
1.813 +{ return _Locale_int_curr_symbol(_M_monetary); }
1.814 +
1.815 +_STLP_DECLSPEC string moneypunct_byname<char, true>::do_positive_sign() const
1.816 +{ return _Locale_positive_sign(_M_monetary); }
1.817 +
1.818 +_STLP_DECLSPEC string moneypunct_byname<char, true>::do_negative_sign() const
1.819 +{ return _Locale_negative_sign(_M_monetary); }
1.820 +
1.821 +_STLP_DECLSPEC int moneypunct_byname<char, true>::do_frac_digits() const
1.822 +{ return _Locale_int_frac_digits(_M_monetary); }
1.823 +
1.824 +_STLP_DECLSPEC moneypunct_byname<char, false>::moneypunct_byname(const char * name,
1.825 + size_t refs, _Locale_name_hint* hint):
1.826 + moneypunct<char, false>(refs), _M_monetary(_STLP_PRIV __acquire_monetary(name, hint)) {
1.827 + if (!_M_monetary)
1.828 + locale::_M_throw_runtime_error();
1.829 + _STLP_PRIV _Init_monetary_formats(_M_pos_format, _M_neg_format, _M_monetary);
1.830 +}
1.831 +
1.832 +_STLP_DECLSPEC moneypunct_byname<char, false>::~moneypunct_byname()
1.833 +{ _STLP_PRIV __release_monetary(_M_monetary); }
1.834 +
1.835 +_STLP_DECLSPEC char moneypunct_byname<char, false>::do_decimal_point() const
1.836 +{ return _Locale_mon_decimal_point(_M_monetary); }
1.837 +
1.838 +_STLP_DECLSPEC char moneypunct_byname<char, false>::do_thousands_sep() const
1.839 +{ return _Locale_mon_thousands_sep(_M_monetary); }
1.840 +
1.841 +_STLP_DECLSPEC string moneypunct_byname<char, false>::do_grouping() const
1.842 +{ return _Locale_mon_grouping(_M_monetary); }
1.843 +
1.844 +_STLP_DECLSPEC string moneypunct_byname<char, false>::do_curr_symbol() const
1.845 +{ return _Locale_currency_symbol(_M_monetary); }
1.846 +
1.847 +_STLP_DECLSPEC string moneypunct_byname<char, false>::do_positive_sign() const
1.848 +{ return _Locale_positive_sign(_M_monetary); }
1.849 +
1.850 +_STLP_DECLSPEC string moneypunct_byname<char, false>::do_negative_sign() const
1.851 +{ return _Locale_negative_sign(_M_monetary); }
1.852 +
1.853 +_STLP_DECLSPEC int moneypunct_byname<char, false>::do_frac_digits() const
1.854 +{ return _Locale_frac_digits(_M_monetary); }
1.855 +
1.856 +//
1.857 +// moneypunct_byname<wchar_t>
1.858 +//
1.859 +#if !defined (_STLP_NO_WCHAR_T)
1.860 +
1.861 +_STLP_DECLSPEC moneypunct_byname<wchar_t, true>::moneypunct_byname(const char * name,
1.862 + size_t refs, _Locale_name_hint* hint):
1.863 + moneypunct<wchar_t, true>(refs), _M_monetary(_STLP_PRIV __acquire_monetary(name, hint)) {
1.864 + if (!_M_monetary)
1.865 + locale::_M_throw_runtime_error();
1.866 + _STLP_PRIV _Init_monetary_formats_int(_M_pos_format, _M_neg_format, _M_monetary);
1.867 +}
1.868 +
1.869 +_STLP_DECLSPEC moneypunct_byname<wchar_t, true>::~moneypunct_byname()
1.870 +{ _STLP_PRIV __release_monetary(_M_monetary); }
1.871 +
1.872 +_STLP_DECLSPEC wchar_t moneypunct_byname<wchar_t, true>::do_decimal_point() const
1.873 +{ return _Locale_mon_decimal_point(_M_monetary); }
1.874 +
1.875 +_STLP_DECLSPEC wchar_t moneypunct_byname<wchar_t, true>::do_thousands_sep() const
1.876 +{ return _Locale_mon_thousands_sep(_M_monetary); }
1.877 +
1.878 +_STLP_DECLSPEC string moneypunct_byname<wchar_t, true>::do_grouping() const
1.879 +{ return _Locale_mon_grouping(_M_monetary); }
1.880 +
1.881 +inline wstring __do_widen (string const& str) {
1.882 +#if defined (_STLP_NO_MEMBER_TEMPLATES) || defined (_STLP_MSVC) || defined(__MRC__) || defined(__SC__) //*ty 05/26/2001 - added workaround for mpw
1.883 + wstring::_Reserve_t __Reserve;
1.884 + size_t __size = str.size();
1.885 + wstring result(__Reserve, __size);
1.886 + copy(str.begin(), str.end(), result.begin());
1.887 +#else
1.888 + wstring result(str.begin(), str.end());
1.889 +#endif
1.890 + return result;
1.891 +}
1.892 +
1.893 +_STLP_DECLSPEC wstring moneypunct_byname<wchar_t, true>::do_curr_symbol() const
1.894 +{ return __do_widen(_Locale_int_curr_symbol(_M_monetary)); }
1.895 +
1.896 +_STLP_DECLSPEC wstring moneypunct_byname<wchar_t, true>::do_positive_sign() const
1.897 +{ return __do_widen(_Locale_positive_sign(_M_monetary)); }
1.898 +
1.899 +_STLP_DECLSPEC wstring moneypunct_byname<wchar_t, true>::do_negative_sign() const
1.900 +{ return __do_widen(_Locale_negative_sign(_M_monetary)); }
1.901 +
1.902 +_STLP_DECLSPEC int moneypunct_byname<wchar_t, true>::do_frac_digits() const
1.903 +{ return _Locale_int_frac_digits(_M_monetary); }
1.904 +
1.905 +_STLP_DECLSPEC moneypunct_byname<wchar_t, false>::moneypunct_byname(const char * name,
1.906 + size_t refs, _Locale_name_hint* hint):
1.907 + moneypunct<wchar_t, false>(refs), _M_monetary(_STLP_PRIV __acquire_monetary(name, hint)) {
1.908 + if (!_M_monetary)
1.909 + locale::_M_throw_runtime_error() ;
1.910 + _STLP_PRIV _Init_monetary_formats(_M_pos_format, _M_neg_format, _M_monetary);
1.911 +}
1.912 +
1.913 +_STLP_DECLSPEC moneypunct_byname<wchar_t, false>::~moneypunct_byname()
1.914 +{ _STLP_PRIV __release_monetary(_M_monetary); }
1.915 +
1.916 +_STLP_DECLSPEC wchar_t moneypunct_byname<wchar_t, false>::do_decimal_point() const
1.917 +{ return _Locale_mon_decimal_point(_M_monetary); }
1.918 +
1.919 +_STLP_DECLSPEC wchar_t moneypunct_byname<wchar_t, false>::do_thousands_sep() const
1.920 +{ return _Locale_mon_thousands_sep(_M_monetary); }
1.921 +
1.922 +_STLP_DECLSPEC string moneypunct_byname<wchar_t, false>::do_grouping() const
1.923 +{ return _Locale_mon_grouping(_M_monetary); }
1.924 +
1.925 +_STLP_DECLSPEC wstring moneypunct_byname<wchar_t, false>::do_curr_symbol() const
1.926 +{ return __do_widen(_Locale_currency_symbol(_M_monetary)); }
1.927 +
1.928 +_STLP_DECLSPEC wstring moneypunct_byname<wchar_t, false>::do_positive_sign() const
1.929 +{ return __do_widen(_Locale_positive_sign(_M_monetary)); }
1.930 +
1.931 +_STLP_DECLSPEC wstring moneypunct_byname<wchar_t, false>::do_negative_sign() const
1.932 +{ return __do_widen(_Locale_negative_sign(_M_monetary)); }
1.933 +
1.934 +_STLP_DECLSPEC int moneypunct_byname<wchar_t, false>::do_frac_digits() const
1.935 +{ return _Locale_frac_digits(_M_monetary); }
1.936 +
1.937 +#endif
1.938 +
1.939 +_STLP_END_NAMESPACE
1.940 +
1.941 +#include "message_facets.h"
1.942 +
1.943 +_STLP_BEGIN_NAMESPACE
1.944 +
1.945 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.946 +
1.947 +void _Catalog_locale_map::insert(nl_catd_type key, const locale& L) {
1.948 + _STLP_TRY {
1.949 +#if !defined(_STLP_NO_TYPEINFO) && !defined(_STLP_NO_RTTI)
1.950 + // Don't bother to do anything unless we're using a non-default ctype facet
1.951 +# ifdef _STLP_NO_WCHAR_T
1.952 + typedef char _Char;
1.953 +# else
1.954 + typedef wchar_t _Char;
1.955 +# endif
1.956 +
1.957 + typedef ctype<_Char> wctype;
1.958 + wctype const& wct = use_facet<wctype>(L);
1.959 + if (typeid(wct) != typeid(wctype)) {
1.960 +# endif /* _STLP_NO_TYPEINFO */
1.961 + if (!M)
1.962 + M = new map_type;
1.963 +
1.964 +#if defined (__SC__)
1.965 + if (!M) delete M;
1.966 +#endif
1.967 + M->insert(map_type::value_type(key, L));
1.968 +#if !defined(_STLP_NO_TYPEINFO) && !defined(_STLP_NO_RTTI)
1.969 + }
1.970 +# endif /* _STLP_NO_TYPEINFO */
1.971 + }
1.972 + _STLP_CATCH_ALL {}
1.973 +}
1.974 +
1.975 +void _Catalog_locale_map::erase(nl_catd_type key) {
1.976 + if (M)
1.977 + M->erase(key);
1.978 +}
1.979 +
1.980 +locale _Catalog_locale_map::lookup(nl_catd_type key) const {
1.981 + if (M) {
1.982 + map_type::const_iterator i = M->find(key);
1.983 + return i != M->end() ? (*i).second : locale::classic();
1.984 + }
1.985 + else
1.986 + return locale::classic();
1.987 +}
1.988 +
1.989 +
1.990 +#if defined (_STLP_USE_NL_CATD_MAPPING)
1.991 +_STLP_VOLATILE __stl_atomic_t _Catalog_nl_catd_map::_count = 0;
1.992 +
1.993 +messages_base::catalog _Catalog_nl_catd_map::insert(nl_catd_type cat) {
1.994 + messages_base::catalog &res = Mr[cat];
1.995 + if ( res == 0 ) {
1.996 +#if defined (_STLP_ATOMIC_INCREMENT)
1.997 + res = __STATIC_CAST(int, _STLP_ATOMIC_INCREMENT(&_count));
1.998 +#else
1.999 + static _STLP_STATIC_MUTEX _Count_lock _STLP_MUTEX_INITIALIZER;
1.1000 + {
1.1001 + _STLP_auto_lock sentry(_Count_lock);
1.1002 + res = __STATIC_CAST(int, ++_count);
1.1003 + }
1.1004 +#endif
1.1005 + M[res] = cat;
1.1006 + }
1.1007 + return res;
1.1008 +}
1.1009 +
1.1010 +void _Catalog_nl_catd_map::erase(messages_base::catalog cat) {
1.1011 + map_type::iterator mit(M.find(cat));
1.1012 + if (mit != M.end()) {
1.1013 + Mr.erase((*mit).second);
1.1014 + M.erase(mit);
1.1015 + }
1.1016 +}
1.1017 +#endif
1.1018 +
1.1019 +//----------------------------------------------------------------------
1.1020 +//
1.1021 +//
1.1022 +
1.1023 +_Messages_impl::_Messages_impl(bool is_wide, _Locale_name_hint* hint) :
1.1024 + _M_message_obj(0), _M_map(0) {
1.1025 + _M_delete = true;
1.1026 + if (is_wide)
1.1027 + _M_map = new _Catalog_locale_map;
1.1028 + _M_message_obj = __acquire_messages("C", hint);
1.1029 +}
1.1030 +
1.1031 +_Messages_impl::_Messages_impl(bool is_wide, _Locale_messages* msg_obj ) :
1.1032 + _M_message_obj(msg_obj), _M_map(0) {
1.1033 + _M_delete = true;
1.1034 + if (is_wide)
1.1035 + _M_map = new _Catalog_locale_map;
1.1036 +}
1.1037 +
1.1038 +_Messages_impl::~_Messages_impl() {
1.1039 + __release_messages(_M_message_obj);
1.1040 + if (_M_map) delete _M_map;
1.1041 +}
1.1042 +
1.1043 +_Messages::catalog _Messages_impl::do_open(const string& filename, const locale& L) const {
1.1044 + nl_catd_type result = _M_message_obj ? _Locale_catopen(_M_message_obj, filename.c_str())
1.1045 + : (nl_catd_type)(-1);
1.1046 +
1.1047 + if ( result != (nl_catd_type)(-1) ) {
1.1048 + if ( _M_map != 0 ) {
1.1049 + _M_map->insert(result, L);
1.1050 + }
1.1051 + return _M_cat.insert( result );
1.1052 + }
1.1053 +
1.1054 + return -1;
1.1055 +}
1.1056 +
1.1057 +string _Messages_impl::do_get(catalog cat,
1.1058 + int set, int p_id, const string& dfault) const {
1.1059 + return _M_message_obj != 0 && cat >= 0
1.1060 + ? string(_Locale_catgets(_M_message_obj, _M_cat[cat], set, p_id, dfault.c_str()))
1.1061 + : dfault;
1.1062 +}
1.1063 +
1.1064 +#if !defined (_STLP_NO_WCHAR_T)
1.1065 +
1.1066 +wstring
1.1067 +_Messages_impl::do_get(catalog thecat,
1.1068 + int set, int p_id, const wstring& dfault) const {
1.1069 + typedef ctype<wchar_t> wctype;
1.1070 + const wctype& ct = use_facet<wctype>(_M_map->lookup( _M_cat[thecat] ) );
1.1071 +
1.1072 + const char* str = _Locale_catgets(_M_message_obj, _M_cat[thecat], set, p_id, "");
1.1073 +
1.1074 + // Verify that the lookup failed; an empty string might represent success.
1.1075 + if (!str)
1.1076 + return dfault;
1.1077 + else if (str[0] == '\0') {
1.1078 + const char* str2 = _Locale_catgets(_M_message_obj, _M_cat[thecat], set, p_id, "*");
1.1079 + if (!str2 || ((str2[0] == '*') && (str2[1] == '\0')))
1.1080 + return dfault;
1.1081 + }
1.1082 +
1.1083 + // str is correct. Now we must widen it to get a wstring.
1.1084 + size_t n = strlen(str);
1.1085 +
1.1086 + // NOT PORTABLE. What we're doing relies on internal details of the
1.1087 + // string implementation. (Contiguity of string elements.)
1.1088 + wstring result(n, wchar_t(0));
1.1089 + ct.widen(str, str + n, &*result.begin());
1.1090 + return result;
1.1091 +}
1.1092 +
1.1093 +#endif
1.1094 +
1.1095 +void _Messages_impl::do_close(catalog thecat) const {
1.1096 + if (_M_message_obj)
1.1097 + _Locale_catclose(_M_message_obj, _M_cat[thecat]);
1.1098 + if (_M_map) _M_map->erase(_M_cat[thecat]);
1.1099 + _M_cat.erase( thecat );
1.1100 +}
1.1101 +
1.1102 +_STLP_MOVE_TO_STD_NAMESPACE
1.1103 +
1.1104 +//----------------------------------------------------------------------
1.1105 +// messages<char>
1.1106 +
1.1107 +_STLP_DECLSPEC messages<char>::messages(size_t refs) :
1.1108 + locale::facet(refs), _M_impl(new _STLP_PRIV _Messages_impl(false)) {}
1.1109 +
1.1110 +_STLP_DECLSPEC messages<char>::messages(size_t refs, _Locale_messages* msg_obj) : locale::facet(refs),
1.1111 + _M_impl(new _STLP_PRIV _Messages_impl(false, msg_obj)) {}
1.1112 +
1.1113 +
1.1114 +//----------------------------------------------------------------------
1.1115 +// messages_byname<char>
1.1116 +
1.1117 +_STLP_DECLSPEC messages_byname<char>::messages_byname(const char* name, size_t refs, _Locale_name_hint* hint)
1.1118 + : messages<char>(refs, name ? _STLP_PRIV __acquire_messages(name, hint) : 0) {}
1.1119 +
1.1120 +_STLP_DECLSPEC messages_byname<char>::~messages_byname() {}
1.1121 +
1.1122 +#if !defined (_STLP_NO_WCHAR_T)
1.1123 +
1.1124 +//----------------------------------------------------------------------
1.1125 +// messages<wchar_t>
1.1126 +
1.1127 +_STLP_DECLSPEC messages<wchar_t>::messages(size_t refs) :
1.1128 + locale::facet(refs), _M_impl(new _STLP_PRIV _Messages_impl(true)) {}
1.1129 +
1.1130 +_STLP_DECLSPEC messages<wchar_t>::messages(size_t refs, _Locale_messages* msg_obj)
1.1131 + : locale::facet(refs),
1.1132 + _M_impl(new _STLP_PRIV _Messages_impl(true, msg_obj)) {}
1.1133 +
1.1134 +//----------------------------------------------------------------------
1.1135 +// messages_byname<wchar_t>
1.1136 +
1.1137 +
1.1138 +_STLP_DECLSPEC messages_byname<wchar_t>::messages_byname(const char* name, size_t refs, _Locale_name_hint* hint)
1.1139 + : messages<wchar_t>(refs, name ? _STLP_PRIV __acquire_messages(name, hint) : 0) {}
1.1140 +
1.1141 +_STLP_DECLSPEC messages_byname<wchar_t>::~messages_byname() {}
1.1142 +
1.1143 +#endif
1.1144 +
1.1145 +_STLP_END_NAMESPACE
1.1146 +