From: Benjamin Kosnik Date: Sun, 13 Jan 2002 04:27:18 +0000 (+0000) Subject: locale_facets.tcc (money_put::do_put(string): Correct output iterator value. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ae72572be948907827c02a4f20e92dcff0f92b29;p=gcc.git locale_facets.tcc (money_put::do_put(string): Correct output iterator value. 2002-01-12 Benjamin Kosnik * include/bits/locale_facets.tcc (money_put::do_put(string): Correct output iterator value. * testsuite/22_locale/money_put_members_char.cc (test03): Add. * testsuite/22_locale/money_put_members_wchar_t.cc: Same. From-SVN: r48809 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ef8625a93b8..56cbc2c6187 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2002-01-12 Benjamin Kosnik + + * include/bits/locale_facets.tcc (money_put::do_put(string): + Correct output iterator value. + * testsuite/22_locale/money_put_members_char.cc (test03): Add. + * testsuite/22_locale/money_put_members_wchar_t.cc: Same. + 2002-01-11 Phil Edwards * include/Makefile.am, include/Makefile.in (stamp-std): Fix typo from diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 35873e1f813..396f4236c4c 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -1415,8 +1415,8 @@ namespace std } // Write resulting, fully-formatted string to output iterator. - for (size_type __j = 0; __j < __len; ++__j) - __s = __res[__j]; + for (size_type __j = 0; __j < __len; ++__j, ++__s) + *__s = __res[__j]; } __io.width(0); return __s; diff --git a/libstdc++-v3/testsuite/22_locale/money_get_members_char.cc b/libstdc++-v3/testsuite/22_locale/money_get_members_char.cc index 5b0892dd748..5e30ac75b99 100644 --- a/libstdc++-v3/testsuite/22_locale/money_get_members_char.cc +++ b/libstdc++-v3/testsuite/22_locale/money_get_members_char.cc @@ -255,7 +255,7 @@ void test03() bool test = true; // Check money_get works with other iterators besides streambuf - // output iterators. + // input iterators. typedef string::const_iterator iter_type; typedef money_get mon_get_type; const ios_base::iostate goodbit = ios_base::goodbit; diff --git a/libstdc++-v3/testsuite/22_locale/money_put_members_char.cc b/libstdc++-v3/testsuite/22_locale/money_put_members_char.cc index c0f8d1eb243..3c318cec211 100644 --- a/libstdc++-v3/testsuite/22_locale/money_put_members_char.cc +++ b/libstdc++-v3/testsuite/22_locale/money_put_members_char.cc @@ -1,6 +1,6 @@ // 2001-08-27 Benjamin Kosnik -// Copyright (C) 2001 Free Software Foundation +// Copyright (C) 2001-2002 Free Software Foundation // // 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 @@ -161,7 +161,7 @@ void test01() VERIFY( result11 == "-,01****************"); } -// test double/string versions +// test double version void test02() { using namespace std; @@ -241,9 +241,53 @@ void test02() VERIFY( result4 != result2 ); } +void test03() +{ + using namespace std; + bool test = true; + + // Check money_put works with other iterators besides streambuf + // output iterators. (As long as output_iterator requirements are met.) + typedef string::iterator iter_type; + typedef money_put mon_put_type; + const ios_base::iostate goodbit = ios_base::goodbit; + const ios_base::iostate eofbit = ios_base::eofbit; + ios_base::iostate err = goodbit; + const locale loc_c = locale::classic(); + // woman, art, thief (stole the blues) + const string str("1943 Janis Joplin"); + const long double ld = 1943; + const string x(str.size(), 'x'); // have to have allocated string! + string res; + + ostringstream oss; + oss.imbue(locale(loc_c, new mon_put_type)); + + // Iterator advanced, state, output. + const mon_put_type& mp = use_facet(oss.getloc()); + + // 01 string + res = x; + iter_type ret1 = mp.put(res.begin(), false, oss, ' ', str); + string sanity1(res.begin(), ret1); + VERIFY( err == goodbit ); + VERIFY( res == "1943xxxxxxxxxxxxx" ); + VERIFY( sanity1 == "1943" ); + + // 02 long double + res = x; + iter_type ret2 = mp.put(res.begin(), false, oss, ' ', ld); + string sanity2(res.begin(), ret2); + VERIFY( err == goodbit ); + VERIFY( res == "1943xxxxxxxxxxxxx" ); + VERIFY( sanity2 == "1943" ); +} + int main() { test01(); test02(); + test03(); return 0; } + diff --git a/libstdc++-v3/testsuite/22_locale/money_put_members_wchar_t.cc b/libstdc++-v3/testsuite/22_locale/money_put_members_wchar_t.cc index b592e4f24eb..36dde8ceef4 100644 --- a/libstdc++-v3/testsuite/22_locale/money_put_members_wchar_t.cc +++ b/libstdc++-v3/testsuite/22_locale/money_put_members_wchar_t.cc @@ -1,6 +1,6 @@ // 2001-09-09 Benjamin Kosnik -// Copyright (C) 2001 Free Software Foundation +// Copyright (C) 2001-2002 Free Software Foundation // // 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 @@ -240,6 +240,48 @@ void test02() VERIFY( result3 != result1 ); VERIFY( result4 != result2 ); } + +void test03() +{ + using namespace std; + bool test = true; + + // Check money_put works with other iterators besides streambuf + // output iterators. (As long as output_iterator requirements are met.) + typedef wstring::iterator iter_type; + typedef money_put mon_put_type; + const ios_base::iostate goodbit = ios_base::goodbit; + const ios_base::iostate eofbit = ios_base::eofbit; + ios_base::iostate err = goodbit; + const locale loc_c = locale::classic(); + // woman, art, thief (stole the blues) + const wstring str(L"1943 Janis Joplin"); + const long double ld = 1943; + const wstring x(str.size(), 'x'); // have to have allocated string! + wstring res; + + wostringstream oss; + oss.imbue(locale(loc_c, new mon_put_type)); + + // Iterator advanced, state, output. + const mon_put_type& mp = use_facet(oss.getloc()); + + // 01 string + res = x; + iter_type ret1 = mp.put(res.begin(), false, oss, ' ', str); + wstring sanity1(res.begin(), ret1); + VERIFY( err == goodbit ); + VERIFY( res == L"1943xxxxxxxxxxxxx" ); + VERIFY( sanity1 == L"1943" ); + + // 02 long double + res = x; + iter_type ret2 = mp.put(res.begin(), false, oss, ' ', ld); + wstring sanity2(res.begin(), ret2); + VERIFY( err == goodbit ); + VERIFY( res == L"1943xxxxxxxxxxxxx" ); + VERIFY( sanity2 == L"1943" ); +} #endif int main() @@ -247,6 +289,7 @@ int main() #ifdef _GLIBCPP_USE_WCHAR_T test01(); test02(); + test03(); #endif return 0; }