OSDN Git Service

2003-10-23 Paolo Carlini <pcarlini@suse.de>
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 23 Oct 2003 17:05:01 +0000 (17:05 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 23 Oct 2003 17:05:01 +0000 (17:05 +0000)
* include/bits/locale_facets.tcc (money_get<>::do_get(...,
string_type&)): Use find_first_not_of to strip leading
zeros; if __tmp_units == "0" never prefix it with '-';
always fail if __tmp_units is empty.
* testsuite/22_locale/money_get/get/char/10.cc: New.
* testsuite/22_locale/money_get/get/wchar_t/10.cc: Ditto.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@72860 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/locale_facets.tcc
libstdc++-v3/testsuite/22_locale/money_get/get/char/10.cc [new file with mode: 0644]
libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/10.cc [new file with mode: 0644]

index 029cbf4..548cc71 100644 (file)
@@ -1,3 +1,12 @@
+2003-10-23  Paolo Carlini  <pcarlini@suse.de>
+
+       * include/bits/locale_facets.tcc (money_get<>::do_get(...,
+       string_type&)): Use find_first_not_of to strip leading
+       zeros; if __tmp_units == "0" never prefix it with '-';
+       always fail if __tmp_units is empty.
+       * testsuite/22_locale/money_get/get/char/10.cc: New.
+       * testsuite/22_locale/money_get/get/wchar_t/10.cc: Ditto.
+
 2003-10-23  Phil Edwards  <phil@codesourcery.com>
 
        * config/os/vxworks/ctype_noninline.h:  Adjust ctor to match
index 0f8d2b5..4a68771 100644 (file)
@@ -1284,38 +1284,50 @@ namespace std
            __testvalid = false;
        }
 
-      // Strip leading zeros.
-      while (__tmp_units.size() > 1 && __tmp_units[0] == __ctype.widen('0'))
-       __tmp_units.erase(__tmp_units.begin());
-
-      if (__sign.size() && __sign == __neg_sign)
-       __tmp_units.insert(__tmp_units.begin(), __ctype.widen('-'));
+      const char_type __zero = __ctype.widen('0');
 
-      // Test for grouping fidelity.
-      if (__grouping.size() && __grouping_tmp.size())
+      // Strip leading zeros.
+      if (__tmp_units.size() > 1)
        {
-         if (!std::__verify_grouping(__grouping, __grouping_tmp))
-           __testvalid = false;
+         const size_type __first = __tmp_units.find_first_not_of(__zero);
+         const bool __only_zeros = __first == string_type::npos;
+         if (__first)
+           __tmp_units.erase(0, __only_zeros  ? __tmp_units.size() - 1
+                                              : __first);
        }
 
-      // Iff no more characters are available.      
-      if (__c == __eof)
-       __err |= ios_base::eofbit;
-
-      // Iff not enough digits were supplied after the decimal-point.
-      if (__testdecfound)
+      if (__tmp_units.size())
        {
-         const int __frac = __intl ? __mpt.frac_digits() 
-                                   : __mpf.frac_digits();
-         if (__frac > 0)
+         // 22.2.6.1.2, p4
+         if (__sign.size() && __sign == __neg_sign
+             && __tmp_units[0] != __zero)
+           __tmp_units.insert(__tmp_units.begin(), __ctype.widen('-'));      
+
+         // Test for grouping fidelity.
+         if (__grouping.size() && __grouping_tmp.size())
            {
-             if (__sep_pos != __frac)
+             if (!std::__verify_grouping(__grouping, __grouping_tmp))
+               __testvalid = false;
+           }
+
+         // Iff not enough digits were supplied after the decimal-point.
+         if (__testdecfound)
+           {
+             const int __frac = __intl ? __mpt.frac_digits() 
+                                       : __mpf.frac_digits();
+             if (__frac > 0 && __sep_pos != __frac)
                __testvalid = false;
            }
        }
+      else
+       __testvalid = false;
+
+      // Iff no more characters are available.      
+      if (__c == __eof)
+       __err |= ios_base::eofbit;
 
       // Iff valid sequence is not recognized.
-      if (!__testvalid || !__tmp_units.size())
+      if (!__testvalid)
        __err |= ios_base::failbit;
       else
        // Use the "swap trick" to copy __tmp_units into __units.
diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/10.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/10.cc
new file mode 100644 (file)
index 0000000..1711e25
--- /dev/null
@@ -0,0 +1,63 @@
+// 2003-10-23  Paolo Carlini  <pcarlini@suse.de>
+
+// Copyright (C) 2003 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 22.2.6.1.1 money_get members
+
+#include <locale>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  using namespace std;
+  typedef istreambuf_iterator<char> iterator_type;
+
+  bool test __attribute__((unused)) = true;
+
+  locale loc_us = __gnu_test::try_named_locale("en_US");
+
+  iterator_type end;
+  istringstream iss;
+  iss.imbue(loc_us);
+
+  const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc());
+
+  iss.str("-$0 ");
+  iterator_type is_it(iss);
+  string extracted_amount;
+  ios_base::iostate err = ios_base::goodbit;
+  mon_get.get(is_it, end, false, iss, err, extracted_amount);
+  VERIFY( extracted_amount == "0" );
+  VERIFY( err == ios_base::goodbit );
+
+  iss.str("-$ ");
+  iterator_type is_it_2(iss);
+  extracted_amount.clear();
+  err = ios_base::goodbit;
+  mon_get.get(is_it_2, end, false, iss, err, extracted_amount);
+  VERIFY( extracted_amount.empty() );
+  VERIFY( err == ios_base::failbit );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/10.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/10.cc
new file mode 100644 (file)
index 0000000..c1e26c8
--- /dev/null
@@ -0,0 +1,63 @@
+// 2003-10-23  Paolo Carlini  <pcarlini@suse.de>
+
+// Copyright (C) 2003 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 22.2.6.1.1 money_get members
+
+#include <locale>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  using namespace std;
+  typedef istreambuf_iterator<wchar_t> iterator_type;
+
+  bool test __attribute__((unused)) = true;
+
+  locale loc_us = __gnu_test::try_named_locale("en_US");
+
+  iterator_type end;
+  wistringstream iss;
+  iss.imbue(loc_us);
+
+  const money_get<wchar_t>& mon_get = use_facet<money_get<wchar_t> >(iss.getloc());
+
+  iss.str(L"-$0 ");
+  iterator_type is_it(iss);
+  wstring extracted_amount;
+  ios_base::iostate err = ios_base::goodbit;
+  mon_get.get(is_it, end, false, iss, err, extracted_amount);
+  VERIFY( extracted_amount == L"0" );
+  VERIFY( err == ios_base::goodbit );
+
+  iss.str(L"-$ ");
+  iterator_type is_it_2(iss);
+  extracted_amount.clear();
+  err = ios_base::goodbit;
+  mon_get.get(is_it_2, end, false, iss, err, extracted_amount);
+  VERIFY( extracted_amount.empty() );
+  VERIFY( err == ios_base::failbit );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}