This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] First step toward... (2nd take)
- From: Paolo Carlini <pcarlini at suse dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Fri, 19 Dec 2003 00:18:04 +0100
- Subject: [Patch] First step toward... (2nd take)
Hi again,
this incorporates my aftertoughts, also, in the light of Martin's
comments, doesn't try to be smart wrt ordering ;) (will deal with
that interesting issue separately, for floats and for integers too).
Tested x86-linux, would like to commit first thing tomorrow italian
time.
Paolo.
/////////////
2003-12-19 Paolo Carlini <pcarlini@suse.de>
* include/bits/locale_facets.tcc (num_get::_M_extract_float):
When __found_sci becomes true stop eating thousands separators
and the decimal radix separator.
* testsuite/22_locale/num_get/get/char/9.cc: New.
* testsuite/22_locale/num_get/get/wchar_t/9.cc: Likewise.
* config/locale/generic/c_locale.cc (__convert_to_v): Don't
check that *__sanity == '\0': parsing may stop earlier, still
be successful.
* config/locale/gnu/c_locale.cc: Likewise.
* testsuite/22_locale/num_get/get/char/10.cc: Likewise.
* testsuite/22_locale/num_get/get/wchar_t/10.cc: Likewise.
* testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc:
Tweak in one place accordingly.
* testsuite/22_locale/money_get/get/char/1.cc: Fix typo.
* testsuite/22_locale/money_get/get/wchar_t/1.cc: Likewise.
diff -urN libstdc++-v3-orig/config/locale/generic/c_locale.cc libstdc++-v3/config/locale/generic/c_locale.cc
--- libstdc++-v3-orig/config/locale/generic/c_locale.cc 2003-12-08 16:37:02.000000000 +0100
+++ libstdc++-v3/config/locale/generic/c_locale.cc 2003-12-18 18:56:27.000000000 +0100
@@ -76,7 +76,7 @@
errno = ERANGE;
#endif
#endif
- if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
+ if (__sanity != __s && errno != ERANGE)
__v = __f;
else
__err |= ios_base::failbit;
@@ -98,7 +98,7 @@
char* __sanity;
errno = 0;
double __d = strtod(__s, &__sanity);
- if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
+ if (__sanity != __s && errno != ERANGE)
__v = __d;
else
__err |= ios_base::failbit;
@@ -121,7 +121,7 @@
char* __sanity;
errno = 0;
long double __ld = strtold(__s, &__sanity);
- if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
+ if (__sanity != __s && errno != ERANGE)
__v = __ld;
#else
typedef char_traits<char>::int_type int_type;
diff -urN libstdc++-v3-orig/config/locale/gnu/c_locale.cc libstdc++-v3/config/locale/gnu/c_locale.cc
--- libstdc++-v3-orig/config/locale/gnu/c_locale.cc 2003-12-08 16:37:02.000000000 +0100
+++ libstdc++-v3/config/locale/gnu/c_locale.cc 2003-12-18 18:55:18.000000000 +0100
@@ -51,7 +51,7 @@
char* __sanity;
errno = 0;
float __f = __strtof_l(__s, &__sanity, __cloc);
- if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
+ if (__sanity != __s && errno != ERANGE)
__v = __f;
else
__err |= ios_base::failbit;
@@ -68,7 +68,7 @@
char* __sanity;
errno = 0;
double __d = __strtod_l(__s, &__sanity, __cloc);
- if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
+ if (__sanity != __s && errno != ERANGE)
__v = __d;
else
__err |= ios_base::failbit;
@@ -85,7 +85,7 @@
char* __sanity;
errno = 0;
long double __ld = __strtold_l(__s, &__sanity, __cloc);
- if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
+ if (__sanity != __s && errno != ERANGE)
__v = __ld;
else
__err |= ios_base::failbit;
diff -urN libstdc++-v3-orig/include/bits/locale_facets.tcc libstdc++-v3/include/bits/locale_facets.tcc
--- libstdc++-v3-orig/include/bits/locale_facets.tcc 2003-12-17 18:40:03.000000000 +0100
+++ libstdc++-v3/include/bits/locale_facets.tcc 2003-12-18 23:47:04.000000000 +0100
@@ -183,8 +183,9 @@
++__sep_pos;
++__beg;
}
- else if (__traits_type::eq(__c, __lc->_M_thousands_sep)
- && __lc->_M_use_grouping && !__found_dec)
+ else if (__lc->_M_use_grouping
+ && __traits_type::eq(__c, __lc->_M_thousands_sep)
+ && !__found_dec && !__found_sci)
{
// NB: Thousands separator at the beginning of a string
// is a no-no, as is two consecutive thousands separators.
@@ -201,7 +202,7 @@
}
}
else if (__traits_type::eq(__c, __lc->_M_decimal_point)
- && !__found_dec)
+ && !__found_dec && !__found_sci)
{
// According to the standard, if no grouping chars are seen,
// no grouping check is applied. Therefore __found_grouping
diff -urN libstdc++-v3-orig/testsuite/22_locale/money_get/get/char/1.cc libstdc++-v3/testsuite/22_locale/money_get/get/char/1.cc
--- libstdc++-v3-orig/testsuite/22_locale/money_get/get/char/1.cc 2003-09-23 22:02:27.000000000 +0200
+++ libstdc++-v3/testsuite/22_locale/money_get/get/char/1.cc 2003-12-18 13:45:46.000000000 +0100
@@ -100,7 +100,7 @@
ios_base::iostate err04 = ios_base::goodbit;
mon_get.get(is_it04, end, true, iss, err04, result4);
VERIFY( result4 == empty );
- VERIFY( err04 == ios_base::failbit | ios_base::eofbit );
+ VERIFY( err04 == (ios_base::failbit | ios_base::eofbit) );
iss.str("working for enlightenment and peace in a mad world");
iterator_type is_it05(iss);
diff -urN libstdc++-v3-orig/testsuite/22_locale/money_get/get/wchar_t/1.cc libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/1.cc
--- libstdc++-v3-orig/testsuite/22_locale/money_get/get/wchar_t/1.cc 2003-09-23 22:02:28.000000000 +0200
+++ libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/1.cc 2003-12-18 13:46:02.000000000 +0100
@@ -100,7 +100,7 @@
ios_base::iostate err04 = ios_base::goodbit;
mon_get.get(is_it04, end, true, iss, err04, result4);
VERIFY( result4 == empty );
- VERIFY( err04 == ios_base::failbit | ios_base::eofbit );
+ VERIFY( err04 == (ios_base::failbit | ios_base::eofbit) );
iss.str(L"working for enlightenment and peace in a mad world");
iterator_type is_it05(iss);
diff -urN libstdc++-v3-orig/testsuite/22_locale/num_get/get/char/10.cc libstdc++-v3/testsuite/22_locale/num_get/get/char/10.cc
--- libstdc++-v3-orig/testsuite/22_locale/num_get/get/char/10.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/22_locale/num_get/get/char/10.cc 2003-12-18 23:57:36.000000000 +0100
@@ -0,0 +1,72 @@
+// 2003-12-19 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.2.1.1 num_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;
+
+ istringstream iss;
+ const num_get<char>& ng = use_facet<num_get<char> >(iss.getloc());
+ ios_base::iostate err = ios_base::goodbit;
+ iterator_type end;
+ float f = 0.0f;
+ double d = 0.0;
+ long double ld = 0.0l;
+ float f1 = 1.0f;
+ double d1 = 3.0;
+ long double ld1 = 6.0l;
+
+ iss.str("1e.");
+ err = ios_base::goodbit;
+ end = ng.get(iss.rdbuf(), 0, iss, err, f);
+ VERIFY( err == ios_base::goodbit );
+ VERIFY( *end == '.' );
+ VERIFY( f == f1 );
+
+ iss.str("3e+");
+ iss.clear();
+ err = ios_base::goodbit;
+ end = ng.get(iss.rdbuf(), 0, iss, err, d);
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( d == d1 );
+
+ iss.str("6e ");
+ iss.clear();
+ err = ios_base::goodbit;
+ end = ng.get(iss.rdbuf(), 0, iss, err, ld);
+ VERIFY( err == ios_base::goodbit );
+ VERIFY( *end == ' ' );
+ VERIFY( ld == ld1 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/22_locale/num_get/get/char/9.cc libstdc++-v3/testsuite/22_locale/num_get/get/char/9.cc
--- libstdc++-v3-orig/testsuite/22_locale/num_get/get/char/9.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/22_locale/num_get/get/char/9.cc 2003-12-18 23:57:26.000000000 +0100
@@ -0,0 +1,65 @@
+// 2003-12-19 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.2.1.1 num_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;
+
+ // A locale that expects grouping
+ locale loc_de = __gnu_test::try_named_locale("de_DE");
+ istringstream iss;
+ iss.imbue(loc_de);
+
+ const num_get<char>& ng = use_facet<num_get<char> >(iss.getloc());
+ ios_base::iostate err = ios_base::goodbit;
+ iterator_type end;
+ double d = 0.0;
+ double d1 = 1e1;
+ double d2 = 3e1;
+
+ iss.str("1e1,");
+ end = ng.get(iss.rdbuf(), 0, iss, err, d);
+ VERIFY( err == ios_base::goodbit );
+ VERIFY( *end == ',' );
+ VERIFY( d == d1 );
+
+ iss.str("3e1.");
+ iss.clear();
+ err = ios_base::goodbit;
+ end = ng.get(iss.rdbuf(), 0, iss, err, d);
+ VERIFY( err == ios_base::goodbit );
+ VERIFY( *end == '.' );
+ VERIFY( d == d2 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/22_locale/num_get/get/wchar_t/10.cc libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/10.cc
--- libstdc++-v3-orig/testsuite/22_locale/num_get/get/wchar_t/10.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/10.cc 2003-12-18 23:57:47.000000000 +0100
@@ -0,0 +1,72 @@
+// 2003-12-19 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.2.1.1 num_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;
+
+ wistringstream iss;
+ const num_get<wchar_t>& ng = use_facet<num_get<wchar_t> >(iss.getloc());
+ ios_base::iostate err = ios_base::goodbit;
+ iterator_type end;
+ float f = 0.0f;
+ double d = 0.0;
+ long double ld = 0.0l;
+ float f1 = 1.0f;
+ double d1 = 3.0;
+ long double ld1 = 6.0l;
+
+ iss.str(L"1e.");
+ err = ios_base::goodbit;
+ end = ng.get(iss.rdbuf(), 0, iss, err, f);
+ VERIFY( err == ios_base::goodbit );
+ VERIFY( *end == L'.' );
+ VERIFY( f == f1 );
+
+ iss.str(L"3e+");
+ iss.clear();
+ err = ios_base::goodbit;
+ end = ng.get(iss.rdbuf(), 0, iss, err, d);
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( d == d1 );
+
+ iss.str(L"6e ");
+ iss.clear();
+ err = ios_base::goodbit;
+ end = ng.get(iss.rdbuf(), 0, iss, err, ld);
+ VERIFY( err == ios_base::goodbit );
+ VERIFY( *end == L' ' );
+ VERIFY( ld == ld1 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/22_locale/num_get/get/wchar_t/9.cc libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/9.cc
--- libstdc++-v3-orig/testsuite/22_locale/num_get/get/wchar_t/9.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/9.cc 2003-12-18 23:57:55.000000000 +0100
@@ -0,0 +1,65 @@
+// 2003-12-19 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.2.1.1 num_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;
+
+ // A locale that expects grouping
+ locale loc_de = __gnu_test::try_named_locale("de_DE");
+ wistringstream iss;
+ iss.imbue(loc_de);
+
+ const num_get<wchar_t>& ng = use_facet<num_get<wchar_t> >(iss.getloc());
+ ios_base::iostate err = ios_base::goodbit;
+ iterator_type end;
+ double d = 0.0;
+ double d1 = 1e1;
+ double d2 = 3e1;
+
+ iss.str(L"1e1,");
+ end = ng.get(iss.rdbuf(), 0, iss, err, d);
+ VERIFY( err == ios_base::goodbit );
+ VERIFY( *end == L',' );
+ VERIFY( d == d1 );
+
+ iss.str(L"3e1.");
+ iss.clear();
+ err = ios_base::goodbit;
+ end = ng.get(iss.rdbuf(), 0, iss, err, d);
+ VERIFY( err == ios_base::goodbit );
+ VERIFY( *end == L'.' );
+ VERIFY( d == d2 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc 2003-09-23 22:03:06.000000000 +0200
+++ libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc 2003-12-18 19:54:43.000000000 +0100
@@ -127,13 +127,13 @@
is_05 >> f;
VERIFY( f == 0 );
is_05 >> f;
- VERIFY( f == 0 );
- VERIFY( is_05.rdstate() == std::ios_base::failbit );
+ VERIFY( f == 5.0 );
+ VERIFY( is_05.rdstate() == std::ios_base::goodbit );
is_05.clear();
is_05 >> c;
VERIFY( c == 'a' );
is_05 >> f;
- VERIFY( f == 0 );
+ VERIFY( f == 5.0 );
VERIFY( is_05.rdstate() == std::ios_base::failbit );
is_05.clear();
is_05.ignore();