This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] First step towards fast parsing of float types
- From: Paolo Carlini <pcarlini at suse dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Thu, 18 Dec 2003 16:00:44 +0100
- Subject: [Patch] First step towards fast parsing of float types
Hi,
this tiny step only clarifies a bit the logic in some (corner)
cases and adds missing testcases. Basically, we were accepting
thousands separators and decimal point also *after* 'e'/'E'.
Tested x86-linux.
Paolo.
////////////
2003-12-18 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.
* testsuite/22_locale/money_get/get/char/1.cc: Fix typo.
* testsuite/22_locale/money_get/get/wchar_t/1.cc: Likewise.
diff -prN libstdc++-v3-orig/include/bits/locale_facets.tcc libstdc++-v3/include/bits/locale_facets.tcc
*** libstdc++-v3-orig/include/bits/locale_facets.tcc Wed Dec 17 18:40:03 2003
--- libstdc++-v3/include/bits/locale_facets.tcc Thu Dec 18 12:14:15 2003
*************** namespace std
*** 183,207 ****
++__sep_pos;
++__beg;
}
- else if (__traits_type::eq(__c, __lc->_M_thousands_sep)
- && __lc->_M_use_grouping && !__found_dec)
- {
- // NB: Thousands separator at the beginning of a string
- // is a no-no, as is two consecutive thousands separators.
- if (__sep_pos)
- {
- __found_grouping += static_cast<char>(__sep_pos);
- __sep_pos = 0;
- ++__beg;
- }
- else
- {
- __err |= ios_base::failbit;
- break;
- }
- }
else if (__traits_type::eq(__c, __lc->_M_decimal_point)
! && !__found_dec)
{
// According to the standard, if no grouping chars are seen,
// no grouping check is applied. Therefore __found_grouping
--- 183,190 ----
++__sep_pos;
++__beg;
}
else if (__traits_type::eq(__c, __lc->_M_decimal_point)
! && !__found_dec && !__found_sci)
{
// According to the standard, if no grouping chars are seen,
// no grouping check is applied. Therefore __found_grouping
*************** namespace std
*** 232,237 ****
--- 215,238 ----
}
}
}
+ 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.
+ if (__sep_pos)
+ {
+ __found_grouping += static_cast<char>(__sep_pos);
+ __sep_pos = 0;
+ ++__beg;
+ }
+ else
+ {
+ __err |= ios_base::failbit;
+ break;
+ }
+ }
else
// Not a valid input item.
break;
diff -prN 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 Tue Sep 23 22:02:27 2003
--- libstdc++-v3/testsuite/22_locale/money_get/get/char/1.cc Thu Dec 18 13:45:46 2003
*************** void test01()
*** 100,106 ****
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 );
iss.str("working for enlightenment and peace in a mad world");
iterator_type is_it05(iss);
--- 100,106 ----
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) );
iss.str("working for enlightenment and peace in a mad world");
iterator_type is_it05(iss);
diff -prN 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 Tue Sep 23 22:02:28 2003
--- libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/1.cc Thu Dec 18 13:46:02 2003
*************** void test01()
*** 100,106 ****
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 );
iss.str(L"working for enlightenment and peace in a mad world");
iterator_type is_it05(iss);
--- 100,106 ----
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) );
iss.str(L"working for enlightenment and peace in a mad world");
iterator_type is_it05(iss);
diff -prN 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 Thu Jan 1 01:00:00 1970
--- libstdc++-v3/testsuite/22_locale/num_get/get/char/9.cc Thu Dec 18 13:21:09 2003
***************
*** 0 ****
--- 1,79 ----
+ // 2003-12-18 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("1e,");
+ iss.clear();
+ err = ios_base::goodbit;
+ end = ng.get(iss.rdbuf(), 0, iss, err, d);
+ VERIFY( err == ios_base::failbit );
+ VERIFY( *end == ',' );
+
+ 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 );
+
+ iss.str("3e.");
+ iss.clear();
+ err = ios_base::goodbit;
+ end = ng.get(iss.rdbuf(), 0, iss, err, d);
+ VERIFY( err == ios_base::failbit );
+ VERIFY( *end == '.' );
+ }
+
+ int main()
+ {
+ test01();
+ return 0;
+ }
diff -prN 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 Thu Jan 1 01:00:00 1970
--- libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/9.cc Thu Dec 18 13:19:36 2003
***************
*** 0 ****
--- 1,79 ----
+ // 2003-12-18 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"1e,");
+ iss.clear();
+ err = ios_base::goodbit;
+ end = ng.get(iss.rdbuf(), 0, iss, err, d);
+ VERIFY( err == ios_base::failbit );
+ VERIFY( *end == L',' );
+
+ 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 );
+
+ iss.str(L"3e.");
+ iss.clear();
+ err = ios_base::goodbit;
+ end = ng.get(iss.rdbuf(), 0, iss, err, d);
+ VERIFY( err == ios_base::failbit );
+ VERIFY( *end == L'.' );
+ }
+
+ int main()
+ {
+ test01();
+ return 0;
+ }