diff options
author | Paolo Carlini <pcarlini@suse.de> | 2003-10-23 17:05:01 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2003-10-23 17:05:01 +0000 |
commit | 60aa9fc304fb2ac1d1cbdba543649a45a1482200 (patch) | |
tree | 4a2e69daf81ca59127b07835c4cc1bf79218b081 | |
parent | 0e67400ab4f95d41decb49c32975f49ceb1e9f8b (diff) | |
download | gcc-60aa9fc304fb2ac1d1cbdba543649a45a1482200.zip gcc-60aa9fc304fb2ac1d1cbdba543649a45a1482200.tar.gz gcc-60aa9fc304fb2ac1d1cbdba543649a45a1482200.tar.bz2 |
locale_facets.tcc (money_get<>::do_get(..., string_type&)): Use find_first_not_of to strip leading zeros...
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.
From-SVN: r72860
-rw-r--r-- | libstdc++-v3/ChangeLog | 9 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/locale_facets.tcc | 54 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/22_locale/money_get/get/char/10.cc | 63 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/10.cc | 63 |
4 files changed, 168 insertions, 21 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 029cbf4..548cc71 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -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 diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 0f8d2b5..4a68771 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -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 index 0000000..1711e25 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/10.cc @@ -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 index 0000000..c1e26c8 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/10.cc @@ -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; +} |