mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-12-02 08:13:58 +08:00
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
This commit is contained in:
parent
0e67400ab4
commit
60aa9fc304
@ -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
|
||||
|
@ -1284,38 +1284,50 @@ namespace std
|
||||
__testvalid = false;
|
||||
}
|
||||
|
||||
const char_type __zero = __ctype.widen('0');
|
||||
|
||||
// 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('-'));
|
||||
|
||||
// Test for grouping fidelity.
|
||||
if (__grouping.size() && __grouping_tmp.size())
|
||||
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);
|
||||
}
|
||||
|
||||
if (__tmp_units.size())
|
||||
{
|
||||
// 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 (!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 not enough digits were supplied after the decimal-point.
|
||||
if (__testdecfound)
|
||||
{
|
||||
const int __frac = __intl ? __mpt.frac_digits()
|
||||
: __mpf.frac_digits();
|
||||
if (__frac > 0)
|
||||
{
|
||||
if (__sep_pos != __frac)
|
||||
__testvalid = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
63
libstdc++-v3/testsuite/22_locale/money_get/get/char/10.cc
Normal file
63
libstdc++-v3/testsuite/22_locale/money_get/get/char/10.cc
Normal file
@ -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;
|
||||
}
|
63
libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/10.cc
Normal file
63
libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/10.cc
Normal file
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user