locale_facets.tcc (money_put::do_put): For the space field use __fill instead of ' ', uniformly.

2002-02-18  Paolo Carlini  <pcarlini@unitus.it>

	libstdc++/5708
	* include/bits/locale_facets.tcc (money_put::do_put):
	For the space field use __fill instead of ' ', uniformly.
	* testsuite/22_locale/money_put_members_char.cc:
	Add test05 distilled from PR.
	(test01-02-03): Trim some '*' to ' '.
	* testsuite/22_locale/money_put_members_wchar_t.cc: Ditto.

From-SVN: r49847
This commit is contained in:
Paolo Carlini 2002-02-18 22:23:26 +01:00 committed by Paolo Carlini
parent 3fcfe88d19
commit 577f406186
4 changed files with 117 additions and 29 deletions

View File

@ -1,3 +1,13 @@
2002-02-18 Paolo Carlini <pcarlini@unitus.it>
libstdc++/5708
* include/bits/locale_facets.tcc (money_put::do_put):
For the space field use __fill instead of ' ', uniformly.
* testsuite/22_locale/money_put_members_char.cc:
Add test05 distilled from PR.
(test01-02-03): Trim some '*' to ' '.
* testsuite/22_locale/money_put_members_wchar_t.cc: Ditto.
2002-02-18 Loren Rittle <ljrittle@acm.org> 2002-02-18 Loren Rittle <ljrittle@acm.org>
libstdc++/5697 libstdc++/5697

View File

@ -1230,7 +1230,7 @@ namespace std
if (__testipad) if (__testipad)
__res += string_type(__width - __len, __fill); __res += string_type(__width - __len, __fill);
else else
__res += __ctype.widen(' '); __res += __ctype.widen(__fill);
break; break;
case money_base::none: case money_base::none:
if (__testipad) if (__testipad)

View File

@ -79,12 +79,12 @@ void test01()
const money_put<char>& mon_put = use_facet<money_put<char> >(oss.getloc()); const money_put<char>& mon_put = use_facet<money_put<char> >(oss.getloc());
iterator_type os_it01 = mon_put.put(oss.rdbuf(), true, oss, '*', digits1); iterator_type os_it01 = mon_put.put(oss.rdbuf(), true, oss, ' ', digits1);
string result1 = oss.str(); string result1 = oss.str();
VERIFY( result1 == "7.200.000.000,00 "); VERIFY( result1 == "7.200.000.000,00 ");
oss.str(empty); oss.str(empty);
iterator_type os_it02 = mon_put.put(oss.rdbuf(), false, oss, '*', digits1); iterator_type os_it02 = mon_put.put(oss.rdbuf(), false, oss, ' ', digits1);
string result2 = oss.str(); string result2 = oss.str();
VERIFY( result2 == "7.200.000.000,00 "); VERIFY( result2 == "7.200.000.000,00 ");
@ -95,12 +95,12 @@ void test01()
oss.setf(ios_base::showbase); oss.setf(ios_base::showbase);
oss.str(empty); oss.str(empty);
iterator_type os_it03 = mon_put.put(oss.rdbuf(), true, oss, '*', digits1); iterator_type os_it03 = mon_put.put(oss.rdbuf(), true, oss, ' ', digits1);
string result3 = oss.str(); string result3 = oss.str();
VERIFY( result3 == "7.200.000.000,00 DEM "); VERIFY( result3 == "7.200.000.000,00 DEM ");
oss.str(empty); oss.str(empty);
iterator_type os_it04 = mon_put.put(oss.rdbuf(), false, oss, '*', digits1); iterator_type os_it04 = mon_put.put(oss.rdbuf(), false, oss, ' ', digits1);
string result4 = oss.str(); string result4 = oss.str();
VERIFY( result4 == "7.200.000.000,00 DM"); VERIFY( result4 == "7.200.000.000,00 DM");
@ -112,26 +112,26 @@ void test01()
// test sign of more than one digit, say hong kong. // test sign of more than one digit, say hong kong.
oss.imbue(loc_hk); oss.imbue(loc_hk);
oss.str(empty); oss.str(empty);
iterator_type os_it05 = mon_put.put(oss.rdbuf(), false, oss, '*', digits1); iterator_type os_it05 = mon_put.put(oss.rdbuf(), false, oss, ' ', digits1);
string result5 = oss.str(); string result5 = oss.str();
VERIFY( result5 == "HK$7,200,000,000.00"); VERIFY( result5 == "HK$7,200,000,000.00");
oss.str(empty); oss.str(empty);
iterator_type os_it06 = mon_put.put(oss.rdbuf(), true, oss, '*', digits2); iterator_type os_it06 = mon_put.put(oss.rdbuf(), true, oss, ' ', digits2);
string result6 = oss.str(); string result6 = oss.str();
VERIFY( result6 == "(HKD 100,000,000,000.00)"); VERIFY( result6 == "(HKD 100,000,000,000.00)");
// test one-digit formats without zero padding // test one-digit formats without zero padding
oss.imbue(loc_c); oss.imbue(loc_c);
oss.str(empty); oss.str(empty);
iterator_type os_it07 = mon_put.put(oss.rdbuf(), true, oss, '*', digits4); iterator_type os_it07 = mon_put.put(oss.rdbuf(), true, oss, ' ', digits4);
string result7 = oss.str(); string result7 = oss.str();
VERIFY( result7 == "1"); VERIFY( result7 == "1");
// test one-digit formats with zero padding, zero frac widths // test one-digit formats with zero padding, zero frac widths
oss.imbue(loc_hk); oss.imbue(loc_hk);
oss.str(empty); oss.str(empty);
iterator_type os_it08 = mon_put.put(oss.rdbuf(), true, oss, '*', digits4); iterator_type os_it08 = mon_put.put(oss.rdbuf(), true, oss, ' ', digits4);
string result8 = oss.str(); string result8 = oss.str();
VERIFY( result8 == "(HKD .01)"); VERIFY( result8 == "(HKD .01)");
@ -139,7 +139,7 @@ void test01()
// test bunk input // test bunk input
oss.str(empty); oss.str(empty);
iterator_type os_it09 = mon_put.put(oss.rdbuf(), true, oss, '*', digits3); iterator_type os_it09 = mon_put.put(oss.rdbuf(), true, oss, ' ', digits3);
string result9 = oss.str(); string result9 = oss.str();
VERIFY( result9 == ""); VERIFY( result9 == "");
@ -151,7 +151,7 @@ void test01()
oss.width(20); oss.width(20);
iterator_type os_it10 = mon_put.put(oss.rdbuf(), true, oss, '*', digits4); iterator_type os_it10 = mon_put.put(oss.rdbuf(), true, oss, '*', digits4);
string result10 = oss.str(); string result10 = oss.str();
VERIFY( result10 == "***************-,01 "); VERIFY( result10 == "***************-,01*");
oss.str(empty); oss.str(empty);
oss.width(20); oss.width(20);
@ -210,12 +210,12 @@ void test02()
const money_put<char>& mon_put = use_facet<money_put<char> >(oss.getloc()); const money_put<char>& mon_put = use_facet<money_put<char> >(oss.getloc());
iterator_type os_it01 = mon_put.put(oss.rdbuf(), true, oss, '*', digits1); iterator_type os_it01 = mon_put.put(oss.rdbuf(), true, oss, ' ', digits1);
string result1 = oss.str(); string result1 = oss.str();
VERIFY( result1 == "7.200.000.000,00 "); VERIFY( result1 == "7.200.000.000,00 ");
oss.str(empty); oss.str(empty);
iterator_type os_it02 = mon_put.put(oss.rdbuf(), false, oss, '*', digits1); iterator_type os_it02 = mon_put.put(oss.rdbuf(), false, oss, ' ', digits1);
string result2 = oss.str(); string result2 = oss.str();
VERIFY( result2 == "7.200.000.000,00 "); VERIFY( result2 == "7.200.000.000,00 ");
@ -226,12 +226,12 @@ void test02()
oss.setf(ios_base::showbase); oss.setf(ios_base::showbase);
oss.str(empty); oss.str(empty);
iterator_type os_it03 = mon_put.put(oss.rdbuf(), true, oss, '*', digits1); iterator_type os_it03 = mon_put.put(oss.rdbuf(), true, oss, ' ', digits1);
string result3 = oss.str(); string result3 = oss.str();
VERIFY( result3 == "7.200.000.000,00 DEM "); VERIFY( result3 == "7.200.000.000,00 DEM ");
oss.str(empty); oss.str(empty);
iterator_type os_it04 = mon_put.put(oss.rdbuf(), false, oss, '*', digits1); iterator_type os_it04 = mon_put.put(oss.rdbuf(), false, oss, ' ', digits1);
string result4 = oss.str(); string result4 = oss.str();
VERIFY( result4 == "7.200.000.000,00 DM"); VERIFY( result4 == "7.200.000.000,00 DM");
@ -303,11 +303,50 @@ void test04()
#endif #endif
} }
struct My_money_io : public std::moneypunct<char,false>
{
char_type do_decimal_point() const { return '.'; }
char_type do_thousands_sep() const { return ','; }
std::string do_grouping() const { return "\003"; }
std::string do_negative_sign() const { return "()"; }
int do_frac_digits() const { return 2; }
pattern do_neg_format() const
{
static pattern pat = { { symbol, space, sign, value } };
return pat;
}
};
// libstdc++/5708
void test05()
{
using namespace std;
typedef ostreambuf_iterator<char> OutIt;
locale loc(locale::classic(), new My_money_io);
bool intl = false;
string val("-123456");
const money_put<char,OutIt>& mp =
use_facet<money_put<char, OutIt> >(loc);
ostringstream fmt;
fmt.imbue(loc);
OutIt out(fmt);
mp.put(out,intl,fmt,'*',val);
VERIFY( fmt.str() == "*(1,234.56)" );
}
int main() int main()
{ {
test01(); test01();
test02(); test02();
test03(); test03();
test04(); test04();
test05();
return 0; return 0;
} }

View File

@ -79,12 +79,12 @@ void test01()
const money_put<wchar_t>& mon_put = use_facet<money_put<wchar_t> >(oss.getloc()); const money_put<wchar_t>& mon_put = use_facet<money_put<wchar_t> >(oss.getloc());
iterator_type os_it01 = mon_put.put(oss.rdbuf(), true, oss, '*', digits1); iterator_type os_it01 = mon_put.put(oss.rdbuf(), true, oss, ' ', digits1);
wstring result1 = oss.str(); wstring result1 = oss.str();
VERIFY( result1 == L"7.200.000.000,00 "); VERIFY( result1 == L"7.200.000.000,00 ");
oss.str(empty); oss.str(empty);
iterator_type os_it02 = mon_put.put(oss.rdbuf(), false, oss, '*', digits1); iterator_type os_it02 = mon_put.put(oss.rdbuf(), false, oss, ' ', digits1);
wstring result2 = oss.str(); wstring result2 = oss.str();
VERIFY( result2 == L"7.200.000.000,00 "); VERIFY( result2 == L"7.200.000.000,00 ");
@ -95,12 +95,12 @@ void test01()
oss.setf(ios_base::showbase); oss.setf(ios_base::showbase);
oss.str(empty); oss.str(empty);
iterator_type os_it03 = mon_put.put(oss.rdbuf(), true, oss, '*', digits1); iterator_type os_it03 = mon_put.put(oss.rdbuf(), true, oss, ' ', digits1);
wstring result3 = oss.str(); wstring result3 = oss.str();
VERIFY( result3 == L"7.200.000.000,00 DEM "); VERIFY( result3 == L"7.200.000.000,00 DEM ");
oss.str(empty); oss.str(empty);
iterator_type os_it04 = mon_put.put(oss.rdbuf(), false, oss, '*', digits1); iterator_type os_it04 = mon_put.put(oss.rdbuf(), false, oss, ' ', digits1);
wstring result4 = oss.str(); wstring result4 = oss.str();
VERIFY( result4 == L"7.200.000.000,00 DM"); VERIFY( result4 == L"7.200.000.000,00 DM");
@ -112,26 +112,26 @@ void test01()
// test sign of more than one digit, say hong kong. // test sign of more than one digit, say hong kong.
oss.imbue(loc_hk); oss.imbue(loc_hk);
oss.str(empty); oss.str(empty);
iterator_type os_it05 = mon_put.put(oss.rdbuf(), false, oss, '*', digits1); iterator_type os_it05 = mon_put.put(oss.rdbuf(), false, oss, ' ', digits1);
wstring result5 = oss.str(); wstring result5 = oss.str();
VERIFY( result5 == L"HK$7,200,000,000.00"); VERIFY( result5 == L"HK$7,200,000,000.00");
oss.str(empty); oss.str(empty);
iterator_type os_it06 = mon_put.put(oss.rdbuf(), true, oss, '*', digits2); iterator_type os_it06 = mon_put.put(oss.rdbuf(), true, oss, ' ', digits2);
wstring result6 = oss.str(); wstring result6 = oss.str();
VERIFY( result6 == L"(HKD 100,000,000,000.00)"); VERIFY( result6 == L"(HKD 100,000,000,000.00)");
// test one-digit formats without zero padding // test one-digit formats without zero padding
oss.imbue(loc_c); oss.imbue(loc_c);
oss.str(empty); oss.str(empty);
iterator_type os_it07 = mon_put.put(oss.rdbuf(), true, oss, '*', digits4); iterator_type os_it07 = mon_put.put(oss.rdbuf(), true, oss, ' ', digits4);
wstring result7 = oss.str(); wstring result7 = oss.str();
VERIFY( result7 == L"1"); VERIFY( result7 == L"1");
// test one-digit formats with zero padding, zero frac widths // test one-digit formats with zero padding, zero frac widths
oss.imbue(loc_hk); oss.imbue(loc_hk);
oss.str(empty); oss.str(empty);
iterator_type os_it08 = mon_put.put(oss.rdbuf(), true, oss, '*', digits4); iterator_type os_it08 = mon_put.put(oss.rdbuf(), true, oss, ' ', digits4);
wstring result8 = oss.str(); wstring result8 = oss.str();
VERIFY( result8 == L"(HKD .01)"); VERIFY( result8 == L"(HKD .01)");
@ -139,7 +139,7 @@ void test01()
// test bunk input // test bunk input
oss.str(empty); oss.str(empty);
iterator_type os_it09 = mon_put.put(oss.rdbuf(), true, oss, '*', digits3); iterator_type os_it09 = mon_put.put(oss.rdbuf(), true, oss, ' ', digits3);
wstring result9 = oss.str(); wstring result9 = oss.str();
VERIFY( result9 == L""); VERIFY( result9 == L"");
@ -151,7 +151,7 @@ void test01()
oss.width(20); oss.width(20);
iterator_type os_it10 = mon_put.put(oss.rdbuf(), true, oss, '*', digits4); iterator_type os_it10 = mon_put.put(oss.rdbuf(), true, oss, '*', digits4);
wstring result10 = oss.str(); wstring result10 = oss.str();
VERIFY( result10 == L"***************-,01 "); VERIFY( result10 == L"***************-,01*");
oss.str(empty); oss.str(empty);
oss.width(20); oss.width(20);
@ -210,12 +210,12 @@ void test02()
const money_put<wchar_t>& mon_put = use_facet<money_put<wchar_t> >(oss.getloc()); const money_put<wchar_t>& mon_put = use_facet<money_put<wchar_t> >(oss.getloc());
iterator_type os_it01 = mon_put.put(oss.rdbuf(), true, oss, '*', digits1); iterator_type os_it01 = mon_put.put(oss.rdbuf(), true, oss, ' ', digits1);
wstring result1 = oss.str(); wstring result1 = oss.str();
VERIFY( result1 == L"7.200.000.000,00 "); VERIFY( result1 == L"7.200.000.000,00 ");
oss.str(empty); oss.str(empty);
iterator_type os_it02 = mon_put.put(oss.rdbuf(), false, oss, '*', digits1); iterator_type os_it02 = mon_put.put(oss.rdbuf(), false, oss, ' ', digits1);
wstring result2 = oss.str(); wstring result2 = oss.str();
VERIFY( result2 == L"7.200.000.000,00 "); VERIFY( result2 == L"7.200.000.000,00 ");
@ -226,12 +226,12 @@ void test02()
oss.setf(ios_base::showbase); oss.setf(ios_base::showbase);
oss.str(empty); oss.str(empty);
iterator_type os_it03 = mon_put.put(oss.rdbuf(), true, oss, '*', digits1); iterator_type os_it03 = mon_put.put(oss.rdbuf(), true, oss, ' ', digits1);
wstring result3 = oss.str(); wstring result3 = oss.str();
VERIFY( result3 == L"7.200.000.000,00 DEM "); VERIFY( result3 == L"7.200.000.000,00 DEM ");
oss.str(empty); oss.str(empty);
iterator_type os_it04 = mon_put.put(oss.rdbuf(), false, oss, '*', digits1); iterator_type os_it04 = mon_put.put(oss.rdbuf(), false, oss, ' ', digits1);
wstring result4 = oss.str(); wstring result4 = oss.str();
VERIFY( result4 == L"7.200.000.000,00 DM"); VERIFY( result4 == L"7.200.000.000,00 DM");
@ -302,6 +302,44 @@ void test04()
} }
#endif #endif
} }
struct My_money_io : public std::moneypunct<wchar_t,false>
{
char_type do_decimal_point() const { return L'.'; }
char_type do_thousands_sep() const { return L','; }
std::string do_grouping() const { return "\003"; }
std::wstring do_negative_sign() const { return L"()"; }
int do_frac_digits() const { return 2; }
pattern do_neg_format() const
{
static pattern pat = { { symbol, space, sign, value } };
return pat;
}
};
// libstdc++/5708
void test05()
{
using namespace std;
typedef ostreambuf_iterator<wchar_t> OutIt;
locale loc(locale::classic(), new My_money_io);
bool intl = false;
wstring val(L"-123456");
const money_put<wchar_t,OutIt>& mp =
use_facet<money_put<wchar_t, OutIt> >(loc);
wostringstream fmt;
fmt.imbue(loc);
OutIt out(fmt);
mp.put(out,intl,fmt,L'*',val);
VERIFY( fmt.str() == L"*(1,234.56)" );
}
#endif #endif
int main() int main()
@ -311,6 +349,7 @@ int main()
test02(); test02();
test03(); test03();
test04(); test04();
test05();
#endif #endif
return 0; return 0;
} }