aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/config
diff options
context:
space:
mode:
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2001-09-10 01:00:27 +0000
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2001-09-10 01:00:27 +0000
commite1a0572dd809ae3defa258fd154e6d52d6058c57 (patch)
treeb815e508219cc05c103ba813878fb45c805615db /libstdc++-v3/config
parentdc556e720cc72825889ee99dca3e2c660b70e582 (diff)
2001-09-09 Benjamin Kosnik <bkoz@redhat.com>
Implement std::money_put. * include/bits/locale_facets.h (moneypunct::_M_initialize_moneypunct): Split up specializations to account for _Intl. More grody hacking to get around the ill-considered use of const bool as a template parameter. * config/locale/moneypunct_members_gnu.cc: And here. * config/locale/moneypunct_members_generic.cc: And here. * testsuite/22_locale/moneypunct_members_char.cc: Add tests. * testsuite/22_locale/moneypunct.cc: Add tests. * testsuite/22_locale/money_put_members_wchar_t.cc: New file. * testsuite/22_locale/moneypunct_members_wchar_t.cc: New file. * src/locale.cc (money_base::_S_construct_pattern): Move into gnu-specific file. * config/locale/moneypunct_members_gnu.cc: Add here. * config/locale/moneypunct_members_generic.cc: Add generic version here. * include/bits/locale_facets.tcc (money_put::do_put): Move member function definitions here. * include/bits/locale_facets.h (money_put): Implement. * src/locale-inst.cc: Add use_facet instantiations for moneypunct. Correct money_get, money_put instantiations. * src/locale.cc (money_base::_S_construct_pattern): Handle case where __posn == 0. * testsuite/22_locale/money_put_members_char.cc: Add tests. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@45496 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/config')
-rw-r--r--libstdc++-v3/config/locale/moneypunct_members_generic.cc42
-rw-r--r--libstdc++-v3/config/locale/moneypunct_members_gnu.cc357
2 files changed, 331 insertions, 68 deletions
diff --git a/libstdc++-v3/config/locale/moneypunct_members_generic.cc b/libstdc++-v3/config/locale/moneypunct_members_generic.cc
index 8c068718739..dd92443c0f7 100644
--- a/libstdc++-v3/config/locale/moneypunct_members_generic.cc
+++ b/libstdc++-v3/config/locale/moneypunct_members_generic.cc
@@ -37,9 +37,31 @@
namespace std
{
+ // Construct and return valid pattern consisting of some combination of:
+ // space none symbol sign value
+ money_base::pattern
+ money_base::_S_construct_pattern(char __preceeds, char __space, char __posn)
+ { return _S_default_pattern; }
+
+ template<>
+ void
+ moneypunct<char, true>::_M_initialize_moneypunct(__c_locale)
+ {
+ // "C" locale
+ _M_decimal_point = '.';
+ _M_thousands_sep = ',';
+ _M_grouping = "";
+ _M_curr_symbol = string_type();
+ _M_positive_sign = string_type();
+ _M_negative_sign = string_type();
+ _M_frac_digits = 0;
+ _M_pos_format = money_base::_S_default_pattern;
+ _M_neg_format = money_base::_S_default_pattern;
+ }
+
template<>
void
- moneypunct<char>::_M_initialize_moneypunct(__c_locale)
+ moneypunct<char, false>::_M_initialize_moneypunct(__c_locale)
{
// "C" locale
_M_decimal_point = '.';
@@ -56,7 +78,23 @@ namespace std
#ifdef _GLIBCPP_USE_WCHAR_T
template<>
void
- moneypunct<wchar_t>::_M_initialize_moneypunct(__c_locale)
+ moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale)
+ {
+ // "C" locale
+ _M_decimal_point = L'.';
+ _M_thousands_sep = L',';
+ _M_grouping = "";
+ _M_curr_symbol = string_type();
+ _M_positive_sign = string_type();
+ _M_negative_sign = string_type();
+ _M_frac_digits = 0;
+ _M_pos_format = money_base::_S_default_pattern;
+ _M_neg_format = money_base::_S_default_pattern;
+ }
+
+ template<>
+ void
+ moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale)
{
// "C" locale
_M_decimal_point = L'.';
diff --git a/libstdc++-v3/config/locale/moneypunct_members_gnu.cc b/libstdc++-v3/config/locale/moneypunct_members_gnu.cc
index d31c84a5386..83d647efbe2 100644
--- a/libstdc++-v3/config/locale/moneypunct_members_gnu.cc
+++ b/libstdc++-v3/config/locale/moneypunct_members_gnu.cc
@@ -37,9 +37,186 @@
namespace std
{
+ // Construct and return valid pattern consisting of some combination of:
+ // space none symbol sign value
+ money_base::pattern
+ money_base::_S_construct_pattern(char __preceeds, char __space, char __posn)
+ {
+ pattern __ret;
+
+ // This insanely complicated routine attempts to construct a valid
+ // pattern for use with monyepunct. A couple of invariants:
+
+ // if (__preceeds) symbol -> value
+ // else value -> symbol
+
+ // if (__space) space
+ // else none
+
+ // none == never first
+ // space never first or last
+
+ // Any elegant implementations of this are welcome.
+ switch (__posn)
+ {
+ case 0:
+ case 1:
+ // 1 The sign precedes the value and symbol.
+ if (__space)
+ {
+ // Pattern starts with sign.
+ if (__preceeds)
+ {
+ __ret.field[1] = symbol;
+ __ret.field[2] = space;
+ __ret.field[3] = value;
+ }
+ else
+ {
+ __ret.field[1] = value;
+ __ret.field[2] = space;
+ __ret.field[3] = symbol;
+ }
+ __ret.field[0] = sign;
+ }
+ else
+ {
+ // Pattern starts with sign and ends with none.
+ if (__preceeds)
+ {
+ __ret.field[1] = symbol;
+ __ret.field[2] = value;
+ }
+ else
+ {
+ __ret.field[1] = value;
+ __ret.field[2] = symbol;
+ }
+ __ret.field[0] = sign;
+ __ret.field[3] = none;
+ }
+ break;
+ case 2:
+ // 2 The sign follows the value and symbol.
+ if (__space)
+ {
+ // Pattern either ends with sign.
+ if (__preceeds)
+ {
+ __ret.field[0] = symbol;
+ __ret.field[1] = space;
+ __ret.field[2] = value;
+ }
+ else
+ {
+ __ret.field[0] = value;
+ __ret.field[1] = space;
+ __ret.field[2] = symbol;
+ }
+ __ret.field[3] = sign;
+ }
+ else
+ {
+ // Pattern ends with sign then none.
+ if (__preceeds)
+ {
+ __ret.field[0] = symbol;
+ __ret.field[1] = value;
+ }
+ else
+ {
+ __ret.field[0] = value;
+ __ret.field[1] = symbol;
+ }
+ __ret.field[2] = sign;
+ __ret.field[3] = none;
+ }
+ break;
+ case 3:
+ // 3 The sign immediately precedes the symbol.
+ if (__space)
+ {
+ // Have space.
+ if (__preceeds)
+ {
+ __ret.field[0] = sign;
+ __ret.field[1] = symbol;
+ __ret.field[2] = space;
+ __ret.field[3] = value;
+ }
+ else
+ {
+ __ret.field[0] = value;
+ __ret.field[1] = space;
+ __ret.field[2] = sign;
+ __ret.field[3] = symbol;
+ }
+ }
+ else
+ {
+ // Have none.
+ if (__preceeds)
+ {
+ __ret.field[0] = sign;
+ __ret.field[1] = symbol;
+ __ret.field[2] = value;
+ }
+ else
+ {
+ __ret.field[0] = value;
+ __ret.field[1] = sign;
+ __ret.field[2] = symbol;
+ }
+ __ret.field[3] = none;
+ }
+ break;
+ case 4:
+ // 4 The sign immediately follows the symbol.
+ if (__space)
+ {
+ // Have space.
+ if (__preceeds)
+ {
+ __ret.field[0] = symbol;
+ __ret.field[1] = sign;
+ __ret.field[2] = space;
+ __ret.field[3] = value;
+ }
+ else
+ {
+ __ret.field[0] = value;
+ __ret.field[1] = space;
+ __ret.field[2] = symbol;
+ __ret.field[3] = sign;
+ }
+ }
+ else
+ {
+ // Have none.
+ if (__preceeds)
+ {
+ __ret.field[0] = symbol;
+ __ret.field[1] = sign;
+ __ret.field[2] = value;
+ }
+ else
+ {
+ __ret.field[0] = value;
+ __ret.field[1] = symbol;
+ __ret.field[2] = sign;
+ }
+ __ret.field[3] = none;
+ }
+ break;
+ default:
+ ;
+ }
+ return __ret;
+ }
+
template<>
void
- moneypunct<char>::_M_initialize_moneypunct(__c_locale __cloc)
+ moneypunct<char, true>::_M_initialize_moneypunct(__c_locale __cloc)
{
if (!__cloc)
{
@@ -62,45 +239,69 @@ namespace std
_M_grouping = __nl_langinfo_l(__MON_GROUPING, __cloc);
_M_positive_sign = __nl_langinfo_l(__POSITIVE_SIGN, __cloc);
_M_negative_sign = __nl_langinfo_l(__NEGATIVE_SIGN, __cloc);
- if (intl)
- {
- _M_curr_symbol = __nl_langinfo_l(__INT_CURR_SYMBOL, __cloc);
- _M_frac_digits = *(__nl_langinfo_l(__INT_FRAC_DIGITS, __cloc));
- char __ppreceeds = *(__nl_langinfo_l(__INT_P_CS_PRECEDES,
- __cloc));
- char __pspace = *(__nl_langinfo_l(__INT_P_SEP_BY_SPACE, __cloc));
- char __pposn = *(__nl_langinfo_l(__INT_P_SIGN_POSN, __cloc));
- _M_pos_format = _S_construct_pattern(__ppreceeds, __pspace,
- __pposn);
- char __npreceeds = *(__nl_langinfo_l(__INT_N_CS_PRECEDES,
- __cloc));
- char __nspace = *(__nl_langinfo_l(__INT_N_SEP_BY_SPACE, __cloc));
- char __nposn = *(__nl_langinfo_l(__INT_N_SIGN_POSN, __cloc));
- _M_neg_format = _S_construct_pattern(__npreceeds, __nspace,
- __nposn);
- }
- else
- {
- _M_curr_symbol = __nl_langinfo_l(__CURRENCY_SYMBOL, __cloc);
- _M_frac_digits = *(__nl_langinfo_l(__FRAC_DIGITS, __cloc));
- char __ppreceeds = *(__nl_langinfo_l(__P_CS_PRECEDES, __cloc));
- char __pspace = *(__nl_langinfo_l(__P_SEP_BY_SPACE, __cloc));
- char __pposn = *(__nl_langinfo_l(__P_SIGN_POSN, __cloc));
- _M_pos_format = _S_construct_pattern(__ppreceeds, __pspace,
- __pposn);
- char __npreceeds = *(__nl_langinfo_l(__N_CS_PRECEDES, __cloc));
- char __nspace = *(__nl_langinfo_l(__N_SEP_BY_SPACE, __cloc));
- char __nposn = *(__nl_langinfo_l(__N_SIGN_POSN, __cloc));
- _M_neg_format = _S_construct_pattern(__npreceeds, __nspace,
- __nposn);
- }
+
+ // _Intl == true
+ _M_curr_symbol = __nl_langinfo_l(__INT_CURR_SYMBOL, __cloc);
+ _M_frac_digits = *(__nl_langinfo_l(__INT_FRAC_DIGITS, __cloc));
+ char __ppreceeds = *(__nl_langinfo_l(__INT_P_CS_PRECEDES, __cloc));
+ char __pspace = *(__nl_langinfo_l(__INT_P_SEP_BY_SPACE, __cloc));
+ char __pposn = *(__nl_langinfo_l(__INT_P_SIGN_POSN, __cloc));
+ _M_pos_format = _S_construct_pattern(__ppreceeds, __pspace, __pposn);
+ char __npreceeds = *(__nl_langinfo_l(__INT_N_CS_PRECEDES, __cloc));
+ char __nspace = *(__nl_langinfo_l(__INT_N_SEP_BY_SPACE, __cloc));
+ char __nposn = *(__nl_langinfo_l(__INT_N_SIGN_POSN, __cloc));
+ if (!__nposn)
+ _M_negative_sign = "()";
+ _M_neg_format = _S_construct_pattern(__npreceeds, __nspace, __nposn);
+ }
+ }
+
+ template<>
+ void
+ moneypunct<char, false>::_M_initialize_moneypunct(__c_locale __cloc)
+ {
+ if (!__cloc)
+ {
+ // "C" locale
+ _M_decimal_point = '.';
+ _M_thousands_sep = ',';
+ _M_grouping = "";
+ _M_curr_symbol = string_type();
+ _M_positive_sign = string_type();
+ _M_negative_sign = string_type();
+ _M_frac_digits = 0;
+ _M_pos_format = money_base::_S_default_pattern;
+ _M_neg_format = money_base::_S_default_pattern;
+ }
+ else
+ {
+ // Named locale.
+ _M_decimal_point = *(__nl_langinfo_l(__MON_DECIMAL_POINT, __cloc));
+ _M_thousands_sep = *(__nl_langinfo_l(__MON_THOUSANDS_SEP, __cloc));
+ _M_grouping = __nl_langinfo_l(__MON_GROUPING, __cloc);
+ _M_positive_sign = __nl_langinfo_l(__POSITIVE_SIGN, __cloc);
+ _M_negative_sign = __nl_langinfo_l(__NEGATIVE_SIGN, __cloc);
+
+ // _Intl == false
+ _M_curr_symbol = __nl_langinfo_l(__CURRENCY_SYMBOL, __cloc);
+ _M_frac_digits = *(__nl_langinfo_l(__FRAC_DIGITS, __cloc));
+ char __ppreceeds = *(__nl_langinfo_l(__P_CS_PRECEDES, __cloc));
+ char __pspace = *(__nl_langinfo_l(__P_SEP_BY_SPACE, __cloc));
+ char __pposn = *(__nl_langinfo_l(__P_SIGN_POSN, __cloc));
+ _M_pos_format = _S_construct_pattern(__ppreceeds, __pspace, __pposn);
+ char __npreceeds = *(__nl_langinfo_l(__N_CS_PRECEDES, __cloc));
+ char __nspace = *(__nl_langinfo_l(__N_SEP_BY_SPACE, __cloc));
+ char __nposn = *(__nl_langinfo_l(__N_SIGN_POSN, __cloc));
+ if (!__nposn)
+ _M_negative_sign = "()";
+ _M_neg_format = _S_construct_pattern(__npreceeds, __nspace, __nposn);
}
}
#ifdef _GLIBCPP_USE_WCHAR_T
template<>
void
- moneypunct<wchar_t>::_M_initialize_moneypunct(__c_locale __cloc)
+ moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale __cloc)
{
if (!__cloc)
{
@@ -123,38 +324,62 @@ namespace std
_M_grouping = __nl_langinfo_l(GROUPING, __cloc);
_M_positive_sign = reinterpret_cast<wchar_t*>(__nl_langinfo_l(__POSITIVE_SIGN, __cloc));
_M_negative_sign = reinterpret_cast<wchar_t*>(__nl_langinfo_l(__NEGATIVE_SIGN, __cloc));
- if (intl)
- {
- _M_curr_symbol = reinterpret_cast<wchar_t*>(__nl_langinfo_l(__INT_CURR_SYMBOL, __cloc));
- _M_frac_digits = *(__nl_langinfo_l(__INT_FRAC_DIGITS, __cloc));
- char __ppreceeds = *(__nl_langinfo_l(__INT_P_CS_PRECEDES,
- __cloc));
- char __pspace = *(__nl_langinfo_l(__INT_P_SEP_BY_SPACE, __cloc));
- char __pposn = *(__nl_langinfo_l(__INT_P_SIGN_POSN, __cloc));
- _M_pos_format = _S_construct_pattern(__ppreceeds, __pspace,
- __pposn);
- char __npreceeds = *(__nl_langinfo_l(__INT_N_CS_PRECEDES,
- __cloc));
- char __nspace = *(__nl_langinfo_l(__INT_N_SEP_BY_SPACE, __cloc));
- char __nposn = *(__nl_langinfo_l(__INT_N_SIGN_POSN, __cloc));
- _M_neg_format = _S_construct_pattern(__npreceeds, __nspace,
- __nposn);
- }
- else
- {
- _M_curr_symbol = reinterpret_cast<wchar_t*>(__nl_langinfo_l(__CURRENCY_SYMBOL, __cloc));
- _M_frac_digits = *(__nl_langinfo_l(__FRAC_DIGITS, __cloc));
- char __ppreceeds = *(__nl_langinfo_l(__P_CS_PRECEDES, __cloc));
- char __pspace = *(__nl_langinfo_l(__P_SEP_BY_SPACE, __cloc));
- char __pposn = *(__nl_langinfo_l(__P_SIGN_POSN, __cloc));
- _M_pos_format = _S_construct_pattern(__ppreceeds, __pspace,
- __pposn);
- char __npreceeds = *(__nl_langinfo_l(__N_CS_PRECEDES, __cloc));
- char __nspace = *(__nl_langinfo_l(__N_SEP_BY_SPACE, __cloc));
- char __nposn = *(__nl_langinfo_l(__N_SIGN_POSN, __cloc));
- _M_neg_format = _S_construct_pattern(__npreceeds, __nspace,
- __nposn);
- }
+
+ // _Intl == true.
+ _M_curr_symbol = reinterpret_cast<wchar_t*>(__nl_langinfo_l(__INT_CURR_SYMBOL, __cloc));
+ _M_frac_digits = *(__nl_langinfo_l(__INT_FRAC_DIGITS, __cloc));
+ char __ppreceeds = *(__nl_langinfo_l(__INT_P_CS_PRECEDES, __cloc));
+ char __pspace = *(__nl_langinfo_l(__INT_P_SEP_BY_SPACE, __cloc));
+ char __pposn = *(__nl_langinfo_l(__INT_P_SIGN_POSN, __cloc));
+ _M_pos_format = _S_construct_pattern(__ppreceeds, __pspace, __pposn);
+ char __npreceeds = *(__nl_langinfo_l(__INT_N_CS_PRECEDES, __cloc));
+ char __nspace = *(__nl_langinfo_l(__INT_N_SEP_BY_SPACE, __cloc));
+ char __nposn = *(__nl_langinfo_l(__INT_N_SIGN_POSN, __cloc));
+ if (!__nposn)
+ _M_negative_sign = L"()";
+ _M_neg_format = _S_construct_pattern(__npreceeds, __nspace, __nposn);
+ }
+ }
+
+ template<>
+ void
+ moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale __cloc)
+ {
+ if (!__cloc)
+ {
+ // "C" locale
+ _M_decimal_point = L'.';
+ _M_thousands_sep = L',';
+ _M_grouping = "";
+ _M_curr_symbol = string_type();
+ _M_positive_sign = string_type();
+ _M_negative_sign = string_type();
+ _M_frac_digits = 0;
+ _M_pos_format = money_base::_S_default_pattern;
+ _M_neg_format = money_base::_S_default_pattern;
+ }
+ else
+ {
+ // Named locale.
+ _M_decimal_point = reinterpret_cast<wchar_t>(__nl_langinfo_l(_NL_NUMERIC_DECIMAL_POINT_WC, __cloc));
+ _M_thousands_sep = reinterpret_cast<wchar_t>(__nl_langinfo_l(_NL_NUMERIC_THOUSANDS_SEP_WC,__cloc));
+ _M_grouping = __nl_langinfo_l(GROUPING, __cloc);
+ _M_positive_sign = reinterpret_cast<wchar_t*>(__nl_langinfo_l(__POSITIVE_SIGN, __cloc));
+ _M_negative_sign = reinterpret_cast<wchar_t*>(__nl_langinfo_l(__NEGATIVE_SIGN, __cloc));
+
+ // _Intl == false.
+ _M_curr_symbol = reinterpret_cast<wchar_t*>(__nl_langinfo_l(__CURRENCY_SYMBOL, __cloc));
+ _M_frac_digits = *(__nl_langinfo_l(__FRAC_DIGITS, __cloc));
+ char __ppreceeds = *(__nl_langinfo_l(__P_CS_PRECEDES, __cloc));
+ char __pspace = *(__nl_langinfo_l(__P_SEP_BY_SPACE, __cloc));
+ char __pposn = *(__nl_langinfo_l(__P_SIGN_POSN, __cloc));
+ _M_pos_format = _S_construct_pattern(__ppreceeds, __pspace, __pposn);
+ char __npreceeds = *(__nl_langinfo_l(__N_CS_PRECEDES, __cloc));
+ char __nspace = *(__nl_langinfo_l(__N_SEP_BY_SPACE, __cloc));
+ char __nposn = *(__nl_langinfo_l(__N_SIGN_POSN, __cloc));
+ if (!__nposn)
+ _M_negative_sign = L"()";
+ _M_neg_format = _S_construct_pattern(__npreceeds, __nspace, __nposn);
}
}
#endif