locale_facets.tcc (money_get::do_get(string)): Check for zero-length negative sign...
authorBenjamin Kosnik <bkoz@redhat.com>
Fri, 11 Jan 2002 20:12:02 +0000 (20:12 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Fri, 11 Jan 2002 20:12:02 +0000 (20:12 +0000)
2002-01-11  Benjamin Kosnik  <bkoz@redhat.com>

* 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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/locale_facets.tcc
libstdc++-v3/testsuite/22_locale/money_get_members_char.cc
libstdc++-v3/testsuite/22_locale/money_get_members_wchar_t.cc

index 3df8b7c47d25e9fd933bfe2213f5b4c2e6c9d290..56936cec1f97360fee9663ee58d9fda81e00a5fc 100644 (file)
@@ -1,3 +1,13 @@
+2002-01-11  Benjamin Kosnik  <bkoz@redhat.com>
+
+       * 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  <seymour_dj@yahoo.com>
 
        libstdc++/5331
index 6e0e8b9f1bcca9eab1686045e2cc38d8dc0e9b8b..35873e1f81301b38f144da541dd4ee79aa418997 100644 (file)
@@ -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<long double>::digits10;
       char* __cs = static_cast<char*>(__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.
index 86d59e8ea00de356e19ac5558e50606e8ffda6ea..5b0892dd7489b1f4950718143bfe0adffba8c6e5 100644 (file)
@@ -1,6 +1,6 @@
 // 2001-09-12 Benjamin Kosnik  <bkoz@redhat.com>
 
-// 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<char, iter_type> 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<mon_get_type>(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;
 }
index 9426c97ef4e2881f6bae00d9db62f7c63420170c..2e0399befef7c18350abe81e1ffffe933f9e19a6 100644 (file)
@@ -1,6 +1,6 @@
 // 2001-09-14 Benjamin Kosnik  <bkoz@redhat.com>
 
-// 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<wchar_t, iter_type> 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<mon_get_type>(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;
 }