From: Benjamin Kosnik Date: Fri, 11 Jan 2002 20:12:02 +0000 (+0000) Subject: locale_facets.tcc (money_get::do_get(string)): Check for zero-length negative sign... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=87a9c33cb1d5df7ab606e290ea8b37d22fae4569;p=gcc.git locale_facets.tcc (money_get::do_get(string)): Check for zero-length negative sign before adding it to output string. 2002-01-11 Benjamin Kosnik * include/bits/locale_facets.tcc (money_get::do_get(string)): Check for zero-length negative sign before adding it to output string. (money_get::do_get(long double)): Return beg. * testsuite/22_locale/money_get_members_char.cc (test02): Add iterator checks. * testsuite/22_locale/money_get_members_wchar_t.cc: Same. From-SVN: r48777 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 3df8b7c47d2..56936cec1f9 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2002-01-11 Benjamin Kosnik + + * include/bits/locale_facets.tcc (money_get::do_get(string)): + Check for zero-length negative sign before adding it to output + string. + (money_get::do_get(long double)): Return beg. + * testsuite/22_locale/money_get_members_char.cc (test02): Add + iterator checks. + * testsuite/22_locale/money_get_members_wchar_t.cc: Same. + 2002-01-10 David Seymour libstdc++/5331 diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 6e0e8b9f1bc..35873e1f813 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -1035,7 +1035,7 @@ namespace std ios_base::iostate& __err, long double& __units) const { string_type __str; - this->do_get(__beg, __end, __intl, __io, __err, __str); + __beg = this->do_get(__beg, __end, __intl, __io, __err, __str); const int __n = numeric_limits::digits10; char* __cs = static_cast(__builtin_alloca(sizeof(char) * __n)); @@ -1222,7 +1222,7 @@ namespace std while (__units[0] == __ctype.widen('0')) __units.erase(__units.begin()); - if (__sign == __neg_sign) + if (__sign.size() && __sign == __neg_sign) __units.insert(__units.begin(), __ctype.widen('-')); // Test for grouping fidelity. 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 86d59e8ea00..5b0892dd748 100644 --- a/libstdc++-v3/testsuite/22_locale/money_get_members_char.cc +++ b/libstdc++-v3/testsuite/22_locale/money_get_members_char.cc @@ -1,6 +1,6 @@ // 2001-09-12 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 @@ -172,7 +172,7 @@ void test01() VERIFY( err11 == ios_base::goodbit ); } -// test double/string versions +// test double version void test02() { using namespace std; @@ -249,9 +249,50 @@ void test02() VERIFY( err03 == ios_base::goodbit ); } +void test03() +{ + using namespace std; + bool test = true; + + // Check money_get works with other iterators besides streambuf + // output iterators. + typedef string::const_iterator iter_type; + typedef money_get mon_get_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(); + const string str = "0.01Eleanor Roosevelt"; + + istringstream iss; + iss.imbue(locale(loc_c, new mon_get_type)); + + // Iterator advanced, state, output. + const mon_get_type& mg = use_facet(iss.getloc()); + + // 01 string + string res1; + iter_type end1 = mg.get(str.begin(), str.end(), false, iss, err, res1); + string rem1(end1, str.end()); + VERIFY( err == goodbit ); + VERIFY( res1 == "1" ); + VERIFY( rem1 == "Eleanor Roosevelt" ); + + // 02 long double + iss.clear(); + err = goodbit; + long double res2; + iter_type end2 = mg.get(str.begin(), str.end(), false, iss, err, res2); + string rem2(end2, str.end()); + VERIFY( err == goodbit ); + VERIFY( res2 == 1 ); + VERIFY( rem2 == "Eleanor Roosevelt" ); +} + int main() { test01(); test02(); + test03(); return 0; } diff --git a/libstdc++-v3/testsuite/22_locale/money_get_members_wchar_t.cc b/libstdc++-v3/testsuite/22_locale/money_get_members_wchar_t.cc index 9426c97ef4e..2e0399befef 100644 --- a/libstdc++-v3/testsuite/22_locale/money_get_members_wchar_t.cc +++ b/libstdc++-v3/testsuite/22_locale/money_get_members_wchar_t.cc @@ -1,6 +1,6 @@ // 2001-09-14 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 @@ -250,13 +250,55 @@ void test02() VERIFY( result3 == digits4 ); VERIFY( err03 == ios_base::goodbit ); } + +void test03() +{ + using namespace std; + bool test = true; + + // Check money_get works with other iterators besides streambuf + // output iterators. + typedef wstring::const_iterator iter_type; + typedef money_get mon_get_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(); + const wstring str = L"0.01Eleanor Roosevelt"; + + wistringstream iss; + iss.imbue(locale(loc_c, new mon_get_type)); + + // Iterator advanced, state, output. + const mon_get_type& mg = use_facet(iss.getloc()); + + // 01 string + wstring res1; + iter_type end1 = mg.get(str.begin(), str.end(), false, iss, err, res1); + wstring rem1(end1, str.end()); + VERIFY( err == goodbit ); + VERIFY( res1 == L"1" ); + VERIFY( rem1 == L"Eleanor Roosevelt" ); + + // 02 long double + iss.clear(); + err = goodbit; + long double res2; + iter_type end2 = mg.get(str.begin(), str.end(), false, iss, err, res2); + wstring rem2(end2, str.end()); + VERIFY( err == goodbit ); + VERIFY( res2 == 1 ); + VERIFY( rem2 == L"Eleanor Roosevelt" ); +} #endif + int main() { #ifdef _GLIBCPP_USE_WCHAR_T test01(); test02(); + test03(); #endif return 0; }