build/stlport/src/facets_byname.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 <hash_map>
michael@0 21 #include <vector>
michael@0 22
michael@0 23 #include <locale>
michael@0 24 #include <istream>
michael@0 25
michael@0 26 #include <algorithm>
michael@0 27 #include <functional>
michael@0 28
michael@0 29 #include "c_locale.h"
michael@0 30 #include "locale_impl.h"
michael@0 31 #include "acquire_release.h"
michael@0 32
michael@0 33 _STLP_BEGIN_NAMESPACE
michael@0 34
michael@0 35 //----------------------------------------------------------------------
michael@0 36 // ctype_byname<char>
michael@0 37
michael@0 38 #if defined (__DMC__)
michael@0 39 _STLP_DECLSPEC
michael@0 40 #endif
michael@0 41 ctype_byname<char>::ctype_byname(const char* name, size_t refs)
michael@0 42 : ctype<char>( 0, false, refs) {
michael@0 43 if (!name)
michael@0 44 locale::_M_throw_on_null_name();
michael@0 45
michael@0 46 int __err_code;
michael@0 47 char buf[_Locale_MAX_SIMPLE_NAME];
michael@0 48 _M_ctype = _STLP_PRIV __acquire_ctype(name, buf, 0, &__err_code);
michael@0 49 if (!_M_ctype)
michael@0 50 locale::_M_throw_on_creation_failure(__err_code, name, "ctype");
michael@0 51
michael@0 52 _M_init();
michael@0 53 }
michael@0 54
michael@0 55 void ctype_byname<char>::_M_init() {
michael@0 56 _M_ctype_table = _M_byname_table;
michael@0 57
michael@0 58 // We have to do this, instead of just pointer twiddling, because
michael@0 59 // ctype_base::mask isn't the same type as _Locale_mask_t.
michael@0 60 const _Locale_mask_t* p = _Locale_ctype_table(_M_ctype);
michael@0 61 for (size_t i = 0; i != table_size; ++i) {
michael@0 62 _M_byname_table[i] = ctype_base::mask(p[i]);
michael@0 63 }
michael@0 64 }
michael@0 65
michael@0 66 ctype_byname<char>::~ctype_byname()
michael@0 67 { _STLP_PRIV __release_ctype(_M_ctype); }
michael@0 68
michael@0 69 char ctype_byname<char>::do_toupper(char c) const
michael@0 70 { return (char)_Locale_toupper(_M_ctype, c); }
michael@0 71
michael@0 72 char ctype_byname<char>::do_tolower(char c) const
michael@0 73 { return (char)_Locale_tolower(_M_ctype, c); }
michael@0 74
michael@0 75 const char*
michael@0 76 ctype_byname<char>::do_toupper(char* first, const char* last) const {
michael@0 77 for ( ; first != last ; ++first)
michael@0 78 *first = (char)_Locale_toupper(_M_ctype, *first);
michael@0 79 return last;
michael@0 80 }
michael@0 81
michael@0 82 const char*
michael@0 83 ctype_byname<char>::do_tolower(char* first, const char* last) const {
michael@0 84 for ( ; first != last ; ++first)
michael@0 85 *first = (char)_Locale_tolower(_M_ctype, *first);
michael@0 86 return last;
michael@0 87 }
michael@0 88
michael@0 89
michael@0 90 // Some helper functions used in ctype<>::scan_is and scan_is_not.
michael@0 91 #if !defined (_STLP_NO_WCHAR_T)
michael@0 92
michael@0 93 _STLP_MOVE_TO_PRIV_NAMESPACE
michael@0 94
michael@0 95 // ctype_byname<wchar_t>
michael@0 96
michael@0 97 struct _Ctype_byname_w_is_mask : public unary_function<wchar_t, bool> {
michael@0 98 _Locale_mask_t M;
michael@0 99 _Locale_ctype* M_ctp;
michael@0 100
michael@0 101 _Ctype_byname_w_is_mask(_Locale_mask_t m, _Locale_ctype* c)
michael@0 102 : M(m), M_ctp(c) {}
michael@0 103 bool operator()(wchar_t c) const
michael@0 104 { return _WLocale_ctype(M_ctp, c, M) != 0; }
michael@0 105 };
michael@0 106
michael@0 107 _STLP_MOVE_TO_STD_NAMESPACE
michael@0 108
michael@0 109 #if defined (__DMC__)
michael@0 110 _STLP_DECLSPEC
michael@0 111 #endif
michael@0 112 ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs)
michael@0 113 : ctype<wchar_t>(refs) {
michael@0 114 if (!name)
michael@0 115 locale::_M_throw_on_null_name();
michael@0 116
michael@0 117 int __err_code;
michael@0 118 char buf[_Locale_MAX_SIMPLE_NAME];
michael@0 119 _M_ctype = _STLP_PRIV __acquire_ctype(name, buf, 0, &__err_code);
michael@0 120 if (!_M_ctype)
michael@0 121 locale::_M_throw_on_creation_failure(__err_code, name, "ctype");
michael@0 122 }
michael@0 123
michael@0 124 ctype_byname<wchar_t>::~ctype_byname()
michael@0 125 { _STLP_PRIV __release_ctype(_M_ctype); }
michael@0 126
michael@0 127 bool ctype_byname<wchar_t>::do_is(ctype_base::mask m, wchar_t c) const
michael@0 128 { return _WLocale_ctype(_M_ctype, c, (_Locale_mask_t)m) != 0; }
michael@0 129
michael@0 130 const wchar_t*
michael@0 131 ctype_byname<wchar_t>::do_is(const wchar_t* low, const wchar_t* high,
michael@0 132 ctype_base::mask * m) const {
michael@0 133 _Locale_mask_t all_bits = _Locale_mask_t(ctype_base::space |
michael@0 134 ctype_base::print |
michael@0 135 ctype_base::cntrl |
michael@0 136 ctype_base::upper |
michael@0 137 ctype_base::lower |
michael@0 138 ctype_base::alpha |
michael@0 139 ctype_base::digit |
michael@0 140 ctype_base::punct |
michael@0 141 ctype_base::xdigit);
michael@0 142
michael@0 143 for ( ; low < high; ++low, ++m)
michael@0 144 *m = ctype_base::mask (_WLocale_ctype(_M_ctype, *low, all_bits));
michael@0 145 return high;
michael@0 146 }
michael@0 147
michael@0 148 const wchar_t*
michael@0 149 ctype_byname<wchar_t>
michael@0 150 ::do_scan_is(ctype_base::mask m, const wchar_t* low, const wchar_t* high) const
michael@0 151 { return find_if(low, high, _STLP_PRIV _Ctype_byname_w_is_mask(m, _M_ctype)); }
michael@0 152
michael@0 153 const wchar_t*
michael@0 154 ctype_byname<wchar_t>
michael@0 155 ::do_scan_not(ctype_base::mask m, const wchar_t* low, const wchar_t* high) const
michael@0 156 { return find_if(low, high, not1(_STLP_PRIV _Ctype_byname_w_is_mask(m, _M_ctype))); }
michael@0 157
michael@0 158 wchar_t ctype_byname<wchar_t>::do_toupper(wchar_t c) const
michael@0 159 { return _WLocale_toupper(_M_ctype, c); }
michael@0 160
michael@0 161 const wchar_t*
michael@0 162 ctype_byname<wchar_t>::do_toupper(wchar_t* low, const wchar_t* high) const {
michael@0 163 for ( ; low < high; ++low)
michael@0 164 *low = _WLocale_toupper(_M_ctype, *low);
michael@0 165 return high;
michael@0 166 }
michael@0 167
michael@0 168 wchar_t ctype_byname<wchar_t>::do_tolower(wchar_t c) const
michael@0 169 { return _WLocale_tolower(_M_ctype, c); }
michael@0 170
michael@0 171 const wchar_t*
michael@0 172 ctype_byname<wchar_t>::do_tolower(wchar_t* low, const wchar_t* high) const {
michael@0 173 for ( ; low < high; ++low)
michael@0 174 *low = _WLocale_tolower(_M_ctype, *low);
michael@0 175 return high;
michael@0 176 }
michael@0 177
michael@0 178 #endif /* WCHAR_T */
michael@0 179
michael@0 180 // collate_byname<char>
michael@0 181 #if defined (__DMC__)
michael@0 182 _STLP_DECLSPEC
michael@0 183 #endif
michael@0 184 collate_byname<char>::collate_byname(const char* name, size_t refs)
michael@0 185 : collate<char>(refs) {
michael@0 186 if (!name)
michael@0 187 locale::_M_throw_on_null_name();
michael@0 188
michael@0 189 int __err_code;
michael@0 190 char buf[_Locale_MAX_SIMPLE_NAME];
michael@0 191 _M_collate = _STLP_PRIV __acquire_collate(name, buf, 0, &__err_code);
michael@0 192 if (!_M_collate)
michael@0 193 locale::_M_throw_on_creation_failure(__err_code, name, "collate");
michael@0 194 }
michael@0 195
michael@0 196 collate_byname<char>::~collate_byname()
michael@0 197 { _STLP_PRIV __release_collate(_M_collate); }
michael@0 198
michael@0 199 int collate_byname<char>::do_compare(const char* __low1,
michael@0 200 const char* __high1,
michael@0 201 const char* __low2,
michael@0 202 const char* __high2) const {
michael@0 203 return _Locale_strcmp(_M_collate,
michael@0 204 __low1, __high1 - __low1,
michael@0 205 __low2, __high2 - __low2);
michael@0 206 }
michael@0 207
michael@0 208 collate_byname<char>::string_type
michael@0 209 collate_byname<char>::do_transform(const char* low, const char* high) const {
michael@0 210 if (low == high)
michael@0 211 return string_type();
michael@0 212
michael@0 213 size_t n = _Locale_strxfrm(_M_collate, NULL, 0, low, high - low);
michael@0 214
michael@0 215 // NOT PORTABLE. What we're doing relies on internal details of the
michael@0 216 // string implementation. (Contiguity of string elements and presence
michael@0 217 // of trailing zero.)
michael@0 218 string_type buf(n, 0);
michael@0 219 _Locale_strxfrm(_M_collate, &(*buf.begin()), n + 1, low, high - low);
michael@0 220 return buf;
michael@0 221 }
michael@0 222
michael@0 223
michael@0 224 #if !defined (_STLP_NO_WCHAR_T)
michael@0 225
michael@0 226 // collate_byname<wchar_t>
michael@0 227
michael@0 228 #if defined (__DMC__)
michael@0 229 _STLP_DECLSPEC
michael@0 230 #endif
michael@0 231 collate_byname<wchar_t>::collate_byname(const char* name, size_t refs)
michael@0 232 : collate<wchar_t>(refs) {
michael@0 233 if (!name)
michael@0 234 locale::_M_throw_on_null_name();
michael@0 235
michael@0 236 int __err_code;
michael@0 237 char buf[_Locale_MAX_SIMPLE_NAME];
michael@0 238 _M_collate = _STLP_PRIV __acquire_collate(name, buf, 0, &__err_code);
michael@0 239 if (!_M_collate)
michael@0 240 locale::_M_throw_on_creation_failure(__err_code, name, "collate");
michael@0 241 }
michael@0 242
michael@0 243 collate_byname<wchar_t>::~collate_byname()
michael@0 244 { _STLP_PRIV __release_collate(_M_collate); }
michael@0 245
michael@0 246 int collate_byname<wchar_t>::do_compare(const wchar_t* low1,
michael@0 247 const wchar_t* high1,
michael@0 248 const wchar_t* low2,
michael@0 249 const wchar_t* high2) const {
michael@0 250 return _WLocale_strcmp(_M_collate,
michael@0 251 low1, high1 - low1,
michael@0 252 low2, high2 - low2);
michael@0 253 }
michael@0 254
michael@0 255 collate_byname<wchar_t>::string_type
michael@0 256 collate_byname<wchar_t>::do_transform(const wchar_t* low,
michael@0 257 const wchar_t* high) const {
michael@0 258 if (low == high)
michael@0 259 return string_type();
michael@0 260
michael@0 261 size_t n = _WLocale_strxfrm(_M_collate, NULL, 0, low, high - low);
michael@0 262
michael@0 263 // NOT PORTABLE. What we're doing relies on internal details of the
michael@0 264 // string implementation. (Contiguity of string elements and presence
michael@0 265 // of trailing zero.)
michael@0 266 string_type buf(n, 0);
michael@0 267 _WLocale_strxfrm(_M_collate, &(*buf.begin()), n + 1, low, high - low);
michael@0 268 return buf;
michael@0 269 }
michael@0 270
michael@0 271 #endif /* _STLP_NO_WCHAR_T */
michael@0 272
michael@0 273 //----------------------------------------------------------------------
michael@0 274 // codecvt_byname<char>
michael@0 275
michael@0 276 codecvt_byname<char, char, mbstate_t>
michael@0 277 ::codecvt_byname(const char* name, size_t refs)
michael@0 278 : codecvt<char, char, mbstate_t>(refs) {
michael@0 279 if (!name)
michael@0 280 locale::_M_throw_on_null_name();
michael@0 281 }
michael@0 282
michael@0 283 codecvt_byname<char, char, mbstate_t>::~codecvt_byname() {}
michael@0 284
michael@0 285
michael@0 286 #if !defined (_STLP_NO_WCHAR_T)
michael@0 287
michael@0 288 //----------------------------------------------------------------------
michael@0 289 // codecvt_byname<wchar_t>
michael@0 290 codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname(const char* name, size_t refs)
michael@0 291 : codecvt<wchar_t, char, mbstate_t>(refs) {
michael@0 292 if (!name)
michael@0 293 locale::_M_throw_on_null_name();
michael@0 294
michael@0 295 int __err_code;
michael@0 296 char buf[_Locale_MAX_SIMPLE_NAME];
michael@0 297 _M_codecvt = _STLP_PRIV __acquire_codecvt(name, buf, 0, &__err_code);
michael@0 298 if (!_M_codecvt)
michael@0 299 locale::_M_throw_on_creation_failure(__err_code, name, "ctype");
michael@0 300 }
michael@0 301
michael@0 302 codecvt_byname<wchar_t, char, mbstate_t>::~codecvt_byname()
michael@0 303 { _STLP_PRIV __release_codecvt(_M_codecvt); }
michael@0 304
michael@0 305 codecvt<wchar_t, char, mbstate_t>::result
michael@0 306 codecvt_byname<wchar_t, char, mbstate_t>::do_out(state_type& state,
michael@0 307 const intern_type* from,
michael@0 308 const intern_type* from_end,
michael@0 309 const intern_type*& from_next,
michael@0 310 extern_type* to,
michael@0 311 extern_type* to_limit,
michael@0 312 extern_type*& to_next) const {
michael@0 313 while (from != from_end && to != to_limit) {
michael@0 314 size_t chars_stored = _WLocale_wctomb(_M_codecvt,
michael@0 315 to, to_limit - to, *from,
michael@0 316 &state);
michael@0 317 if (chars_stored == (size_t) -1) {
michael@0 318 from_next = from;
michael@0 319 to_next = to;
michael@0 320 return error;
michael@0 321 }
michael@0 322 else if (chars_stored == (size_t) -2) {
michael@0 323 from_next = from;
michael@0 324 to_next = to;
michael@0 325 return partial;
michael@0 326 }
michael@0 327
michael@0 328 ++from;
michael@0 329 to += chars_stored;
michael@0 330 }
michael@0 331
michael@0 332 from_next = from;
michael@0 333 to_next = to;
michael@0 334 return ok;
michael@0 335 }
michael@0 336
michael@0 337 codecvt<wchar_t, char, mbstate_t>::result
michael@0 338 codecvt_byname<wchar_t, char, mbstate_t>::do_in(state_type& state,
michael@0 339 const extern_type* from,
michael@0 340 const extern_type* from_end,
michael@0 341 const extern_type*& from_next,
michael@0 342 intern_type* to,
michael@0 343 intern_type* to_end,
michael@0 344 intern_type*& to_next) const {
michael@0 345 while (from != from_end && to != to_end) {
michael@0 346 size_t chars_read = _WLocale_mbtowc(_M_codecvt,
michael@0 347 to, from, from_end - from,
michael@0 348 &state);
michael@0 349 if (chars_read == (size_t) -1) {
michael@0 350 from_next = from;
michael@0 351 to_next = to;
michael@0 352 return error;
michael@0 353 }
michael@0 354
michael@0 355 if (chars_read == (size_t) -2) {
michael@0 356 from_next = from;
michael@0 357 to_next = to;
michael@0 358 return partial;
michael@0 359 }
michael@0 360
michael@0 361 from += chars_read;
michael@0 362 to++;
michael@0 363 }
michael@0 364
michael@0 365 from_next = from;
michael@0 366 to_next = to;
michael@0 367 return ok;
michael@0 368 }
michael@0 369
michael@0 370 codecvt<wchar_t, char, mbstate_t>::result
michael@0 371 codecvt_byname<wchar_t, char, mbstate_t>::do_unshift(state_type& state,
michael@0 372 extern_type* to,
michael@0 373 extern_type* to_limit,
michael@0 374 extern_type*& to_next) const {
michael@0 375 to_next = to;
michael@0 376 size_t result = _WLocale_unshift(_M_codecvt, &state,
michael@0 377 to, to_limit - to, &to_next);
michael@0 378 if (result == (size_t) -1)
michael@0 379 return error;
michael@0 380 else if (result == (size_t) -2)
michael@0 381 return partial;
michael@0 382 else
michael@0 383 # if defined (__ISCPP__)
michael@0 384 return /*to_next == to ? noconv :*/ ok;
michael@0 385 # else
michael@0 386 return to_next == to ? noconv : ok;
michael@0 387 # endif
michael@0 388 }
michael@0 389
michael@0 390 int
michael@0 391 codecvt_byname<wchar_t, char, mbstate_t>::do_encoding() const _STLP_NOTHROW {
michael@0 392 if (_WLocale_is_stateless(_M_codecvt)) {
michael@0 393 int max_width = _WLocale_mb_cur_max(_M_codecvt);
michael@0 394 int min_width = _WLocale_mb_cur_min(_M_codecvt);
michael@0 395 return min_width == max_width ? min_width : 0;
michael@0 396 }
michael@0 397 else
michael@0 398 return -1;
michael@0 399 }
michael@0 400
michael@0 401 bool
michael@0 402 codecvt_byname<wchar_t, char, mbstate_t>::do_always_noconv() const _STLP_NOTHROW
michael@0 403 { return false; }
michael@0 404
michael@0 405 int
michael@0 406 codecvt_byname<wchar_t, char, mbstate_t>::do_length(state_type& state,
michael@0 407 const extern_type* from,
michael@0 408 const extern_type* end,
michael@0 409 size_t mx) const {
michael@0 410 size_t __count = 0;
michael@0 411 while (from != end && mx--) {
michael@0 412 intern_type __dummy;
michael@0 413 size_t chars_read = _WLocale_mbtowc(_M_codecvt,
michael@0 414 &__dummy, from, end - from,
michael@0 415 &state);
michael@0 416 if ((chars_read == (size_t) -1) || (chars_read == (size_t) -2)) // error or partial
michael@0 417 break;
michael@0 418 __count += chars_read;
michael@0 419 from += chars_read;
michael@0 420 }
michael@0 421 return int(__count);
michael@0 422 }
michael@0 423
michael@0 424 int
michael@0 425 codecvt_byname<wchar_t, char, mbstate_t>::do_max_length() const _STLP_NOTHROW
michael@0 426 { return _WLocale_mb_cur_max(_M_codecvt); }
michael@0 427 #endif
michael@0 428
michael@0 429 // numpunct_byname<char>
michael@0 430 numpunct_byname<char>::numpunct_byname(const char* name, size_t refs)
michael@0 431 : numpunct<char>(refs) {
michael@0 432 if (!name)
michael@0 433 locale::_M_throw_on_null_name();
michael@0 434
michael@0 435 int __err_code;
michael@0 436 char buf[_Locale_MAX_SIMPLE_NAME];
michael@0 437 _M_numeric = _STLP_PRIV __acquire_numeric(name, buf, 0, &__err_code);
michael@0 438 if (!_M_numeric)
michael@0 439 locale::_M_throw_on_creation_failure(__err_code, name, "numpunct");
michael@0 440 }
michael@0 441
michael@0 442 numpunct_byname<char>::~numpunct_byname()
michael@0 443 { _STLP_PRIV __release_numeric(_M_numeric); }
michael@0 444
michael@0 445 char numpunct_byname<char>::do_decimal_point() const
michael@0 446 { return _Locale_decimal_point(_M_numeric); }
michael@0 447
michael@0 448 char numpunct_byname<char>::do_thousands_sep() const
michael@0 449 { return _Locale_thousands_sep(_M_numeric); }
michael@0 450
michael@0 451 string numpunct_byname<char>::do_grouping() const {
michael@0 452 const char * __grouping = _Locale_grouping(_M_numeric);
michael@0 453 if (__grouping != NULL && __grouping[0] == CHAR_MAX)
michael@0 454 __grouping = "";
michael@0 455 return __grouping;
michael@0 456 }
michael@0 457
michael@0 458 string numpunct_byname<char>::do_truename() const
michael@0 459 { return _Locale_true(_M_numeric); }
michael@0 460
michael@0 461 string numpunct_byname<char>::do_falsename() const
michael@0 462 { return _Locale_false(_M_numeric); }
michael@0 463
michael@0 464 //----------------------------------------------------------------------
michael@0 465 // numpunct<wchar_t>
michael@0 466
michael@0 467 #if !defined (_STLP_NO_WCHAR_T)
michael@0 468
michael@0 469 // numpunct_byname<wchar_t>
michael@0 470
michael@0 471 numpunct_byname<wchar_t>::numpunct_byname(const char* name, size_t refs)
michael@0 472 : numpunct<wchar_t>(refs) {
michael@0 473 if (!name)
michael@0 474 locale::_M_throw_on_null_name();
michael@0 475
michael@0 476 int __err_code;
michael@0 477 char buf[_Locale_MAX_SIMPLE_NAME];
michael@0 478 _M_numeric = _STLP_PRIV __acquire_numeric(name, buf, 0, &__err_code);
michael@0 479 if (!_M_numeric)
michael@0 480 locale::_M_throw_on_creation_failure(__err_code, name, "numpunct");
michael@0 481 }
michael@0 482
michael@0 483 numpunct_byname<wchar_t>::~numpunct_byname()
michael@0 484 { _STLP_PRIV __release_numeric(_M_numeric); }
michael@0 485
michael@0 486 wchar_t numpunct_byname<wchar_t>::do_decimal_point() const
michael@0 487 { return _WLocale_decimal_point(_M_numeric); }
michael@0 488
michael@0 489 wchar_t numpunct_byname<wchar_t>::do_thousands_sep() const
michael@0 490 { return _WLocale_thousands_sep(_M_numeric); }
michael@0 491
michael@0 492 string numpunct_byname<wchar_t>::do_grouping() const {
michael@0 493 const char * __grouping = _Locale_grouping(_M_numeric);
michael@0 494 if (__grouping != NULL && __grouping[0] == CHAR_MAX)
michael@0 495 __grouping = "";
michael@0 496 return __grouping;
michael@0 497 }
michael@0 498
michael@0 499 wstring numpunct_byname<wchar_t>::do_truename() const {
michael@0 500 wchar_t buf[16];
michael@0 501 return _WLocale_true(_M_numeric, _STLP_ARRAY_AND_SIZE(buf));
michael@0 502 }
michael@0 503
michael@0 504 wstring numpunct_byname<wchar_t>::do_falsename() const {
michael@0 505 wchar_t buf[16];
michael@0 506 return _WLocale_false(_M_numeric, _STLP_ARRAY_AND_SIZE(buf));
michael@0 507 }
michael@0 508
michael@0 509 #endif
michael@0 510
michael@0 511 _STLP_MOVE_TO_PRIV_NAMESPACE
michael@0 512
michael@0 513 static void _Init_monetary_formats(money_base::pattern& pos_format,
michael@0 514 money_base::pattern& neg_format,
michael@0 515 _Locale_monetary * monetary) {
michael@0 516 switch (_Locale_p_sign_posn(monetary)) {
michael@0 517 case 0: // Parentheses surround the quantity and currency symbol
michael@0 518 case 1: // The sign string precedes the quantity and currency symbol
michael@0 519 pos_format.field[0] = (char) money_base::sign;
michael@0 520 if (_Locale_p_cs_precedes(monetary)) {
michael@0 521 // 1 if currency symbol precedes a positive value
michael@0 522 pos_format.field[1] = (char) money_base::symbol;
michael@0 523 if (_Locale_p_sep_by_space(monetary)) {
michael@0 524 // a space separates currency symbol from a positive value.
michael@0 525 pos_format.field[2] = (char) money_base::space;
michael@0 526 pos_format.field[3] = (char) money_base::value;
michael@0 527 } else {
michael@0 528 // a space not separates currency symbol from a positive value.
michael@0 529 pos_format.field[2] = (char) money_base::value;
michael@0 530 pos_format.field[3] = (char) money_base::none;
michael@0 531 }
michael@0 532 } else {
michael@0 533 // 0 if currency symbol succeeds a positive value
michael@0 534 pos_format.field[1] = (char) money_base::value;
michael@0 535 if (_Locale_p_sep_by_space(monetary)) {
michael@0 536 // a space separates currency symbol from a positive value.
michael@0 537 pos_format.field[2] = (char) money_base::space;
michael@0 538 pos_format.field[3] = (char) money_base::symbol;
michael@0 539 } else {
michael@0 540 // a space not separates currency symbol from a positive value.
michael@0 541 pos_format.field[2] = (char) money_base::symbol;
michael@0 542 pos_format.field[3] = (char) money_base::none;
michael@0 543 }
michael@0 544 }
michael@0 545 break;
michael@0 546 case 2: // The sign string succeeds the quantity and currency symbol.
michael@0 547 if (_Locale_p_cs_precedes(monetary)) {
michael@0 548 // 1 if currency symbol precedes a positive value
michael@0 549 pos_format.field[0] = (char) money_base::symbol;
michael@0 550 if (_Locale_p_sep_by_space(monetary)) {
michael@0 551 // a space separates currency symbol from a positive value.
michael@0 552 pos_format.field[1] = (char) money_base::space;
michael@0 553 pos_format.field[2] = (char) money_base::value;
michael@0 554 pos_format.field[3] = (char) money_base::sign;
michael@0 555 } else {
michael@0 556 // a space not separates currency symbol from a positive value.
michael@0 557 pos_format.field[1] = (char) money_base::value;
michael@0 558 pos_format.field[2] = (char) money_base::sign;
michael@0 559 pos_format.field[3] = (char) money_base::none;
michael@0 560 }
michael@0 561 } else {
michael@0 562 // 0 if currency symbol succeeds a positive value
michael@0 563 pos_format.field[0] = (char) money_base::value;
michael@0 564 if (_Locale_p_sep_by_space(monetary)) {
michael@0 565 // a space separates currency symbol from a positive value.
michael@0 566 pos_format.field[1] = (char) money_base::space;
michael@0 567 pos_format.field[2] = (char) money_base::symbol;
michael@0 568 pos_format.field[3] = (char) money_base::sign;
michael@0 569 } else {
michael@0 570 // a space not separates currency symbol from a positive value.
michael@0 571 pos_format.field[1] = (char) money_base::symbol;
michael@0 572 pos_format.field[2] = (char) money_base::sign;
michael@0 573 pos_format.field[3] = (char) money_base::none;
michael@0 574 }
michael@0 575 }
michael@0 576 break;
michael@0 577 case 3: // The sign string immediately precedes the currency symbol.
michael@0 578 if (_Locale_p_cs_precedes(monetary)) {
michael@0 579 // 1 if currency symbol precedes a positive value
michael@0 580 pos_format.field[0] = (char) money_base::sign;
michael@0 581 pos_format.field[1] = (char) money_base::symbol;
michael@0 582 if (_Locale_p_sep_by_space(monetary)) {
michael@0 583 // a space separates currency symbol from a positive value.
michael@0 584 pos_format.field[2] = (char) money_base::space;
michael@0 585 pos_format.field[3] = (char) money_base::value;
michael@0 586 } else {
michael@0 587 // a space not separates currency symbol from a positive value.
michael@0 588 pos_format.field[2] = (char) money_base::value;
michael@0 589 pos_format.field[3] = (char) money_base::none;
michael@0 590 }
michael@0 591 } else {
michael@0 592 // 0 if currency symbol succeeds a positive value
michael@0 593 pos_format.field[0] = (char) money_base::value;
michael@0 594 pos_format.field[1] = (char) money_base::sign;
michael@0 595 pos_format.field[2] = (char) money_base::symbol;
michael@0 596 pos_format.field[3] = (char) money_base::none;
michael@0 597 }
michael@0 598 break;
michael@0 599 case 4: // The sign string immediately succeeds the currency symbol.
michael@0 600 if (_Locale_p_cs_precedes(monetary)) {
michael@0 601 // 1 if currency symbol precedes a positive value
michael@0 602 pos_format.field[0] = (char) money_base::symbol;
michael@0 603 pos_format.field[1] = (char) money_base::sign;
michael@0 604 pos_format.field[2] = (char) money_base::value;
michael@0 605 pos_format.field[3] = (char) money_base::none;
michael@0 606 } else {
michael@0 607 // 0 if currency symbol succeeds a positive value
michael@0 608 pos_format.field[0] = (char) money_base::value;
michael@0 609 if (_Locale_p_sep_by_space(monetary)) {
michael@0 610 // a space separates currency symbol from a positive value.
michael@0 611 pos_format.field[1] = (char) money_base::space;
michael@0 612 pos_format.field[2] = (char) money_base::symbol;
michael@0 613 pos_format.field[3] = (char) money_base::sign;
michael@0 614 } else {
michael@0 615 // a space not separates currency symbol from a positive value.
michael@0 616 pos_format.field[1] = (char) money_base::symbol;
michael@0 617 pos_format.field[2] = (char) money_base::sign;
michael@0 618 pos_format.field[3] = (char) money_base::none;
michael@0 619 }
michael@0 620 }
michael@0 621 break;
michael@0 622 default: // Default C++ Standard format
michael@0 623 pos_format.field[0] = (char) money_base::symbol;
michael@0 624 pos_format.field[1] = (char) money_base::sign;
michael@0 625 pos_format.field[2] = (char) money_base::none;
michael@0 626 pos_format.field[3] = (char) money_base::value;
michael@0 627 break;
michael@0 628 }
michael@0 629
michael@0 630 switch (_Locale_n_sign_posn(monetary)) {
michael@0 631 case 0: // Parentheses surround the quantity and currency symbol
michael@0 632 case 1: // The sign string precedes the quantity and currency symbol
michael@0 633 neg_format.field[0] = (char) money_base::sign;
michael@0 634 if (_Locale_n_cs_precedes(monetary)) {
michael@0 635 // 1 if currency symbol precedes a negative value
michael@0 636 neg_format.field[1] = (char) money_base::symbol;
michael@0 637 if (_Locale_n_sep_by_space(monetary)) {
michael@0 638 // a space separates currency symbol from a negative value.
michael@0 639 neg_format.field[2] = (char) money_base::space;
michael@0 640 neg_format.field[3] = (char) money_base::value;
michael@0 641 } else {
michael@0 642 // a space not separates currency symbol from a negative value.
michael@0 643 neg_format.field[2] = (char) money_base::value;
michael@0 644 neg_format.field[3] = (char) money_base::none;
michael@0 645 }
michael@0 646 } else {
michael@0 647 // 0 if currency symbol succeeds a negative value
michael@0 648 neg_format.field[1] = (char) money_base::value;
michael@0 649 if (_Locale_n_sep_by_space(monetary)) {
michael@0 650 // a space separates currency symbol from a negative value.
michael@0 651 neg_format.field[2] = (char) money_base::space;
michael@0 652 neg_format.field[3] = (char) money_base::symbol;
michael@0 653 } else {
michael@0 654 // a space not separates currency symbol from a negative value.
michael@0 655 neg_format.field[2] = (char) money_base::symbol;
michael@0 656 neg_format.field[3] = (char) money_base::none;
michael@0 657 }
michael@0 658 }
michael@0 659 break;
michael@0 660 case 2: // The sign string succeeds the quantity and currency symbol.
michael@0 661 if (_Locale_n_cs_precedes(monetary)) {
michael@0 662 // 1 if currency symbol precedes a negative value
michael@0 663 neg_format.field[0] = (char) money_base::symbol;
michael@0 664 if (_Locale_n_sep_by_space(monetary)) {
michael@0 665 // a space separates currency symbol from a negative value.
michael@0 666 neg_format.field[1] = (char) money_base::space;
michael@0 667 neg_format.field[2] = (char) money_base::value;
michael@0 668 neg_format.field[3] = (char) money_base::sign;
michael@0 669 } else {
michael@0 670 // a space not separates currency symbol from a negative value.
michael@0 671 neg_format.field[1] = (char) money_base::value;
michael@0 672 neg_format.field[2] = (char) money_base::sign;
michael@0 673 neg_format.field[3] = (char) money_base::none;
michael@0 674 }
michael@0 675 } else {
michael@0 676 // 0 if currency symbol succeeds a negative value
michael@0 677 neg_format.field[0] = (char) money_base::value;
michael@0 678 if (_Locale_n_sep_by_space(monetary)) {
michael@0 679 // a space separates currency symbol from a negative value.
michael@0 680 neg_format.field[1] = (char) money_base::space;
michael@0 681 neg_format.field[2] = (char) money_base::symbol;
michael@0 682 neg_format.field[3] = (char) money_base::sign;
michael@0 683 } else {
michael@0 684 // a space not separates currency symbol from a negative value.
michael@0 685 neg_format.field[1] = (char) money_base::symbol;
michael@0 686 neg_format.field[2] = (char) money_base::sign;
michael@0 687 neg_format.field[3] = (char) money_base::none;
michael@0 688 }
michael@0 689 }
michael@0 690 break;
michael@0 691 case 3: // The sign string immediately precedes the currency symbol.
michael@0 692 if (_Locale_n_cs_precedes(monetary)) {
michael@0 693 // 1 if currency symbol precedes a negative value
michael@0 694 neg_format.field[0] = (char) money_base::sign;
michael@0 695 neg_format.field[1] = (char) money_base::symbol;
michael@0 696 if (_Locale_n_sep_by_space(monetary)) {
michael@0 697 // a space separates currency symbol from a negative value.
michael@0 698 neg_format.field[2] = (char) money_base::space;
michael@0 699 neg_format.field[3] = (char) money_base::value;
michael@0 700 } else {
michael@0 701 // a space not separates currency symbol from a negative value.
michael@0 702 neg_format.field[2] = (char) money_base::value;
michael@0 703 neg_format.field[3] = (char) money_base::none;
michael@0 704 }
michael@0 705 } else {
michael@0 706 // 0 if currency symbol succeeds a negative value
michael@0 707 neg_format.field[0] = (char) money_base::value;
michael@0 708 neg_format.field[1] = (char) money_base::sign;
michael@0 709 neg_format.field[2] = (char) money_base::symbol;
michael@0 710 neg_format.field[3] = (char) money_base::none;
michael@0 711 }
michael@0 712 break;
michael@0 713 case 4: // The sign string immediately succeeds the currency symbol.
michael@0 714 if (_Locale_n_cs_precedes(monetary)) {
michael@0 715 // 1 if currency symbol precedes a negative value
michael@0 716 neg_format.field[0] = (char) money_base::symbol;
michael@0 717 neg_format.field[1] = (char) money_base::sign;
michael@0 718 neg_format.field[2] = (char) money_base::none;
michael@0 719 neg_format.field[3] = (char) money_base::value;
michael@0 720 } else {
michael@0 721 // 0 if currency symbol succeeds a negative value
michael@0 722 neg_format.field[0] = (char) money_base::value;
michael@0 723 if (_Locale_n_sep_by_space(monetary)) {
michael@0 724 // a space separates currency symbol from a negative value.
michael@0 725 neg_format.field[1] = (char) money_base::space;
michael@0 726 neg_format.field[2] = (char) money_base::symbol;
michael@0 727 neg_format.field[3] = (char) money_base::sign;
michael@0 728 } else {
michael@0 729 // a space not separates currency symbol from a negative value.
michael@0 730 neg_format.field[1] = (char) money_base::symbol;
michael@0 731 neg_format.field[2] = (char) money_base::sign;
michael@0 732 neg_format.field[3] = (char) money_base::none;
michael@0 733 }
michael@0 734 }
michael@0 735 break;
michael@0 736 default: // Default C++ Standard format
michael@0 737 neg_format.field[0] = (char) money_base::symbol;
michael@0 738 neg_format.field[1] = (char) money_base::sign;
michael@0 739 neg_format.field[2] = (char) money_base::none;
michael@0 740 neg_format.field[3] = (char) money_base::value;
michael@0 741 break;
michael@0 742 }
michael@0 743 }
michael@0 744
michael@0 745 // international variant of monetary
michael@0 746
michael@0 747 /*
michael@0 748 * int_curr_symbol
michael@0 749 *
michael@0 750 * The international currency symbol. The operand is a four-character
michael@0 751 * string, with the first three characters containing the alphabetic
michael@0 752 * international currency symbol in accordance with those specified
michael@0 753 * in the ISO 4217 specification. The fourth character is the character used
michael@0 754 * to separate the international currency symbol from the monetary quantity.
michael@0 755 *
michael@0 756 * (http://www.opengroup.org/onlinepubs/7990989775/xbd/locale.html)
michael@0 757 */
michael@0 758
michael@0 759 /*
michael@0 760 * Standards are unclear in the usage of international currency
michael@0 761 * and monetary formats.
michael@0 762 * But I am expect that international currency symbol should be the first
michael@0 763 * (not depends upon where currency symbol situated in the national
michael@0 764 * format).
michael@0 765 *
michael@0 766 * If this isn't so, let's see:
michael@0 767 * 1 234.56 RUR
michael@0 768 * GBP 1,234.56
michael@0 769 * USD 1,234.56
michael@0 770 * The situation really is worse than you see above:
michael@0 771 * RUR typed wrong here---it prints '1 234.56 RUR ' (see space after RUR).
michael@0 772 * This is due to intl_fmp.curr_symbol() == "RUR ". (see reference in comments
michael@0 773 * above).
michael@0 774 *
michael@0 775 */
michael@0 776
michael@0 777 static void _Init_monetary_formats_int(money_base::pattern& pos_format,
michael@0 778 money_base::pattern& neg_format,
michael@0 779 _Locale_monetary * monetary)
michael@0 780 {
michael@0 781
michael@0 782 switch (_Locale_p_sign_posn(monetary)) {
michael@0 783 case 0: // Parentheses surround the quantity and currency symbol
michael@0 784 case 1: // The sign string precedes the quantity and currency symbol
michael@0 785 pos_format.field[0] = (char) money_base::symbol;
michael@0 786 pos_format.field[1] = (char) money_base::sign;
michael@0 787 pos_format.field[2] = (char) money_base::value;
michael@0 788 pos_format.field[3] = (char) money_base::none;
michael@0 789 break;
michael@0 790 case 2: // The sign string succeeds the quantity and currency symbol.
michael@0 791 pos_format.field[0] = (char) money_base::symbol;
michael@0 792 pos_format.field[1] = (char) money_base::value;
michael@0 793 pos_format.field[2] = (char) money_base::sign;
michael@0 794 pos_format.field[3] = (char) money_base::none;
michael@0 795 break;
michael@0 796 case 3: // The sign string immediately precedes the currency symbol.
michael@0 797 case 4: // The sign string immediately succeeds the currency symbol.
michael@0 798 pos_format.field[0] = (char) money_base::symbol;
michael@0 799 if (_Locale_p_cs_precedes(monetary)) {
michael@0 800 // 1 if currency symbol precedes a positive value
michael@0 801 pos_format.field[1] = (char) money_base::sign;
michael@0 802 pos_format.field[2] = (char) money_base::value;
michael@0 803 } else {
michael@0 804 // 0 if currency symbol succeeds a positive value
michael@0 805 pos_format.field[1] = (char) money_base::value;
michael@0 806 pos_format.field[2] = (char) money_base::sign;
michael@0 807 }
michael@0 808 pos_format.field[3] = (char) money_base::none;
michael@0 809 break;
michael@0 810 default: // Default C++ Standard format
michael@0 811 pos_format.field[0] = (char) money_base::symbol;
michael@0 812 pos_format.field[1] = (char) money_base::sign;
michael@0 813 pos_format.field[2] = (char) money_base::none;
michael@0 814 pos_format.field[3] = (char) money_base::value;
michael@0 815 break;
michael@0 816 }
michael@0 817
michael@0 818
michael@0 819 switch (_Locale_n_sign_posn(monetary)) {
michael@0 820 case 0: // Parentheses surround the quantity and currency symbol
michael@0 821 case 1: // The sign string precedes the quantity and currency symbol
michael@0 822 neg_format.field[0] = (char) money_base::symbol;
michael@0 823 neg_format.field[1] = (char) money_base::sign;
michael@0 824 neg_format.field[2] = (char) money_base::value;
michael@0 825 neg_format.field[3] = (char) money_base::none;
michael@0 826 break;
michael@0 827 case 2: // The sign string succeeds the quantity and currency symbol.
michael@0 828 neg_format.field[0] = (char) money_base::symbol;
michael@0 829 neg_format.field[1] = (char) money_base::value;
michael@0 830 neg_format.field[2] = (char) money_base::sign;
michael@0 831 neg_format.field[3] = (char) money_base::none;
michael@0 832 break;
michael@0 833 case 3: // The sign string immediately precedes the currency symbol.
michael@0 834 case 4: // The sign string immediately succeeds the currency symbol.
michael@0 835 neg_format.field[0] = (char) money_base::symbol;
michael@0 836 if (_Locale_n_cs_precedes(monetary)) {
michael@0 837 // 1 if currency symbol precedes a negative value
michael@0 838 neg_format.field[1] = (char) money_base::sign;
michael@0 839 neg_format.field[2] = (char) money_base::value;
michael@0 840 } else {
michael@0 841 // 0 if currency symbol succeeds a negative value
michael@0 842 neg_format.field[1] = (char) money_base::value;
michael@0 843 neg_format.field[2] = (char) money_base::sign;
michael@0 844 }
michael@0 845 neg_format.field[3] = (char) money_base::none;
michael@0 846 break;
michael@0 847 default: // Default C++ Standard format
michael@0 848 neg_format.field[0] = (char) money_base::symbol;
michael@0 849 neg_format.field[1] = (char) money_base::sign;
michael@0 850 neg_format.field[2] = (char) money_base::none;
michael@0 851 neg_format.field[3] = (char) money_base::value;
michael@0 852 break;
michael@0 853 }
michael@0 854 }
michael@0 855
michael@0 856 _STLP_MOVE_TO_STD_NAMESPACE
michael@0 857
michael@0 858 //
michael@0 859 // moneypunct_byname<>
michael@0 860 //
michael@0 861 moneypunct_byname<char, true>::moneypunct_byname(const char * name,
michael@0 862 size_t refs)
michael@0 863 : moneypunct<char, true>(refs) {
michael@0 864 if (!name)
michael@0 865 locale::_M_throw_on_null_name();
michael@0 866
michael@0 867 int __err_code;
michael@0 868 char buf[_Locale_MAX_SIMPLE_NAME];
michael@0 869 _M_monetary = _STLP_PRIV __acquire_monetary(name, buf, 0, &__err_code);
michael@0 870 if (!_M_monetary)
michael@0 871 locale::_M_throw_on_creation_failure(__err_code, name, "moneypunct");
michael@0 872
michael@0 873 _STLP_PRIV _Init_monetary_formats_int(_M_pos_format, _M_neg_format, _M_monetary);
michael@0 874 }
michael@0 875
michael@0 876 moneypunct_byname<char, true>::moneypunct_byname(_Locale_monetary *__mon)
michael@0 877 : _M_monetary(__mon) {
michael@0 878 _STLP_PRIV _Init_monetary_formats_int(_M_pos_format, _M_neg_format, _M_monetary);
michael@0 879 }
michael@0 880
michael@0 881 moneypunct_byname<char, true>::~moneypunct_byname()
michael@0 882 { _STLP_PRIV __release_monetary(_M_monetary); }
michael@0 883
michael@0 884 char moneypunct_byname<char, true>::do_decimal_point() const
michael@0 885 { return _Locale_mon_decimal_point(_M_monetary); }
michael@0 886
michael@0 887 char moneypunct_byname<char, true>::do_thousands_sep() const
michael@0 888 { return _Locale_mon_thousands_sep(_M_monetary); }
michael@0 889
michael@0 890 string moneypunct_byname<char, true>::do_grouping() const
michael@0 891 { return _Locale_mon_grouping(_M_monetary); }
michael@0 892
michael@0 893 string moneypunct_byname<char, true>::do_curr_symbol() const
michael@0 894 { return _Locale_int_curr_symbol(_M_monetary); }
michael@0 895
michael@0 896 string moneypunct_byname<char, true>::do_positive_sign() const
michael@0 897 { return _Locale_positive_sign(_M_monetary); }
michael@0 898
michael@0 899 string moneypunct_byname<char, true>::do_negative_sign() const
michael@0 900 { return _Locale_negative_sign(_M_monetary); }
michael@0 901
michael@0 902 int moneypunct_byname<char, true>::do_frac_digits() const
michael@0 903 { return _Locale_int_frac_digits(_M_monetary); }
michael@0 904
michael@0 905 moneypunct_byname<char, false>::moneypunct_byname(const char * name,
michael@0 906 size_t refs)
michael@0 907 : moneypunct<char, false>(refs) {
michael@0 908 if (!name)
michael@0 909 locale::_M_throw_on_null_name();
michael@0 910
michael@0 911 int __err_code;
michael@0 912 char buf[_Locale_MAX_SIMPLE_NAME];
michael@0 913 _M_monetary = _STLP_PRIV __acquire_monetary(name, buf, 0, &__err_code);
michael@0 914 if (!_M_monetary)
michael@0 915 locale::_M_throw_on_creation_failure(__err_code, name, "moneypunct");
michael@0 916
michael@0 917 _STLP_PRIV _Init_monetary_formats(_M_pos_format, _M_neg_format, _M_monetary);
michael@0 918 }
michael@0 919
michael@0 920 moneypunct_byname<char, false>::moneypunct_byname(_Locale_monetary *__mon)
michael@0 921 : _M_monetary(__mon) {
michael@0 922 _STLP_PRIV _Init_monetary_formats(_M_pos_format, _M_neg_format, _M_monetary);
michael@0 923 }
michael@0 924
michael@0 925 moneypunct_byname<char, false>::~moneypunct_byname()
michael@0 926 { _STLP_PRIV __release_monetary(_M_monetary); }
michael@0 927
michael@0 928 char moneypunct_byname<char, false>::do_decimal_point() const
michael@0 929 { return _Locale_mon_decimal_point(_M_monetary); }
michael@0 930
michael@0 931 char moneypunct_byname<char, false>::do_thousands_sep() const
michael@0 932 { return _Locale_mon_thousands_sep(_M_monetary); }
michael@0 933
michael@0 934 string moneypunct_byname<char, false>::do_grouping() const
michael@0 935 { return _Locale_mon_grouping(_M_monetary); }
michael@0 936
michael@0 937 string moneypunct_byname<char, false>::do_curr_symbol() const
michael@0 938 { return _Locale_currency_symbol(_M_monetary); }
michael@0 939
michael@0 940 string moneypunct_byname<char, false>::do_positive_sign() const
michael@0 941 { return _Locale_positive_sign(_M_monetary); }
michael@0 942
michael@0 943 string moneypunct_byname<char, false>::do_negative_sign() const
michael@0 944 { return _Locale_negative_sign(_M_monetary); }
michael@0 945
michael@0 946 int moneypunct_byname<char, false>::do_frac_digits() const
michael@0 947 { return _Locale_frac_digits(_M_monetary); }
michael@0 948
michael@0 949 //
michael@0 950 // moneypunct_byname<wchar_t>
michael@0 951 //
michael@0 952 #if !defined (_STLP_NO_WCHAR_T)
michael@0 953
michael@0 954 moneypunct_byname<wchar_t, true>::moneypunct_byname(const char * name,
michael@0 955 size_t refs)
michael@0 956 : moneypunct<wchar_t, true>(refs) {
michael@0 957 if (!name)
michael@0 958 locale::_M_throw_on_null_name();
michael@0 959
michael@0 960 int __err_code;
michael@0 961 char buf[_Locale_MAX_SIMPLE_NAME];
michael@0 962 _M_monetary = _STLP_PRIV __acquire_monetary(name, buf, 0, &__err_code);
michael@0 963 if (!_M_monetary)
michael@0 964 locale::_M_throw_on_creation_failure(__err_code, name, "moneypunct");
michael@0 965
michael@0 966 _STLP_PRIV _Init_monetary_formats_int(_M_pos_format, _M_neg_format, _M_monetary);
michael@0 967 }
michael@0 968
michael@0 969 moneypunct_byname<wchar_t, true>::moneypunct_byname(_Locale_monetary *__mon)
michael@0 970 : _M_monetary(__mon) {
michael@0 971 _STLP_PRIV _Init_monetary_formats_int(_M_pos_format, _M_neg_format, _M_monetary);
michael@0 972 }
michael@0 973
michael@0 974 moneypunct_byname<wchar_t, true>::~moneypunct_byname()
michael@0 975 { _STLP_PRIV __release_monetary(_M_monetary); }
michael@0 976
michael@0 977 wchar_t moneypunct_byname<wchar_t, true>::do_decimal_point() const
michael@0 978 { return _Locale_mon_decimal_point(_M_monetary); }
michael@0 979
michael@0 980 wchar_t moneypunct_byname<wchar_t, true>::do_thousands_sep() const
michael@0 981 { return _Locale_mon_thousands_sep(_M_monetary); }
michael@0 982
michael@0 983 string moneypunct_byname<wchar_t, true>::do_grouping() const
michael@0 984 { return _Locale_mon_grouping(_M_monetary); }
michael@0 985
michael@0 986 inline wstring __do_widen (string const& str) {
michael@0 987 #if defined (_STLP_NO_MEMBER_TEMPLATES) || defined (_STLP_MSVC)
michael@0 988 wstring::_Reserve_t __Reserve;
michael@0 989 size_t __size = str.size();
michael@0 990 wstring result(__Reserve, __size);
michael@0 991 copy(str.begin(), str.end(), result.begin());
michael@0 992 #else
michael@0 993 wstring result(str.begin(), str.end());
michael@0 994 #endif
michael@0 995 return result;
michael@0 996 }
michael@0 997
michael@0 998 wstring moneypunct_byname<wchar_t, true>::do_curr_symbol() const
michael@0 999 { wchar_t buf[16]; return _WLocale_int_curr_symbol(_M_monetary, _STLP_ARRAY_AND_SIZE(buf)); }
michael@0 1000
michael@0 1001 wstring moneypunct_byname<wchar_t, true>::do_positive_sign() const
michael@0 1002 { wchar_t buf[16]; return _WLocale_positive_sign(_M_monetary, _STLP_ARRAY_AND_SIZE(buf)); }
michael@0 1003
michael@0 1004 wstring moneypunct_byname<wchar_t, true>::do_negative_sign() const
michael@0 1005 { wchar_t buf[16]; return _WLocale_negative_sign(_M_monetary, _STLP_ARRAY_AND_SIZE(buf)); }
michael@0 1006
michael@0 1007 int moneypunct_byname<wchar_t, true>::do_frac_digits() const
michael@0 1008 { return _Locale_int_frac_digits(_M_monetary); }
michael@0 1009
michael@0 1010 moneypunct_byname<wchar_t, false>::moneypunct_byname(const char * name,
michael@0 1011 size_t refs)
michael@0 1012 : moneypunct<wchar_t, false>(refs) {
michael@0 1013 if (!name)
michael@0 1014 locale::_M_throw_on_null_name() ;
michael@0 1015
michael@0 1016 int __err_code;
michael@0 1017 char buf[_Locale_MAX_SIMPLE_NAME];
michael@0 1018 _M_monetary = _STLP_PRIV __acquire_monetary(name, buf, 0, &__err_code);
michael@0 1019 if (!_M_monetary)
michael@0 1020 locale::_M_throw_on_creation_failure(__err_code, name, "moneypunct");
michael@0 1021
michael@0 1022 _STLP_PRIV _Init_monetary_formats(_M_pos_format, _M_neg_format, _M_monetary);
michael@0 1023 }
michael@0 1024
michael@0 1025 moneypunct_byname<wchar_t, false>::moneypunct_byname(_Locale_monetary *__mon)
michael@0 1026 : _M_monetary(__mon) {
michael@0 1027 _STLP_PRIV _Init_monetary_formats(_M_pos_format, _M_neg_format, _M_monetary);
michael@0 1028 }
michael@0 1029
michael@0 1030 moneypunct_byname<wchar_t, false>::~moneypunct_byname()
michael@0 1031 { _STLP_PRIV __release_monetary(_M_monetary); }
michael@0 1032
michael@0 1033 wchar_t moneypunct_byname<wchar_t, false>::do_decimal_point() const
michael@0 1034 { return _Locale_mon_decimal_point(_M_monetary); }
michael@0 1035
michael@0 1036 wchar_t moneypunct_byname<wchar_t, false>::do_thousands_sep() const
michael@0 1037 { return _Locale_mon_thousands_sep(_M_monetary); }
michael@0 1038
michael@0 1039 string moneypunct_byname<wchar_t, false>::do_grouping() const
michael@0 1040 { return _Locale_mon_grouping(_M_monetary); }
michael@0 1041
michael@0 1042 wstring moneypunct_byname<wchar_t, false>::do_curr_symbol() const
michael@0 1043 { wchar_t buf[16]; return _WLocale_currency_symbol(_M_monetary, _STLP_ARRAY_AND_SIZE(buf)); }
michael@0 1044
michael@0 1045 wstring moneypunct_byname<wchar_t, false>::do_positive_sign() const
michael@0 1046 { wchar_t buf[16]; return _WLocale_positive_sign(_M_monetary, _STLP_ARRAY_AND_SIZE(buf)); }
michael@0 1047
michael@0 1048 wstring moneypunct_byname<wchar_t, false>::do_negative_sign() const
michael@0 1049 { wchar_t buf[16]; return _WLocale_negative_sign(_M_monetary, _STLP_ARRAY_AND_SIZE(buf)); }
michael@0 1050
michael@0 1051 int moneypunct_byname<wchar_t, false>::do_frac_digits() const
michael@0 1052 { return _Locale_frac_digits(_M_monetary); }
michael@0 1053
michael@0 1054 #endif
michael@0 1055
michael@0 1056 _STLP_END_NAMESPACE
michael@0 1057

mercurial