diff options
author | Paolo Carlini <pcarlini@suse.de> | 2004-02-21 09:26:35 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2004-02-21 09:26:35 +0000 |
commit | fe932e504bb0efaaa874d1caffdc25e4d34c5484 (patch) | |
tree | 658b1a60aa9e4e6e7272da508ab2dff3e4f6d74b /libstdc++-v3/config/locale | |
parent | 8bb418a3d5c47572c382c7b8f195526247c02a1f (diff) | |
download | gcc-fe932e504bb0efaaa874d1caffdc25e4d34c5484.zip gcc-fe932e504bb0efaaa874d1caffdc25e4d34c5484.tar.gz gcc-fe932e504bb0efaaa874d1caffdc25e4d34c5484.tar.bz2 |
locale_facets.h (class money_base): Add { _S_minus, _S_zero, _S_end } enum, _S_atoms.
2004-02-21 Paolo Carlini <pcarlini@suse.de>
* include/bits/locale_facets.h (class money_base): Add { _S_minus,
_S_zero, _S_end } enum, _S_atoms.
(struct __moneypunct_cache<>): Parameterize on _Intl too; add
_M_grouping_size, _M_curr_symbol_size, _M_positive_sign_size,
_M_negative_sign_size, _M_atoms; tweak constructor consistently.
(__moneypunct_cache<>::~__moneypunct_cache): Update.
(__moneypunct_cache<>::_M_cache): Fill the cache.
(class moneypunct): Tweak __cache_type typedef.
(class money_put): Inherit from money_base too; tweak declaration
of _M_insert, now parameterized on _Intl.
* include/bits/locale_facets.tcc
(struct __use_cache<__moneypunct_cache<_CharT, _Intl> >): New.
(money_put<>::_M_insert): Update definition to use the cache;
call reserve on __res to avoid multiple reallocations.
(money_put<>::do_put(long double),
money_put<>::do_put(const string_type&): Update calls of _M_insert.
* config/locale/generic/monetary_members.cc
(moneypunct<char, true>::_M_initialize_moneypunct,
moneypunct<char, false>::_M_initialize_moneypunct,
moneypunct<wchar_t, true>::_M_initialize_moneypunct,
moneypunct<wchar_t, false>::_M_initialize_moneypunct): Update.
* config/locale/gnu/monetary_members.cc: Likewise.
* config/locale/gnu/monetary_members.cc
(moneypunct<wchar_t, true>::~moneypunct(),
moneypunct<wchar_t, false>::~moneypunct()): Likewise.
* src/globals_locale.cc: Tweak fake_money_cache_c.
* src/locale-inst.cc: Add instantiations for
money_put::_M_insert<false> and money_put::_M_insert<true> and
__moneypunct_cache<C, false>, __moneypunct_cache<C, true>.
* src/locale_facets.cc: Define money_base::_S_atoms.
* src/locale_init.cc: Update placement new of
__moneypunct_cache<char, false>, __moneypunct_cache<char, true>,
__moneypunct_cache<wchar_t, false>, __moneypunct_cache<wchar_T, true>.
* config/locale/generic/numeric_members.cc: Clean up.
* config/locale/gnu/numeric_members.cc: Likewise.
* testsuite/22_locale/money_put/put/char/1.cc: Likewise.
* testsuite/22_locale/money_put/put/char/2.cc: Likewise.
* testsuite/22_locale/money_put/put/char/3.cc: Likewise.
* testsuite/22_locale/money_put/put/wchar_t/1.cc: Likewise.
* testsuite/22_locale/money_put/put/wchar_t/2.cc: Likewise.
* testsuite/22_locale/money_put/put/wchar_t/3.cc: Likewise.
From-SVN: r78216
Diffstat (limited to 'libstdc++-v3/config/locale')
4 files changed, 115 insertions, 25 deletions
diff --git a/libstdc++-v3/config/locale/generic/monetary_members.cc b/libstdc++-v3/config/locale/generic/monetary_members.cc index 51bbe0b..957a326 100644 --- a/libstdc++-v3/config/locale/generic/monetary_members.cc +++ b/libstdc++-v3/config/locale/generic/monetary_members.cc @@ -1,6 +1,6 @@ // std::moneypunct implementation details, generic version -*- C++ -*- -// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -49,17 +49,24 @@ namespace std { // "C" locale. if (!_M_data) - _M_data = new __moneypunct_cache<char>; + _M_data = new __moneypunct_cache<char, true>; _M_data->_M_decimal_point = '.'; _M_data->_M_thousands_sep = ','; _M_data->_M_grouping = ""; + _M_data->_M_grouping_size = 0; _M_data->_M_curr_symbol = ""; + _M_data->_M_curr_symbol_size = 0; _M_data->_M_positive_sign = ""; + _M_data->_M_positive_sign_size = 0; _M_data->_M_negative_sign = ""; + _M_data->_M_negative_sign_size = 0; _M_data->_M_frac_digits = 0; _M_data->_M_pos_format = money_base::_S_default_pattern; _M_data->_M_neg_format = money_base::_S_default_pattern; + + for (size_t __i = 0; __i < money_base::_S_end; ++__i) + _M_data->_M_atoms[__i] = money_base::_S_atoms[__i]; } template<> @@ -68,17 +75,24 @@ namespace std { // "C" locale. if (!_M_data) - _M_data = new __moneypunct_cache<char>; + _M_data = new __moneypunct_cache<char, false>; _M_data->_M_decimal_point = '.'; _M_data->_M_thousands_sep = ','; _M_data->_M_grouping = ""; + _M_data->_M_grouping_size = 0; _M_data->_M_curr_symbol = ""; + _M_data->_M_curr_symbol_size = 0; _M_data->_M_positive_sign = ""; + _M_data->_M_positive_sign_size = 0; _M_data->_M_negative_sign = ""; + _M_data->_M_negative_sign_size = 0; _M_data->_M_frac_digits = 0; _M_data->_M_pos_format = money_base::_S_default_pattern; _M_data->_M_neg_format = money_base::_S_default_pattern; + + for (size_t __i = 0; __i < money_base::_S_end; ++__i) + _M_data->_M_atoms[__i] = money_base::_S_atoms[__i]; } template<> @@ -97,17 +111,28 @@ namespace std { // "C" locale if (!_M_data) - _M_data = new __moneypunct_cache<wchar_t>; + _M_data = new __moneypunct_cache<wchar_t, true>; _M_data->_M_decimal_point = L'.'; _M_data->_M_thousands_sep = L','; _M_data->_M_grouping = ""; + _M_data->_M_grouping_size = 0; _M_data->_M_curr_symbol = L""; + _M_data->_M_curr_symbol_size = 0; _M_data->_M_positive_sign = L""; + _M_data->_M_positive_sign_size = 0; _M_data->_M_negative_sign = L""; + _M_data->_M_negative_sign_size = 0; _M_data->_M_frac_digits = 0; _M_data->_M_pos_format = money_base::_S_default_pattern; _M_data->_M_neg_format = money_base::_S_default_pattern; + + unsigned char uc; + for (size_t __i = 0; __i < money_base::_S_end; ++__i) + { + uc = static_cast<unsigned char>(money_base::_S_atoms[__i]); + _M_data->_M_atoms[__i] = btowc(uc); + } } template<> @@ -117,17 +142,28 @@ namespace std { // "C" locale if (!_M_data) - _M_data = new __moneypunct_cache<wchar_t>; + _M_data = new __moneypunct_cache<wchar_t, false>; _M_data->_M_decimal_point = L'.'; _M_data->_M_thousands_sep = L','; _M_data->_M_grouping = ""; + _M_data->_M_grouping_size = 0; _M_data->_M_curr_symbol = L""; + _M_data->_M_curr_symbol_size = 0; _M_data->_M_positive_sign = L""; + _M_data->_M_positive_sign_size = 0; _M_data->_M_negative_sign = L""; + _M_data->_M_negative_sign_size = 0; _M_data->_M_frac_digits = 0; _M_data->_M_pos_format = money_base::_S_default_pattern; _M_data->_M_neg_format = money_base::_S_default_pattern; + + unsigned char uc; + for (size_t __i = 0; __i < money_base::_S_end; ++__i) + { + uc = static_cast<unsigned char>(money_base::_S_atoms[__i]); + _M_data->_M_atoms[__i] = btowc(uc); + } } template<> diff --git a/libstdc++-v3/config/locale/generic/numeric_members.cc b/libstdc++-v3/config/locale/generic/numeric_members.cc index 0645865..e2afed9 100644 --- a/libstdc++-v3/config/locale/generic/numeric_members.cc +++ b/libstdc++-v3/config/locale/generic/numeric_members.cc @@ -46,6 +46,7 @@ namespace std _M_data = new __numpunct_cache<char>; _M_data->_M_grouping = ""; + _M_data->_M_grouping_size = 0; _M_data->_M_use_grouping = false; _M_data->_M_decimal_point = '.'; @@ -57,8 +58,6 @@ namespace std for (size_t __i = 0; __i < __num_base::_S_iend; ++__i) _M_data->_M_atoms_in[__i] = __num_base::_S_atoms_in[__i]; - _M_data->_M_grouping_size = strlen(_M_data->_M_grouping); - _M_data->_M_truename = "true"; _M_data->_M_truename_size = strlen(_M_data->_M_truename); _M_data->_M_falsename = "false"; @@ -79,6 +78,7 @@ namespace std _M_data = new __numpunct_cache<wchar_t>; _M_data->_M_grouping = ""; + _M_data->_M_grouping_size = 0; _M_data->_M_use_grouping = false; _M_data->_M_decimal_point = L'.'; @@ -98,8 +98,6 @@ namespace std _M_data->_M_atoms_in[__i] = btowc(uc); } - _M_data->_M_grouping_size = strlen(_M_data->_M_grouping); - _M_data->_M_truename = L"true"; _M_data->_M_truename_size = wcslen(_M_data->_M_truename); _M_data->_M_falsename = L"false"; diff --git a/libstdc++-v3/config/locale/gnu/monetary_members.cc b/libstdc++-v3/config/locale/gnu/monetary_members.cc index a2aa0c5..63bcdd8 100644 --- a/libstdc++-v3/config/locale/gnu/monetary_members.cc +++ b/libstdc++-v3/config/locale/gnu/monetary_members.cc @@ -210,7 +210,7 @@ namespace std const char*) { if (!_M_data) - _M_data = new __moneypunct_cache<char>; + _M_data = new __moneypunct_cache<char, true>; if (!__cloc) { @@ -218,12 +218,19 @@ namespace std _M_data->_M_decimal_point = '.'; _M_data->_M_thousands_sep = ','; _M_data->_M_grouping = ""; + _M_data->_M_grouping_size = 0; _M_data->_M_curr_symbol = ""; + _M_data->_M_curr_symbol_size = 0; _M_data->_M_positive_sign = ""; + _M_data->_M_positive_sign_size = 0; _M_data->_M_negative_sign = ""; + _M_data->_M_negative_sign_size = 0; _M_data->_M_frac_digits = 0; _M_data->_M_pos_format = money_base::_S_default_pattern; _M_data->_M_neg_format = money_base::_S_default_pattern; + + for (size_t __i = 0; __i < money_base::_S_end; ++__i) + _M_data->_M_atoms[__i] = money_base::_S_atoms[__i]; } else { @@ -233,7 +240,9 @@ namespace std _M_data->_M_thousands_sep = *(__nl_langinfo_l(__MON_THOUSANDS_SEP, __cloc)); _M_data->_M_grouping = __nl_langinfo_l(__MON_GROUPING, __cloc); + _M_data->_M_grouping_size = strlen(_M_data->_M_grouping); _M_data->_M_positive_sign = __nl_langinfo_l(__POSITIVE_SIGN, __cloc); + _M_data->_M_positive_sign_size = strlen(_M_data->_M_positive_sign); char __nposn = *(__nl_langinfo_l(__INT_N_SIGN_POSN, __cloc)); if (!__nposn) @@ -241,9 +250,11 @@ namespace std else _M_data->_M_negative_sign = __nl_langinfo_l(__NEGATIVE_SIGN, __cloc); + _M_data->_M_negative_sign_size = strlen(_M_data->_M_negative_sign); // _Intl == true _M_data->_M_curr_symbol = __nl_langinfo_l(__INT_CURR_SYMBOL, __cloc); + _M_data->_M_curr_symbol_size = strlen(_M_data->_M_curr_symbol); _M_data->_M_frac_digits = *(__nl_langinfo_l(__INT_FRAC_DIGITS, __cloc)); char __pprecedes = *(__nl_langinfo_l(__INT_P_CS_PRECEDES, __cloc)); @@ -264,7 +275,7 @@ namespace std const char*) { if (!_M_data) - _M_data = new __moneypunct_cache<char>; + _M_data = new __moneypunct_cache<char, false>; if (!__cloc) { @@ -272,12 +283,19 @@ namespace std _M_data->_M_decimal_point = '.'; _M_data->_M_thousands_sep = ','; _M_data->_M_grouping = ""; + _M_data->_M_grouping_size = 0; _M_data->_M_curr_symbol = ""; + _M_data->_M_curr_symbol_size = 0; _M_data->_M_positive_sign = ""; + _M_data->_M_positive_sign_size = 0; _M_data->_M_negative_sign = ""; + _M_data->_M_negative_sign_size = 0; _M_data->_M_frac_digits = 0; _M_data->_M_pos_format = money_base::_S_default_pattern; _M_data->_M_neg_format = money_base::_S_default_pattern; + + for (size_t __i = 0; __i < money_base::_S_end; ++__i) + _M_data->_M_atoms[__i] = money_base::_S_atoms[__i]; } else { @@ -287,17 +305,21 @@ namespace std _M_data->_M_thousands_sep = *(__nl_langinfo_l(__MON_THOUSANDS_SEP, __cloc)); _M_data->_M_grouping = __nl_langinfo_l(__MON_GROUPING, __cloc); + _M_data->_M_grouping_size = strlen(_M_data->_M_grouping); _M_data->_M_positive_sign = __nl_langinfo_l(__POSITIVE_SIGN, __cloc); + _M_data->_M_positive_sign_size = strlen(_M_data->_M_positive_sign); char __nposn = *(__nl_langinfo_l(__N_SIGN_POSN, __cloc)); if (!__nposn) _M_data->_M_negative_sign = "()"; else - _M_data->_M_negative_sign = __nl_langinfo_l(__NEGATIVE_SIGN, + _M_data->_M_negative_sign = __nl_langinfo_l(__NEGATIVE_SIGN, __cloc); + _M_data->_M_negative_sign_size = strlen(_M_data->_M_negative_sign); // _Intl == false _M_data->_M_curr_symbol = __nl_langinfo_l(__CURRENCY_SYMBOL, __cloc); + _M_data->_M_curr_symbol_size = strlen(_M_data->_M_curr_symbol); _M_data->_M_frac_digits = *(__nl_langinfo_l(__FRAC_DIGITS, __cloc)); char __pprecedes = *(__nl_langinfo_l(__P_CS_PRECEDES, __cloc)); char __pspace = *(__nl_langinfo_l(__P_SEP_BY_SPACE, __cloc)); @@ -330,7 +352,7 @@ namespace std #endif { if (!_M_data) - _M_data = new __moneypunct_cache<wchar_t>; + _M_data = new __moneypunct_cache<wchar_t, true>; if (!__cloc) { @@ -338,12 +360,24 @@ namespace std _M_data->_M_decimal_point = L'.'; _M_data->_M_thousands_sep = L','; _M_data->_M_grouping = ""; + _M_data->_M_grouping_size = 0; _M_data->_M_curr_symbol = L""; + _M_data->_M_curr_symbol_size = 0; _M_data->_M_positive_sign = L""; + _M_data->_M_positive_sign_size = 0; _M_data->_M_negative_sign = L""; + _M_data->_M_negative_sign_size = 0; _M_data->_M_frac_digits = 0; _M_data->_M_pos_format = money_base::_S_default_pattern; _M_data->_M_neg_format = money_base::_S_default_pattern; + + // Use ctype::widen code without the facet... + unsigned char uc; + for (size_t __i = 0; __i < money_base::_S_end; ++__i) + { + uc = static_cast<unsigned char>(money_base::_S_atoms[__i]); + _M_data->_M_atoms[__i] = btowc(uc); + } } else { @@ -363,6 +397,7 @@ namespace std __u.__s = __nl_langinfo_l(_NL_NUMERIC_THOUSANDS_SEP_WC, __cloc); _M_data->_M_thousands_sep = static_cast<wchar_t>(__u.__w); _M_data->_M_grouping = __nl_langinfo_l(GROUPING, __cloc); + _M_data->_M_grouping_size = strlen(_M_data->_M_grouping); const char* __cpossign = __nl_langinfo_l(__POSITIVE_SIGN, __cloc); const char* __cnegsign = __nl_langinfo_l(__NEGATIVE_SIGN, __cloc); @@ -385,6 +420,7 @@ namespace std } else _M_data->_M_positive_sign = L""; + _M_data->_M_positive_sign_size = wcslen(_M_data->_M_positive_sign); __len = strlen(__cnegsign); if (!__nposn) @@ -399,6 +435,7 @@ namespace std } else _M_data->_M_negative_sign = L""; + _M_data->_M_negative_sign_size = wcslen(_M_data->_M_negative_sign); // _Intl == true. __len = strlen(__ccurr); @@ -412,6 +449,7 @@ namespace std } else _M_data->_M_curr_symbol = L""; + _M_data->_M_curr_symbol_size = wcslen(_M_data->_M_curr_symbol); } catch (...) { @@ -459,7 +497,7 @@ namespace std #endif { if (!_M_data) - _M_data = new __moneypunct_cache<wchar_t>; + _M_data = new __moneypunct_cache<wchar_t, false>; if (!__cloc) { @@ -467,12 +505,24 @@ namespace std _M_data->_M_decimal_point = L'.'; _M_data->_M_thousands_sep = L','; _M_data->_M_grouping = ""; + _M_data->_M_grouping_size = 0; _M_data->_M_curr_symbol = L""; + _M_data->_M_curr_symbol_size = 0; _M_data->_M_positive_sign = L""; + _M_data->_M_positive_sign_size = 0; _M_data->_M_negative_sign = L""; + _M_data->_M_negative_sign_size = 0; _M_data->_M_frac_digits = 0; _M_data->_M_pos_format = money_base::_S_default_pattern; _M_data->_M_neg_format = money_base::_S_default_pattern; + + // Use ctype::widen code without the facet... + unsigned char uc; + for (size_t __i = 0; __i < money_base::_S_end; ++__i) + { + uc = static_cast<unsigned char>(money_base::_S_atoms[__i]); + _M_data->_M_atoms[__i] = btowc(uc); + } } else { @@ -492,6 +542,7 @@ namespace std __u.__s = __nl_langinfo_l(_NL_NUMERIC_THOUSANDS_SEP_WC, __cloc); _M_data->_M_thousands_sep = static_cast<wchar_t>(__u.__w); _M_data->_M_grouping = __nl_langinfo_l(GROUPING, __cloc); + _M_data->_M_grouping_size = strlen(_M_data->_M_grouping); const char* __cpossign = __nl_langinfo_l(__POSITIVE_SIGN, __cloc); const char* __cnegsign = __nl_langinfo_l(__NEGATIVE_SIGN, __cloc); @@ -515,6 +566,7 @@ namespace std } else _M_data->_M_positive_sign = L""; + _M_data->_M_positive_sign_size = wcslen(_M_data->_M_positive_sign); __len = strlen(__cnegsign); if (!__nposn) @@ -529,7 +581,8 @@ namespace std } else _M_data->_M_negative_sign = L""; - + _M_data->_M_negative_sign_size = wcslen(_M_data->_M_negative_sign); + // _Intl == true. __len = strlen(__ccurr); if (__len) @@ -542,6 +595,7 @@ namespace std } else _M_data->_M_curr_symbol = L""; + _M_data->_M_curr_symbol_size = wcslen(_M_data->_M_curr_symbol); } catch (...) { @@ -581,12 +635,12 @@ namespace std template<> moneypunct<wchar_t, true>::~moneypunct() { - if (wcslen(_M_data->_M_positive_sign)) + if (_M_data->_M_positive_sign_size) delete [] _M_data->_M_positive_sign; - if (wcslen(_M_data->_M_negative_sign) - && (wcscmp(_M_data->_M_negative_sign, L"()") != 0)) + if (_M_data->_M_negative_sign_size + && wcscmp(_M_data->_M_negative_sign, L"()") != 0) delete [] _M_data->_M_negative_sign; - if (wcslen(_M_data->_M_curr_symbol)) + if (_M_data->_M_curr_symbol_size) delete [] _M_data->_M_curr_symbol; delete _M_data; } @@ -594,12 +648,12 @@ namespace std template<> moneypunct<wchar_t, false>::~moneypunct() { - if (wcslen(_M_data->_M_positive_sign)) + if (_M_data->_M_positive_sign_size) delete [] _M_data->_M_positive_sign; - if (wcslen(_M_data->_M_negative_sign) - && (wcscmp(_M_data->_M_negative_sign, L"()") != 0)) + if (_M_data->_M_negative_sign_size + && wcscmp(_M_data->_M_negative_sign, L"()") != 0) delete [] _M_data->_M_negative_sign; - if (wcslen(_M_data->_M_curr_symbol)) + if (_M_data->_M_curr_symbol_size) delete [] _M_data->_M_curr_symbol; delete _M_data; } diff --git a/libstdc++-v3/config/locale/gnu/numeric_members.cc b/libstdc++-v3/config/locale/gnu/numeric_members.cc index debee10..e2bb089 100644 --- a/libstdc++-v3/config/locale/gnu/numeric_members.cc +++ b/libstdc++-v3/config/locale/gnu/numeric_members.cc @@ -49,6 +49,7 @@ namespace std { // "C" locale _M_data->_M_grouping = ""; + _M_data->_M_grouping_size = 0; _M_data->_M_use_grouping = false; _M_data->_M_decimal_point = '.'; @@ -71,8 +72,8 @@ namespace std _M_data->_M_grouping = ""; else _M_data->_M_grouping = __nl_langinfo_l(GROUPING, __cloc); + _M_data->_M_grouping_size = strlen(_M_data->_M_grouping); } - _M_data->_M_grouping_size = strlen(_M_data->_M_grouping); // NB: There is no way to extact this info from posix locales. // _M_truename = __nl_langinfo_l(YESSTR, __cloc); @@ -99,6 +100,7 @@ namespace std { // "C" locale _M_data->_M_grouping = ""; + _M_data->_M_grouping_size = 0; _M_data->_M_use_grouping = false; _M_data->_M_decimal_point = L'.'; @@ -138,8 +140,8 @@ namespace std _M_data->_M_grouping = ""; else _M_data->_M_grouping = __nl_langinfo_l(GROUPING, __cloc); + _M_data->_M_grouping_size = strlen(_M_data->_M_grouping); } - _M_data->_M_grouping_size = strlen(_M_data->_M_grouping); // NB: There is no way to extact this info from posix locales. // _M_truename = __nl_langinfo_l(YESSTR, __cloc); |