Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenfacets_byname.cpp
Go to the documentation of this file.
00001 /* 00002 * Copyright (c) 1999 00003 * Silicon Graphics Computer Systems, Inc. 00004 * 00005 * Copyright (c) 1999 00006 * Boris Fomitchev 00007 * 00008 * This material is provided "as is", with absolutely no warranty expressed 00009 * or implied. Any use is at your own risk. 00010 * 00011 * Permission to use or copy this software for any purpose is hereby granted 00012 * without fee, provided the above notices are retained on all copies. 00013 * Permission to modify the code and to distribute modified code is granted, 00014 * provided the above notices are retained, and a notice that the code was 00015 * modified is included with the above copyright notice. 00016 * 00017 */ 00018 #include "stlport_prefix.h" 00019 00020 #include <hash_map> 00021 #include <vector> 00022 00023 #include <locale> 00024 #include <istream> 00025 00026 #include <algorithm> 00027 #include <functional> 00028 00029 #include "c_locale.h" 00030 #include "locale_impl.h" 00031 #include "acquire_release.h" 00032 00033 _STLP_BEGIN_NAMESPACE 00034 00035 //---------------------------------------------------------------------- 00036 // ctype_byname<char> 00037 00038 #if defined (__DMC__) 00039 _STLP_DECLSPEC 00040 #endif 00041 ctype_byname<char>::ctype_byname(const char* name, size_t refs) 00042 : ctype<char>( 0, false, refs) { 00043 if (!name) 00044 locale::_M_throw_on_null_name(); 00045 00046 int __err_code; 00047 char buf[_Locale_MAX_SIMPLE_NAME]; 00048 _M_ctype = _STLP_PRIV __acquire_ctype(name, buf, 0, &__err_code); 00049 if (!_M_ctype) 00050 locale::_M_throw_on_creation_failure(__err_code, name, "ctype"); 00051 00052 _M_init(); 00053 } 00054 00055 void ctype_byname<char>::_M_init() { 00056 _M_ctype_table = _M_byname_table; 00057 00058 // We have to do this, instead of just pointer twiddling, because 00059 // ctype_base::mask isn't the same type as _Locale_mask_t. 00060 const _Locale_mask_t* p = _Locale_ctype_table(_M_ctype); 00061 for (size_t i = 0; i != table_size; ++i) { 00062 _M_byname_table[i] = ctype_base::mask(p[i]); 00063 } 00064 } 00065 00066 ctype_byname<char>::~ctype_byname() 00067 { _STLP_PRIV __release_ctype(_M_ctype); } 00068 00069 char ctype_byname<char>::do_toupper(char c) const 00070 { return (char)_Locale_toupper(_M_ctype, c); } 00071 00072 char ctype_byname<char>::do_tolower(char c) const 00073 { return (char)_Locale_tolower(_M_ctype, c); } 00074 00075 const char* 00076 ctype_byname<char>::do_toupper(char* first, const char* last) const { 00077 for ( ; first != last ; ++first) 00078 *first = (char)_Locale_toupper(_M_ctype, *first); 00079 return last; 00080 } 00081 00082 const char* 00083 ctype_byname<char>::do_tolower(char* first, const char* last) const { 00084 for ( ; first != last ; ++first) 00085 *first = (char)_Locale_tolower(_M_ctype, *first); 00086 return last; 00087 } 00088 00089 00090 // Some helper functions used in ctype<>::scan_is and scan_is_not. 00091 #if !defined (_STLP_NO_WCHAR_T) 00092 00093 _STLP_MOVE_TO_PRIV_NAMESPACE 00094 00095 // ctype_byname<wchar_t> 00096 00097 struct _Ctype_byname_w_is_mask : public unary_function<wchar_t, bool> { 00098 _Locale_mask_t M; 00099 _Locale_ctype* M_ctp; 00100 00101 _Ctype_byname_w_is_mask(_Locale_mask_t m, _Locale_ctype* c) 00102 : M(m), M_ctp(c) {} 00103 bool operator()(wchar_t c) const 00104 { return _WLocale_ctype(M_ctp, c, M) != 0; } 00105 }; 00106 00107 _STLP_MOVE_TO_STD_NAMESPACE 00108 00109 #if defined (__DMC__) 00110 _STLP_DECLSPEC 00111 #endif 00112 ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs) 00113 : ctype<wchar_t>(refs) { 00114 if (!name) 00115 locale::_M_throw_on_null_name(); 00116 00117 int __err_code; 00118 char buf[_Locale_MAX_SIMPLE_NAME]; 00119 _M_ctype = _STLP_PRIV __acquire_ctype(name, buf, 0, &__err_code); 00120 if (!_M_ctype) 00121 locale::_M_throw_on_creation_failure(__err_code, name, "ctype"); 00122 } 00123 00124 ctype_byname<wchar_t>::~ctype_byname() 00125 { _STLP_PRIV __release_ctype(_M_ctype); } 00126 00127 bool ctype_byname<wchar_t>::do_is(ctype_base::mask m, wchar_t c) const 00128 { return _WLocale_ctype(_M_ctype, c, (_Locale_mask_t)m) != 0; } 00129 00130 const wchar_t* 00131 ctype_byname<wchar_t>::do_is(const wchar_t* low, const wchar_t* high, 00132 ctype_base::mask * m) const { 00133 _Locale_mask_t all_bits = _Locale_mask_t(ctype_base::space | 00134 ctype_base::print | 00135 ctype_base::cntrl | 00136 ctype_base::upper | 00137 ctype_base::lower | 00138 ctype_base::alpha | 00139 ctype_base::digit | 00140 ctype_base::punct | 00141 ctype_base::xdigit); 00142 00143 for ( ; low < high; ++low, ++m) 00144 *m = ctype_base::mask (_WLocale_ctype(_M_ctype, *low, all_bits)); 00145 return high; 00146 } 00147 00148 const wchar_t* 00149 ctype_byname<wchar_t> 00150 ::do_scan_is(ctype_base::mask m, const wchar_t* low, const wchar_t* high) const 00151 { return find_if(low, high, _STLP_PRIV _Ctype_byname_w_is_mask(m, _M_ctype)); } 00152 00153 const wchar_t* 00154 ctype_byname<wchar_t> 00155 ::do_scan_not(ctype_base::mask m, const wchar_t* low, const wchar_t* high) const 00156 { return find_if(low, high, not1(_STLP_PRIV _Ctype_byname_w_is_mask(m, _M_ctype))); } 00157 00158 wchar_t ctype_byname<wchar_t>::do_toupper(wchar_t c) const 00159 { return _WLocale_toupper(_M_ctype, c); } 00160 00161 const wchar_t* 00162 ctype_byname<wchar_t>::do_toupper(wchar_t* low, const wchar_t* high) const { 00163 for ( ; low < high; ++low) 00164 *low = _WLocale_toupper(_M_ctype, *low); 00165 return high; 00166 } 00167 00168 wchar_t ctype_byname<wchar_t>::do_tolower(wchar_t c) const 00169 { return _WLocale_tolower(_M_ctype, c); } 00170 00171 const wchar_t* 00172 ctype_byname<wchar_t>::do_tolower(wchar_t* low, const wchar_t* high) const { 00173 for ( ; low < high; ++low) 00174 *low = _WLocale_tolower(_M_ctype, *low); 00175 return high; 00176 } 00177 00178 #endif /* WCHAR_T */ 00179 00180 // collate_byname<char> 00181 #if defined (__DMC__) 00182 _STLP_DECLSPEC 00183 #endif 00184 collate_byname<char>::collate_byname(const char* name, size_t refs) 00185 : collate<char>(refs) { 00186 if (!name) 00187 locale::_M_throw_on_null_name(); 00188 00189 int __err_code; 00190 char buf[_Locale_MAX_SIMPLE_NAME]; 00191 _M_collate = _STLP_PRIV __acquire_collate(name, buf, 0, &__err_code); 00192 if (!_M_collate) 00193 locale::_M_throw_on_creation_failure(__err_code, name, "collate"); 00194 } 00195 00196 collate_byname<char>::~collate_byname() 00197 { _STLP_PRIV __release_collate(_M_collate); } 00198 00199 int collate_byname<char>::do_compare(const char* __low1, 00200 const char* __high1, 00201 const char* __low2, 00202 const char* __high2) const { 00203 return _Locale_strcmp(_M_collate, 00204 __low1, __high1 - __low1, 00205 __low2, __high2 - __low2); 00206 } 00207 00208 collate_byname<char>::string_type 00209 collate_byname<char>::do_transform(const char* low, const char* high) const { 00210 if (low == high) 00211 return string_type(); 00212 00213 size_t n = _Locale_strxfrm(_M_collate, NULL, 0, low, high - low); 00214 00215 // NOT PORTABLE. What we're doing relies on internal details of the 00216 // string implementation. (Contiguity of string elements and presence 00217 // of trailing zero.) 00218 string_type buf(n, 0); 00219 _Locale_strxfrm(_M_collate, &(*buf.begin()), n + 1, low, high - low); 00220 return buf; 00221 } 00222 00223 00224 #if !defined (_STLP_NO_WCHAR_T) 00225 00226 // collate_byname<wchar_t> 00227 00228 #if defined (__DMC__) 00229 _STLP_DECLSPEC 00230 #endif 00231 collate_byname<wchar_t>::collate_byname(const char* name, size_t refs) 00232 : collate<wchar_t>(refs) { 00233 if (!name) 00234 locale::_M_throw_on_null_name(); 00235 00236 int __err_code; 00237 char buf[_Locale_MAX_SIMPLE_NAME]; 00238 _M_collate = _STLP_PRIV __acquire_collate(name, buf, 0, &__err_code); 00239 if (!_M_collate) 00240 locale::_M_throw_on_creation_failure(__err_code, name, "collate"); 00241 } 00242 00243 collate_byname<wchar_t>::~collate_byname() 00244 { _STLP_PRIV __release_collate(_M_collate); } 00245 00246 int collate_byname<wchar_t>::do_compare(const wchar_t* low1, 00247 const wchar_t* high1, 00248 const wchar_t* low2, 00249 const wchar_t* high2) const { 00250 return _WLocale_strcmp(_M_collate, 00251 low1, high1 - low1, 00252 low2, high2 - low2); 00253 } 00254 00255 collate_byname<wchar_t>::string_type 00256 collate_byname<wchar_t>::do_transform(const wchar_t* low, 00257 const wchar_t* high) const { 00258 if (low == high) 00259 return string_type(); 00260 00261 size_t n = _WLocale_strxfrm(_M_collate, NULL, 0, low, high - low); 00262 00263 // NOT PORTABLE. What we're doing relies on internal details of the 00264 // string implementation. (Contiguity of string elements and presence 00265 // of trailing zero.) 00266 string_type buf(n, 0); 00267 _WLocale_strxfrm(_M_collate, &(*buf.begin()), n + 1, low, high - low); 00268 return buf; 00269 } 00270 00271 #endif /* _STLP_NO_WCHAR_T */ 00272 00273 //---------------------------------------------------------------------- 00274 // codecvt_byname<char> 00275 00276 codecvt_byname<char, char, mbstate_t> 00277 ::codecvt_byname(const char* name, size_t refs) 00278 : codecvt<char, char, mbstate_t>(refs) { 00279 if (!name) 00280 locale::_M_throw_on_null_name(); 00281 } 00282 00283 codecvt_byname<char, char, mbstate_t>::~codecvt_byname() {} 00284 00285 00286 #if !defined (_STLP_NO_WCHAR_T) 00287 00288 //---------------------------------------------------------------------- 00289 // codecvt_byname<wchar_t> 00290 codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname(const char* name, size_t refs) 00291 : codecvt<wchar_t, char, mbstate_t>(refs) { 00292 if (!name) 00293 locale::_M_throw_on_null_name(); 00294 00295 int __err_code; 00296 char buf[_Locale_MAX_SIMPLE_NAME]; 00297 _M_codecvt = _STLP_PRIV __acquire_codecvt(name, buf, 0, &__err_code); 00298 if (!_M_codecvt) 00299 locale::_M_throw_on_creation_failure(__err_code, name, "ctype"); 00300 } 00301 00302 codecvt_byname<wchar_t, char, mbstate_t>::~codecvt_byname() 00303 { _STLP_PRIV __release_codecvt(_M_codecvt); } 00304 00305 codecvt<wchar_t, char, mbstate_t>::result 00306 codecvt_byname<wchar_t, char, mbstate_t>::do_out(state_type& state, 00307 const intern_type* from, 00308 const intern_type* from_end, 00309 const intern_type*& from_next, 00310 extern_type* to, 00311 extern_type* to_limit, 00312 extern_type*& to_next) const { 00313 while (from != from_end && to != to_limit) { 00314 size_t chars_stored = _WLocale_wctomb(_M_codecvt, 00315 to, to_limit - to, *from, 00316 &state); 00317 if (chars_stored == (size_t) -1) { 00318 from_next = from; 00319 to_next = to; 00320 return error; 00321 } 00322 else if (chars_stored == (size_t) -2) { 00323 from_next = from; 00324 to_next = to; 00325 return partial; 00326 } 00327 00328 ++from; 00329 to += chars_stored; 00330 } 00331 00332 from_next = from; 00333 to_next = to; 00334 return ok; 00335 } 00336 00337 codecvt<wchar_t, char, mbstate_t>::result 00338 codecvt_byname<wchar_t, char, mbstate_t>::do_in(state_type& state, 00339 const extern_type* from, 00340 const extern_type* from_end, 00341 const extern_type*& from_next, 00342 intern_type* to, 00343 intern_type* to_end, 00344 intern_type*& to_next) const { 00345 while (from != from_end && to != to_end) { 00346 size_t chars_read = _WLocale_mbtowc(_M_codecvt, 00347 to, from, from_end - from, 00348 &state); 00349 if (chars_read == (size_t) -1) { 00350 from_next = from; 00351 to_next = to; 00352 return error; 00353 } 00354 00355 if (chars_read == (size_t) -2) { 00356 from_next = from; 00357 to_next = to; 00358 return partial; 00359 } 00360 00361 from += chars_read; 00362 to++; 00363 } 00364 00365 from_next = from; 00366 to_next = to; 00367 return ok; 00368 } 00369 00370 codecvt<wchar_t, char, mbstate_t>::result 00371 codecvt_byname<wchar_t, char, mbstate_t>::do_unshift(state_type& state, 00372 extern_type* to, 00373 extern_type* to_limit, 00374 extern_type*& to_next) const { 00375 to_next = to; 00376 size_t result = _WLocale_unshift(_M_codecvt, &state, 00377 to, to_limit - to, &to_next); 00378 if (result == (size_t) -1) 00379 return error; 00380 else if (result == (size_t) -2) 00381 return partial; 00382 else 00383 # if defined (__ISCPP__) 00384 return /*to_next == to ? noconv :*/ ok; 00385 # else 00386 return to_next == to ? noconv : ok; 00387 # endif 00388 } 00389 00390 int 00391 codecvt_byname<wchar_t, char, mbstate_t>::do_encoding() const _STLP_NOTHROW { 00392 if (_WLocale_is_stateless(_M_codecvt)) { 00393 int max_width = _WLocale_mb_cur_max(_M_codecvt); 00394 int min_width = _WLocale_mb_cur_min(_M_codecvt); 00395 return min_width == max_width ? min_width : 0; 00396 } 00397 else 00398 return -1; 00399 } 00400 00401 bool 00402 codecvt_byname<wchar_t, char, mbstate_t>::do_always_noconv() const _STLP_NOTHROW 00403 { return false; } 00404 00405 int 00406 codecvt_byname<wchar_t, char, mbstate_t>::do_length(state_type& state, 00407 const extern_type* from, 00408 const extern_type* end, 00409 size_t mx) const { 00410 size_t __count = 0; 00411 while (from != end && mx--) { 00412 intern_type __dummy; 00413 size_t chars_read = _WLocale_mbtowc(_M_codecvt, 00414 &__dummy, from, end - from, 00415 &state); 00416 if ((chars_read == (size_t) -1) || (chars_read == (size_t) -2)) // error or partial 00417 break; 00418 __count += chars_read; 00419 from += chars_read; 00420 } 00421 return int(__count); 00422 } 00423 00424 int 00425 codecvt_byname<wchar_t, char, mbstate_t>::do_max_length() const _STLP_NOTHROW 00426 { return _WLocale_mb_cur_max(_M_codecvt); } 00427 #endif 00428 00429 // numpunct_byname<char> 00430 numpunct_byname<char>::numpunct_byname(const char* name, size_t refs) 00431 : numpunct<char>(refs) { 00432 if (!name) 00433 locale::_M_throw_on_null_name(); 00434 00435 int __err_code; 00436 char buf[_Locale_MAX_SIMPLE_NAME]; 00437 _M_numeric = _STLP_PRIV __acquire_numeric(name, buf, 0, &__err_code); 00438 if (!_M_numeric) 00439 locale::_M_throw_on_creation_failure(__err_code, name, "numpunct"); 00440 } 00441 00442 numpunct_byname<char>::~numpunct_byname() 00443 { _STLP_PRIV __release_numeric(_M_numeric); } 00444 00445 char numpunct_byname<char>::do_decimal_point() const 00446 { return _Locale_decimal_point(_M_numeric); } 00447 00448 char numpunct_byname<char>::do_thousands_sep() const 00449 { return _Locale_thousands_sep(_M_numeric); } 00450 00451 string numpunct_byname<char>::do_grouping() const { 00452 const char * __grouping = _Locale_grouping(_M_numeric); 00453 if (__grouping != NULL && __grouping[0] == CHAR_MAX) 00454 __grouping = ""; 00455 return __grouping; 00456 } 00457 00458 string numpunct_byname<char>::do_truename() const 00459 { return _Locale_true(_M_numeric); } 00460 00461 string numpunct_byname<char>::do_falsename() const 00462 { return _Locale_false(_M_numeric); } 00463 00464 //---------------------------------------------------------------------- 00465 // numpunct<wchar_t> 00466 00467 #if !defined (_STLP_NO_WCHAR_T) 00468 00469 // numpunct_byname<wchar_t> 00470 00471 numpunct_byname<wchar_t>::numpunct_byname(const char* name, size_t refs) 00472 : numpunct<wchar_t>(refs) { 00473 if (!name) 00474 locale::_M_throw_on_null_name(); 00475 00476 int __err_code; 00477 char buf[_Locale_MAX_SIMPLE_NAME]; 00478 _M_numeric = _STLP_PRIV __acquire_numeric(name, buf, 0, &__err_code); 00479 if (!_M_numeric) 00480 locale::_M_throw_on_creation_failure(__err_code, name, "numpunct"); 00481 } 00482 00483 numpunct_byname<wchar_t>::~numpunct_byname() 00484 { _STLP_PRIV __release_numeric(_M_numeric); } 00485 00486 wchar_t numpunct_byname<wchar_t>::do_decimal_point() const 00487 { return _WLocale_decimal_point(_M_numeric); } 00488 00489 wchar_t numpunct_byname<wchar_t>::do_thousands_sep() const 00490 { return _WLocale_thousands_sep(_M_numeric); } 00491 00492 string numpunct_byname<wchar_t>::do_grouping() const { 00493 const char * __grouping = _Locale_grouping(_M_numeric); 00494 if (__grouping != NULL && __grouping[0] == CHAR_MAX) 00495 __grouping = ""; 00496 return __grouping; 00497 } 00498 00499 wstring numpunct_byname<wchar_t>::do_truename() const { 00500 wchar_t buf[16]; 00501 return _WLocale_true(_M_numeric, _STLP_ARRAY_AND_SIZE(buf)); 00502 } 00503 00504 wstring numpunct_byname<wchar_t>::do_falsename() const { 00505 wchar_t buf[16]; 00506 return _WLocale_false(_M_numeric, _STLP_ARRAY_AND_SIZE(buf)); 00507 } 00508 00509 #endif 00510 00511 _STLP_MOVE_TO_PRIV_NAMESPACE 00512 00513 static void _Init_monetary_formats(money_base::pattern& pos_format, 00514 money_base::pattern& neg_format, 00515 _Locale_monetary * monetary) { 00516 switch (_Locale_p_sign_posn(monetary)) { 00517 case 0: // Parentheses surround the quantity and currency symbol 00518 case 1: // The sign string precedes the quantity and currency symbol 00519 pos_format.field[0] = (char) money_base::sign; 00520 if (_Locale_p_cs_precedes(monetary)) { 00521 // 1 if currency symbol precedes a positive value 00522 pos_format.field[1] = (char) money_base::symbol; 00523 if (_Locale_p_sep_by_space(monetary)) { 00524 // a space separates currency symbol from a positive value. 00525 pos_format.field[2] = (char) money_base::space; 00526 pos_format.field[3] = (char) money_base::value; 00527 } else { 00528 // a space not separates currency symbol from a positive value. 00529 pos_format.field[2] = (char) money_base::value; 00530 pos_format.field[3] = (char) money_base::none; 00531 } 00532 } else { 00533 // 0 if currency symbol succeeds a positive value 00534 pos_format.field[1] = (char) money_base::value; 00535 if (_Locale_p_sep_by_space(monetary)) { 00536 // a space separates currency symbol from a positive value. 00537 pos_format.field[2] = (char) money_base::space; 00538 pos_format.field[3] = (char) money_base::symbol; 00539 } else { 00540 // a space not separates currency symbol from a positive value. 00541 pos_format.field[2] = (char) money_base::symbol; 00542 pos_format.field[3] = (char) money_base::none; 00543 } 00544 } 00545 break; 00546 case 2: // The sign string succeeds the quantity and currency symbol. 00547 if (_Locale_p_cs_precedes(monetary)) { 00548 // 1 if currency symbol precedes a positive value 00549 pos_format.field[0] = (char) money_base::symbol; 00550 if (_Locale_p_sep_by_space(monetary)) { 00551 // a space separates currency symbol from a positive value. 00552 pos_format.field[1] = (char) money_base::space; 00553 pos_format.field[2] = (char) money_base::value; 00554 pos_format.field[3] = (char) money_base::sign; 00555 } else { 00556 // a space not separates currency symbol from a positive value. 00557 pos_format.field[1] = (char) money_base::value; 00558 pos_format.field[2] = (char) money_base::sign; 00559 pos_format.field[3] = (char) money_base::none; 00560 } 00561 } else { 00562 // 0 if currency symbol succeeds a positive value 00563 pos_format.field[0] = (char) money_base::value; 00564 if (_Locale_p_sep_by_space(monetary)) { 00565 // a space separates currency symbol from a positive value. 00566 pos_format.field[1] = (char) money_base::space; 00567 pos_format.field[2] = (char) money_base::symbol; 00568 pos_format.field[3] = (char) money_base::sign; 00569 } else { 00570 // a space not separates currency symbol from a positive value. 00571 pos_format.field[1] = (char) money_base::symbol; 00572 pos_format.field[2] = (char) money_base::sign; 00573 pos_format.field[3] = (char) money_base::none; 00574 } 00575 } 00576 break; 00577 case 3: // The sign string immediately precedes the currency symbol. 00578 if (_Locale_p_cs_precedes(monetary)) { 00579 // 1 if currency symbol precedes a positive value 00580 pos_format.field[0] = (char) money_base::sign; 00581 pos_format.field[1] = (char) money_base::symbol; 00582 if (_Locale_p_sep_by_space(monetary)) { 00583 // a space separates currency symbol from a positive value. 00584 pos_format.field[2] = (char) money_base::space; 00585 pos_format.field[3] = (char) money_base::value; 00586 } else { 00587 // a space not separates currency symbol from a positive value. 00588 pos_format.field[2] = (char) money_base::value; 00589 pos_format.field[3] = (char) money_base::none; 00590 } 00591 } else { 00592 // 0 if currency symbol succeeds a positive value 00593 pos_format.field[0] = (char) money_base::value; 00594 pos_format.field[1] = (char) money_base::sign; 00595 pos_format.field[2] = (char) money_base::symbol; 00596 pos_format.field[3] = (char) money_base::none; 00597 } 00598 break; 00599 case 4: // The sign string immediately succeeds the currency symbol. 00600 if (_Locale_p_cs_precedes(monetary)) { 00601 // 1 if currency symbol precedes a positive value 00602 pos_format.field[0] = (char) money_base::symbol; 00603 pos_format.field[1] = (char) money_base::sign; 00604 pos_format.field[2] = (char) money_base::value; 00605 pos_format.field[3] = (char) money_base::none; 00606 } else { 00607 // 0 if currency symbol succeeds a positive value 00608 pos_format.field[0] = (char) money_base::value; 00609 if (_Locale_p_sep_by_space(monetary)) { 00610 // a space separates currency symbol from a positive value. 00611 pos_format.field[1] = (char) money_base::space; 00612 pos_format.field[2] = (char) money_base::symbol; 00613 pos_format.field[3] = (char) money_base::sign; 00614 } else { 00615 // a space not separates currency symbol from a positive value. 00616 pos_format.field[1] = (char) money_base::symbol; 00617 pos_format.field[2] = (char) money_base::sign; 00618 pos_format.field[3] = (char) money_base::none; 00619 } 00620 } 00621 break; 00622 default: // Default C++ Standard format 00623 pos_format.field[0] = (char) money_base::symbol; 00624 pos_format.field[1] = (char) money_base::sign; 00625 pos_format.field[2] = (char) money_base::none; 00626 pos_format.field[3] = (char) money_base::value; 00627 break; 00628 } 00629 00630 switch (_Locale_n_sign_posn(monetary)) { 00631 case 0: // Parentheses surround the quantity and currency symbol 00632 case 1: // The sign string precedes the quantity and currency symbol 00633 neg_format.field[0] = (char) money_base::sign; 00634 if (_Locale_n_cs_precedes(monetary)) { 00635 // 1 if currency symbol precedes a negative value 00636 neg_format.field[1] = (char) money_base::symbol; 00637 if (_Locale_n_sep_by_space(monetary)) { 00638 // a space separates currency symbol from a negative value. 00639 neg_format.field[2] = (char) money_base::space; 00640 neg_format.field[3] = (char) money_base::value; 00641 } else { 00642 // a space not separates currency symbol from a negative value. 00643 neg_format.field[2] = (char) money_base::value; 00644 neg_format.field[3] = (char) money_base::none; 00645 } 00646 } else { 00647 // 0 if currency symbol succeeds a negative value 00648 neg_format.field[1] = (char) money_base::value; 00649 if (_Locale_n_sep_by_space(monetary)) { 00650 // a space separates currency symbol from a negative value. 00651 neg_format.field[2] = (char) money_base::space; 00652 neg_format.field[3] = (char) money_base::symbol; 00653 } else { 00654 // a space not separates currency symbol from a negative value. 00655 neg_format.field[2] = (char) money_base::symbol; 00656 neg_format.field[3] = (char) money_base::none; 00657 } 00658 } 00659 break; 00660 case 2: // The sign string succeeds the quantity and currency symbol. 00661 if (_Locale_n_cs_precedes(monetary)) { 00662 // 1 if currency symbol precedes a negative value 00663 neg_format.field[0] = (char) money_base::symbol; 00664 if (_Locale_n_sep_by_space(monetary)) { 00665 // a space separates currency symbol from a negative value. 00666 neg_format.field[1] = (char) money_base::space; 00667 neg_format.field[2] = (char) money_base::value; 00668 neg_format.field[3] = (char) money_base::sign; 00669 } else { 00670 // a space not separates currency symbol from a negative value. 00671 neg_format.field[1] = (char) money_base::value; 00672 neg_format.field[2] = (char) money_base::sign; 00673 neg_format.field[3] = (char) money_base::none; 00674 } 00675 } else { 00676 // 0 if currency symbol succeeds a negative value 00677 neg_format.field[0] = (char) money_base::value; 00678 if (_Locale_n_sep_by_space(monetary)) { 00679 // a space separates currency symbol from a negative value. 00680 neg_format.field[1] = (char) money_base::space; 00681 neg_format.field[2] = (char) money_base::symbol; 00682 neg_format.field[3] = (char) money_base::sign; 00683 } else { 00684 // a space not separates currency symbol from a negative value. 00685 neg_format.field[1] = (char) money_base::symbol; 00686 neg_format.field[2] = (char) money_base::sign; 00687 neg_format.field[3] = (char) money_base::none; 00688 } 00689 } 00690 break; 00691 case 3: // The sign string immediately precedes the currency symbol. 00692 if (_Locale_n_cs_precedes(monetary)) { 00693 // 1 if currency symbol precedes a negative value 00694 neg_format.field[0] = (char) money_base::sign; 00695 neg_format.field[1] = (char) money_base::symbol; 00696 if (_Locale_n_sep_by_space(monetary)) { 00697 // a space separates currency symbol from a negative value. 00698 neg_format.field[2] = (char) money_base::space; 00699 neg_format.field[3] = (char) money_base::value; 00700 } else { 00701 // a space not separates currency symbol from a negative value. 00702 neg_format.field[2] = (char) money_base::value; 00703 neg_format.field[3] = (char) money_base::none; 00704 } 00705 } else { 00706 // 0 if currency symbol succeeds a negative value 00707 neg_format.field[0] = (char) money_base::value; 00708 neg_format.field[1] = (char) money_base::sign; 00709 neg_format.field[2] = (char) money_base::symbol; 00710 neg_format.field[3] = (char) money_base::none; 00711 } 00712 break; 00713 case 4: // The sign string immediately succeeds the currency symbol. 00714 if (_Locale_n_cs_precedes(monetary)) { 00715 // 1 if currency symbol precedes a negative value 00716 neg_format.field[0] = (char) money_base::symbol; 00717 neg_format.field[1] = (char) money_base::sign; 00718 neg_format.field[2] = (char) money_base::none; 00719 neg_format.field[3] = (char) money_base::value; 00720 } else { 00721 // 0 if currency symbol succeeds a negative value 00722 neg_format.field[0] = (char) money_base::value; 00723 if (_Locale_n_sep_by_space(monetary)) { 00724 // a space separates currency symbol from a negative value. 00725 neg_format.field[1] = (char) money_base::space; 00726 neg_format.field[2] = (char) money_base::symbol; 00727 neg_format.field[3] = (char) money_base::sign; 00728 } else { 00729 // a space not separates currency symbol from a negative value. 00730 neg_format.field[1] = (char) money_base::symbol; 00731 neg_format.field[2] = (char) money_base::sign; 00732 neg_format.field[3] = (char) money_base::none; 00733 } 00734 } 00735 break; 00736 default: // Default C++ Standard format 00737 neg_format.field[0] = (char) money_base::symbol; 00738 neg_format.field[1] = (char) money_base::sign; 00739 neg_format.field[2] = (char) money_base::none; 00740 neg_format.field[3] = (char) money_base::value; 00741 break; 00742 } 00743 } 00744 00745 // international variant of monetary 00746 00747 /* 00748 * int_curr_symbol 00749 * 00750 * The international currency symbol. The operand is a four-character 00751 * string, with the first three characters containing the alphabetic 00752 * international currency symbol in accordance with those specified 00753 * in the ISO 4217 specification. The fourth character is the character used 00754 * to separate the international currency symbol from the monetary quantity. 00755 * 00756 * (http://www.opengroup.org/onlinepubs/7990989775/xbd/locale.html) 00757 */ 00758 00759 /* 00760 * Standards are unclear in the usage of international currency 00761 * and monetary formats. 00762 * But I am expect that international currency symbol should be the first 00763 * (not depends upon where currency symbol situated in the national 00764 * format). 00765 * 00766 * If this isn't so, let's see: 00767 * 1 234.56 RUR 00768 * GBP 1,234.56 00769 * USD 1,234.56 00770 * The situation really is worse than you see above: 00771 * RUR typed wrong here---it prints '1 234.56 RUR ' (see space after RUR). 00772 * This is due to intl_fmp.curr_symbol() == "RUR ". (see reference in comments 00773 * above). 00774 * 00775 */ 00776 00777 static void _Init_monetary_formats_int(money_base::pattern& pos_format, 00778 money_base::pattern& neg_format, 00779 _Locale_monetary * monetary) 00780 { 00781 00782 switch (_Locale_p_sign_posn(monetary)) { 00783 case 0: // Parentheses surround the quantity and currency symbol 00784 case 1: // The sign string precedes the quantity and currency symbol 00785 pos_format.field[0] = (char) money_base::symbol; 00786 pos_format.field[1] = (char) money_base::sign; 00787 pos_format.field[2] = (char) money_base::value; 00788 pos_format.field[3] = (char) money_base::none; 00789 break; 00790 case 2: // The sign string succeeds the quantity and currency symbol. 00791 pos_format.field[0] = (char) money_base::symbol; 00792 pos_format.field[1] = (char) money_base::value; 00793 pos_format.field[2] = (char) money_base::sign; 00794 pos_format.field[3] = (char) money_base::none; 00795 break; 00796 case 3: // The sign string immediately precedes the currency symbol. 00797 case 4: // The sign string immediately succeeds the currency symbol. 00798 pos_format.field[0] = (char) money_base::symbol; 00799 if (_Locale_p_cs_precedes(monetary)) { 00800 // 1 if currency symbol precedes a positive value 00801 pos_format.field[1] = (char) money_base::sign; 00802 pos_format.field[2] = (char) money_base::value; 00803 } else { 00804 // 0 if currency symbol succeeds a positive value 00805 pos_format.field[1] = (char) money_base::value; 00806 pos_format.field[2] = (char) money_base::sign; 00807 } 00808 pos_format.field[3] = (char) money_base::none; 00809 break; 00810 default: // Default C++ Standard format 00811 pos_format.field[0] = (char) money_base::symbol; 00812 pos_format.field[1] = (char) money_base::sign; 00813 pos_format.field[2] = (char) money_base::none; 00814 pos_format.field[3] = (char) money_base::value; 00815 break; 00816 } 00817 00818 00819 switch (_Locale_n_sign_posn(monetary)) { 00820 case 0: // Parentheses surround the quantity and currency symbol 00821 case 1: // The sign string precedes the quantity and currency symbol 00822 neg_format.field[0] = (char) money_base::symbol; 00823 neg_format.field[1] = (char) money_base::sign; 00824 neg_format.field[2] = (char) money_base::value; 00825 neg_format.field[3] = (char) money_base::none; 00826 break; 00827 case 2: // The sign string succeeds the quantity and currency symbol. 00828 neg_format.field[0] = (char) money_base::symbol; 00829 neg_format.field[1] = (char) money_base::value; 00830 neg_format.field[2] = (char) money_base::sign; 00831 neg_format.field[3] = (char) money_base::none; 00832 break; 00833 case 3: // The sign string immediately precedes the currency symbol. 00834 case 4: // The sign string immediately succeeds the currency symbol. 00835 neg_format.field[0] = (char) money_base::symbol; 00836 if (_Locale_n_cs_precedes(monetary)) { 00837 // 1 if currency symbol precedes a negative value 00838 neg_format.field[1] = (char) money_base::sign; 00839 neg_format.field[2] = (char) money_base::value; 00840 } else { 00841 // 0 if currency symbol succeeds a negative value 00842 neg_format.field[1] = (char) money_base::value; 00843 neg_format.field[2] = (char) money_base::sign; 00844 } 00845 neg_format.field[3] = (char) money_base::none; 00846 break; 00847 default: // Default C++ Standard format 00848 neg_format.field[0] = (char) money_base::symbol; 00849 neg_format.field[1] = (char) money_base::sign; 00850 neg_format.field[2] = (char) money_base::none; 00851 neg_format.field[3] = (char) money_base::value; 00852 break; 00853 } 00854 } 00855 00856 _STLP_MOVE_TO_STD_NAMESPACE 00857 00858 // 00859 // moneypunct_byname<> 00860 // 00861 moneypunct_byname<char, true>::moneypunct_byname(const char * name, 00862 size_t refs) 00863 : moneypunct<char, true>(refs) { 00864 if (!name) 00865 locale::_M_throw_on_null_name(); 00866 00867 int __err_code; 00868 char buf[_Locale_MAX_SIMPLE_NAME]; 00869 _M_monetary = _STLP_PRIV __acquire_monetary(name, buf, 0, &__err_code); 00870 if (!_M_monetary) 00871 locale::_M_throw_on_creation_failure(__err_code, name, "moneypunct"); 00872 00873 _STLP_PRIV _Init_monetary_formats_int(_M_pos_format, _M_neg_format, _M_monetary); 00874 } 00875 00876 moneypunct_byname<char, true>::moneypunct_byname(_Locale_monetary *__mon) 00877 : _M_monetary(__mon) { 00878 _STLP_PRIV _Init_monetary_formats_int(_M_pos_format, _M_neg_format, _M_monetary); 00879 } 00880 00881 moneypunct_byname<char, true>::~moneypunct_byname() 00882 { _STLP_PRIV __release_monetary(_M_monetary); } 00883 00884 char moneypunct_byname<char, true>::do_decimal_point() const 00885 { return _Locale_mon_decimal_point(_M_monetary); } 00886 00887 char moneypunct_byname<char, true>::do_thousands_sep() const 00888 { return _Locale_mon_thousands_sep(_M_monetary); } 00889 00890 string moneypunct_byname<char, true>::do_grouping() const 00891 { return _Locale_mon_grouping(_M_monetary); } 00892 00893 string moneypunct_byname<char, true>::do_curr_symbol() const 00894 { return _Locale_int_curr_symbol(_M_monetary); } 00895 00896 string moneypunct_byname<char, true>::do_positive_sign() const 00897 { return _Locale_positive_sign(_M_monetary); } 00898 00899 string moneypunct_byname<char, true>::do_negative_sign() const 00900 { return _Locale_negative_sign(_M_monetary); } 00901 00902 int moneypunct_byname<char, true>::do_frac_digits() const 00903 { return _Locale_int_frac_digits(_M_monetary); } 00904 00905 moneypunct_byname<char, false>::moneypunct_byname(const char * name, 00906 size_t refs) 00907 : moneypunct<char, false>(refs) { 00908 if (!name) 00909 locale::_M_throw_on_null_name(); 00910 00911 int __err_code; 00912 char buf[_Locale_MAX_SIMPLE_NAME]; 00913 _M_monetary = _STLP_PRIV __acquire_monetary(name, buf, 0, &__err_code); 00914 if (!_M_monetary) 00915 locale::_M_throw_on_creation_failure(__err_code, name, "moneypunct"); 00916 00917 _STLP_PRIV _Init_monetary_formats(_M_pos_format, _M_neg_format, _M_monetary); 00918 } 00919 00920 moneypunct_byname<char, false>::moneypunct_byname(_Locale_monetary *__mon) 00921 : _M_monetary(__mon) { 00922 _STLP_PRIV _Init_monetary_formats(_M_pos_format, _M_neg_format, _M_monetary); 00923 } 00924 00925 moneypunct_byname<char, false>::~moneypunct_byname() 00926 { _STLP_PRIV __release_monetary(_M_monetary); } 00927 00928 char moneypunct_byname<char, false>::do_decimal_point() const 00929 { return _Locale_mon_decimal_point(_M_monetary); } 00930 00931 char moneypunct_byname<char, false>::do_thousands_sep() const 00932 { return _Locale_mon_thousands_sep(_M_monetary); } 00933 00934 string moneypunct_byname<char, false>::do_grouping() const 00935 { return _Locale_mon_grouping(_M_monetary); } 00936 00937 string moneypunct_byname<char, false>::do_curr_symbol() const 00938 { return _Locale_currency_symbol(_M_monetary); } 00939 00940 string moneypunct_byname<char, false>::do_positive_sign() const 00941 { return _Locale_positive_sign(_M_monetary); } 00942 00943 string moneypunct_byname<char, false>::do_negative_sign() const 00944 { return _Locale_negative_sign(_M_monetary); } 00945 00946 int moneypunct_byname<char, false>::do_frac_digits() const 00947 { return _Locale_frac_digits(_M_monetary); } 00948 00949 // 00950 // moneypunct_byname<wchar_t> 00951 // 00952 #if !defined (_STLP_NO_WCHAR_T) 00953 00954 moneypunct_byname<wchar_t, true>::moneypunct_byname(const char * name, 00955 size_t refs) 00956 : moneypunct<wchar_t, true>(refs) { 00957 if (!name) 00958 locale::_M_throw_on_null_name(); 00959 00960 int __err_code; 00961 char buf[_Locale_MAX_SIMPLE_NAME]; 00962 _M_monetary = _STLP_PRIV __acquire_monetary(name, buf, 0, &__err_code); 00963 if (!_M_monetary) 00964 locale::_M_throw_on_creation_failure(__err_code, name, "moneypunct"); 00965 00966 _STLP_PRIV _Init_monetary_formats_int(_M_pos_format, _M_neg_format, _M_monetary); 00967 } 00968 00969 moneypunct_byname<wchar_t, true>::moneypunct_byname(_Locale_monetary *__mon) 00970 : _M_monetary(__mon) { 00971 _STLP_PRIV _Init_monetary_formats_int(_M_pos_format, _M_neg_format, _M_monetary); 00972 } 00973 00974 moneypunct_byname<wchar_t, true>::~moneypunct_byname() 00975 { _STLP_PRIV __release_monetary(_M_monetary); } 00976 00977 wchar_t moneypunct_byname<wchar_t, true>::do_decimal_point() const 00978 { return _Locale_mon_decimal_point(_M_monetary); } 00979 00980 wchar_t moneypunct_byname<wchar_t, true>::do_thousands_sep() const 00981 { return _Locale_mon_thousands_sep(_M_monetary); } 00982 00983 string moneypunct_byname<wchar_t, true>::do_grouping() const 00984 { return _Locale_mon_grouping(_M_monetary); } 00985 00986 inline wstring __do_widen (string const& str) { 00987 #if defined (_STLP_NO_MEMBER_TEMPLATES) || defined (_STLP_MSVC) 00988 wstring::_Reserve_t __Reserve; 00989 size_t __size = str.size(); 00990 wstring result(__Reserve, __size); 00991 copy(str.begin(), str.end(), result.begin()); 00992 #else 00993 wstring result(str.begin(), str.end()); 00994 #endif 00995 return result; 00996 } 00997 00998 wstring moneypunct_byname<wchar_t, true>::do_curr_symbol() const 00999 { wchar_t buf[16]; return _WLocale_int_curr_symbol(_M_monetary, _STLP_ARRAY_AND_SIZE(buf)); } 01000 01001 wstring moneypunct_byname<wchar_t, true>::do_positive_sign() const 01002 { wchar_t buf[16]; return _WLocale_positive_sign(_M_monetary, _STLP_ARRAY_AND_SIZE(buf)); } 01003 01004 wstring moneypunct_byname<wchar_t, true>::do_negative_sign() const 01005 { wchar_t buf[16]; return _WLocale_negative_sign(_M_monetary, _STLP_ARRAY_AND_SIZE(buf)); } 01006 01007 int moneypunct_byname<wchar_t, true>::do_frac_digits() const 01008 { return _Locale_int_frac_digits(_M_monetary); } 01009 01010 moneypunct_byname<wchar_t, false>::moneypunct_byname(const char * name, 01011 size_t refs) 01012 : moneypunct<wchar_t, false>(refs) { 01013 if (!name) 01014 locale::_M_throw_on_null_name() ; 01015 01016 int __err_code; 01017 char buf[_Locale_MAX_SIMPLE_NAME]; 01018 _M_monetary = _STLP_PRIV __acquire_monetary(name, buf, 0, &__err_code); 01019 if (!_M_monetary) 01020 locale::_M_throw_on_creation_failure(__err_code, name, "moneypunct"); 01021 01022 _STLP_PRIV _Init_monetary_formats(_M_pos_format, _M_neg_format, _M_monetary); 01023 } 01024 01025 moneypunct_byname<wchar_t, false>::moneypunct_byname(_Locale_monetary *__mon) 01026 : _M_monetary(__mon) { 01027 _STLP_PRIV _Init_monetary_formats(_M_pos_format, _M_neg_format, _M_monetary); 01028 } 01029 01030 moneypunct_byname<wchar_t, false>::~moneypunct_byname() 01031 { _STLP_PRIV __release_monetary(_M_monetary); } 01032 01033 wchar_t moneypunct_byname<wchar_t, false>::do_decimal_point() const 01034 { return _Locale_mon_decimal_point(_M_monetary); } 01035 01036 wchar_t moneypunct_byname<wchar_t, false>::do_thousands_sep() const 01037 { return _Locale_mon_thousands_sep(_M_monetary); } 01038 01039 string moneypunct_byname<wchar_t, false>::do_grouping() const 01040 { return _Locale_mon_grouping(_M_monetary); } 01041 01042 wstring moneypunct_byname<wchar_t, false>::do_curr_symbol() const 01043 { wchar_t buf[16]; return _WLocale_currency_symbol(_M_monetary, _STLP_ARRAY_AND_SIZE(buf)); } 01044 01045 wstring moneypunct_byname<wchar_t, false>::do_positive_sign() const 01046 { wchar_t buf[16]; return _WLocale_positive_sign(_M_monetary, _STLP_ARRAY_AND_SIZE(buf)); } 01047 01048 wstring moneypunct_byname<wchar_t, false>::do_negative_sign() const 01049 { wchar_t buf[16]; return _WLocale_negative_sign(_M_monetary, _STLP_ARRAY_AND_SIZE(buf)); } 01050 01051 int moneypunct_byname<wchar_t, false>::do_frac_digits() const 01052 { return _Locale_frac_digits(_M_monetary); } 01053 01054 #endif 01055 01056 _STLP_END_NAMESPACE 01057 Generated on Sun May 27 2012 04:35:11 for ReactOS by
1.7.6.1
|