mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-24 07:30:31 +08:00
locale_facets.tcc (money_get<>::_M_extract): Adjust the logic underlying the parsing of symbol to deal correctly with an...
2004-03-15 Paolo Carlini <pcarlini@suse.de> * include/bits/locale_facets.tcc (money_get<>::_M_extract): Adjust the logic underlying the parsing of symbol to deal correctly with an optional sign component (i.e., when either negative_sign or positive_sign is empty) * testsuite/22_locale/money_get/get/char/19.cc: New. * testsuite/22_locale/money_get/get/wchar_t/19.cc: New. 2004-03-15 Paolo Carlini <pcarlini@suse.de> * include/bits/locale_facets.tcc (money_get<>::_M_extract): Do not accept an incomplete currency symbol. * testsuite/22_locale/money_get/get/char/18.cc: New. * testsuite/22_locale/money_get/get/wchar_t/18.cc: New. From-SVN: r79491
This commit is contained in:
parent
d08418fa77
commit
33674f003a
@ -1,3 +1,19 @@
|
||||
2004-03-15 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
* include/bits/locale_facets.tcc (money_get<>::_M_extract):
|
||||
Adjust the logic underlying the parsing of symbol to deal
|
||||
correctly with an optional sign component (i.e., when either
|
||||
negative_sign or positive_sign is empty)
|
||||
* testsuite/22_locale/money_get/get/char/19.cc: New.
|
||||
* testsuite/22_locale/money_get/get/wchar_t/19.cc: New.
|
||||
|
||||
2004-03-15 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
* include/bits/locale_facets.tcc (money_get<>::_M_extract):
|
||||
Do not accept an incomplete currency symbol.
|
||||
* testsuite/22_locale/money_get/get/char/18.cc: New.
|
||||
* testsuite/22_locale/money_get/get/wchar_t/18.cc: New.
|
||||
|
||||
2004-03-13 Benjamin Kosnik <bkoz@redhat.com>
|
||||
|
||||
* config/allocator: New.
|
||||
|
@ -1185,6 +1185,9 @@ namespace std
|
||||
bool __negative = false;
|
||||
// Sign size.
|
||||
size_type __sign_size = 0;
|
||||
// True if sign is mandatory.
|
||||
const bool __mandatory_sign = (__lc->_M_positive_sign_size
|
||||
&& __lc->_M_negative_sign_size);
|
||||
// String of grouping info from thousands_sep plucked from __units.
|
||||
string __grouping_tmp;
|
||||
if (__lc->_M_use_grouping)
|
||||
@ -1211,21 +1214,30 @@ namespace std
|
||||
switch (__which)
|
||||
{
|
||||
case money_base::symbol:
|
||||
if (__io.flags() & ios_base::showbase
|
||||
|| __i < 2 || __sign_size > 1
|
||||
|| ((static_cast<part>(__p.field[3]) != money_base::none)
|
||||
&& __i == 2))
|
||||
// According to 22.2.6.1.2, p2, symbol is required
|
||||
// if (__io.flags() & ios_base::showbase), otherwise
|
||||
// is optional and consumed only if other characters
|
||||
// are needed to complete the format.
|
||||
if (__io.flags() & ios_base::showbase || __sign_size > 1
|
||||
|| __i == 0
|
||||
|| (__i == 1 && (__mandatory_sign
|
||||
|| (static_cast<part>(__p.field[0])
|
||||
== sign)
|
||||
|| (static_cast<part>(__p.field[2])
|
||||
== space)))
|
||||
|| (__i == 2 && ((static_cast<part>(__p.field[3])
|
||||
== money_base::value)
|
||||
|| __mandatory_sign
|
||||
&& (static_cast<part>(__p.field[3])
|
||||
== money_base::sign))))
|
||||
{
|
||||
// According to 22.2.6.1.2, p2, symbol is required
|
||||
// if (__io.flags() & ios_base::showbase), otherwise
|
||||
// is optional and consumed only if other characters
|
||||
// are needed to complete the format.
|
||||
const size_type __len = __lc->_M_curr_symbol_size;
|
||||
size_type __j = 0;
|
||||
for (; __beg != __end && __j < __len
|
||||
&& *__beg == __lc->_M_curr_symbol[__j];
|
||||
++__beg, ++__j);
|
||||
if (__j != __len && (__io.flags() & ios_base::showbase))
|
||||
if (__j != __len
|
||||
&& (__j || __io.flags() & ios_base::showbase))
|
||||
__testvalid = false;
|
||||
}
|
||||
break;
|
||||
@ -1249,12 +1261,8 @@ namespace std
|
||||
// "... if no sign is detected, the result is given the sign
|
||||
// that corresponds to the source of the empty string"
|
||||
__negative = true;
|
||||
else if (__lc->_M_positive_sign_size
|
||||
&& __lc->_M_negative_sign_size)
|
||||
{
|
||||
// Sign is mandatory.
|
||||
__testvalid = false;
|
||||
}
|
||||
else if (__mandatory_sign)
|
||||
__testvalid = false;
|
||||
break;
|
||||
case money_base::value:
|
||||
// Extract digits, remove and stash away the
|
||||
|
69
libstdc++-v3/testsuite/22_locale/money_get/get/char/18.cc
Normal file
69
libstdc++-v3/testsuite/22_locale/money_get/get/char/18.cc
Normal file
@ -0,0 +1,69 @@
|
||||
// 2004-03-15 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
// Copyright (C) 2004 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>
|
||||
|
||||
// If (str.flags() & str.showbase) is false, the currency symbol is optional,
|
||||
// but, if found, must be consumed entirely.
|
||||
void test01()
|
||||
{
|
||||
using namespace std;
|
||||
typedef istreambuf_iterator<char> iterator_type;
|
||||
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
// basic construction
|
||||
locale loc_c = locale::classic();
|
||||
locale loc_hk = __gnu_test::try_named_locale("en_HK");
|
||||
VERIFY( loc_c != loc_hk );
|
||||
|
||||
iterator_type end, end01, end02;
|
||||
istringstream iss;
|
||||
iss.imbue(loc_hk);
|
||||
// cache the money_get facet
|
||||
const money_get<char>& mon_get =
|
||||
use_facet<money_get<char> >(iss.getloc());
|
||||
|
||||
iss.str("HK7,200,000,000.00");
|
||||
iterator_type is_it01(iss);
|
||||
string result01;
|
||||
ios_base::iostate err01 = ios_base::goodbit;
|
||||
end01 = mon_get.get(is_it01, end, false, iss, err01, result01);
|
||||
VERIFY( err01 == ios_base::failbit );
|
||||
VERIFY( *end01 == '7' );
|
||||
|
||||
iss.str("(HK100,000,000,000.00)");
|
||||
iterator_type is_it02(iss);
|
||||
string result02;
|
||||
ios_base::iostate err02 = ios_base::goodbit;
|
||||
end02 = mon_get.get(is_it02, end, true, iss, err02, result02);
|
||||
VERIFY( err02 == ios_base::failbit );
|
||||
VERIFY( *end02 == '1' );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
125
libstdc++-v3/testsuite/22_locale/money_get/get/char/19.cc
Normal file
125
libstdc++-v3/testsuite/22_locale/money_get/get/char/19.cc
Normal file
@ -0,0 +1,125 @@
|
||||
// 2004-03-15 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
// Copyright (C) 2004 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>
|
||||
|
||||
struct My_money_io_01 : public std::moneypunct<char, false>
|
||||
{
|
||||
std::string do_curr_symbol() const { return "$"; }
|
||||
std::string do_positive_sign() const { return ""; }
|
||||
std::string do_negative_sign() const { return ""; }
|
||||
|
||||
pattern do_neg_format() const
|
||||
{
|
||||
pattern pat = { { value, symbol, none, sign } };
|
||||
return pat;
|
||||
}
|
||||
};
|
||||
|
||||
struct My_money_io_02 : public std::moneypunct<char, false>
|
||||
{
|
||||
std::string do_curr_symbol() const { return "%"; }
|
||||
std::string do_positive_sign() const { return ""; }
|
||||
std::string do_negative_sign() const { return "-"; }
|
||||
|
||||
pattern do_neg_format() const
|
||||
{
|
||||
pattern pat = { { value, symbol, sign, none } };
|
||||
return pat;
|
||||
}
|
||||
};
|
||||
|
||||
struct My_money_io_03 : public std::moneypunct<char, false>
|
||||
{
|
||||
std::string do_curr_symbol() const { return "&"; }
|
||||
std::string do_positive_sign() const { return ""; }
|
||||
std::string do_negative_sign() const { return ""; }
|
||||
|
||||
pattern do_neg_format() const
|
||||
{
|
||||
pattern pat = { { value, space, symbol, sign } };
|
||||
return pat;
|
||||
}
|
||||
};
|
||||
|
||||
// When both do_positive_sign and do_negative_sign return an empty
|
||||
// string, patterns of the forms { value, symbol, none, sign },
|
||||
// { value, symbol, sign, none } and { X, Y, symbol, sign } imply
|
||||
// that the symbol is not consumed since no other characters are
|
||||
// needed to complete the format.
|
||||
void test01()
|
||||
{
|
||||
using namespace std;
|
||||
typedef istreambuf_iterator<char> iterator_type;
|
||||
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
// basic construction
|
||||
locale loc_01(locale::classic(), new My_money_io_01);
|
||||
locale loc_02(locale::classic(), new My_money_io_02);
|
||||
locale loc_03(locale::classic(), new My_money_io_03);
|
||||
|
||||
iterator_type end, end01, end02, end03;
|
||||
istringstream iss_01, iss_02, iss_03;
|
||||
iss_01.imbue(loc_01);
|
||||
iss_02.imbue(loc_02);
|
||||
iss_03.imbue(loc_03);
|
||||
// cache the money_get facet
|
||||
const money_get<char>& mon_get_01 =
|
||||
use_facet<money_get<char> >(iss_01.getloc());
|
||||
const money_get<char>& mon_get_02 =
|
||||
use_facet<money_get<char> >(iss_02.getloc());
|
||||
const money_get<char>& mon_get_03 =
|
||||
use_facet<money_get<char> >(iss_03.getloc());
|
||||
|
||||
iss_01.str("10$");
|
||||
iterator_type is_it01(iss_01);
|
||||
string result01;
|
||||
ios_base::iostate err01 = ios_base::goodbit;
|
||||
end01 = mon_get_01.get(is_it01, end, false, iss_01, err01, result01);
|
||||
VERIFY( err01 == ios_base::goodbit );
|
||||
VERIFY( *end01 == '$' );
|
||||
|
||||
iss_02.str("50%");
|
||||
iterator_type is_it02(iss_02);
|
||||
string result02;
|
||||
ios_base::iostate err02 = ios_base::goodbit;
|
||||
end02 = mon_get_02.get(is_it02, end, false, iss_02, err02, result02);
|
||||
VERIFY( err02 == ios_base::goodbit );
|
||||
VERIFY( *end02 == '%' );
|
||||
|
||||
iss_03.str("7 &");
|
||||
iterator_type is_it03(iss_03);
|
||||
string result03;
|
||||
ios_base::iostate err03 = ios_base::goodbit;
|
||||
end03 = mon_get_03.get(is_it03, end, false, iss_03, err03, result03);
|
||||
VERIFY( err03 == ios_base::goodbit );
|
||||
VERIFY( *end03 == '&' );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
69
libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/18.cc
Normal file
69
libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/18.cc
Normal file
@ -0,0 +1,69 @@
|
||||
// 2004-03-15 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
// Copyright (C) 2004 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>
|
||||
|
||||
// If (str.flags() & str.showbase) is false, the currency symbol is optional,
|
||||
// but, if found, must be consumed entirely.
|
||||
void test01()
|
||||
{
|
||||
using namespace std;
|
||||
typedef istreambuf_iterator<wchar_t> iterator_type;
|
||||
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
// basic construction
|
||||
locale loc_c = locale::classic();
|
||||
locale loc_hk = __gnu_test::try_named_locale("en_HK");
|
||||
VERIFY( loc_c != loc_hk );
|
||||
|
||||
iterator_type end, end01, end02;
|
||||
wistringstream iss;
|
||||
iss.imbue(loc_hk);
|
||||
// cache the money_get facet
|
||||
const money_get<wchar_t>& mon_get =
|
||||
use_facet<money_get<wchar_t> >(iss.getloc());
|
||||
|
||||
iss.str(L"HK7,200,000,000.00");
|
||||
iterator_type is_it01(iss);
|
||||
wstring result01;
|
||||
ios_base::iostate err01 = ios_base::goodbit;
|
||||
end01 = mon_get.get(is_it01, end, false, iss, err01, result01);
|
||||
VERIFY( err01 == ios_base::failbit );
|
||||
VERIFY( *end01 == L'7' );
|
||||
|
||||
iss.str(L"(HK100,000,000,000.00)");
|
||||
iterator_type is_it02(iss);
|
||||
wstring result02;
|
||||
ios_base::iostate err02 = ios_base::goodbit;
|
||||
end02 = mon_get.get(is_it02, end, true, iss, err02, result02);
|
||||
VERIFY( err02 == ios_base::failbit );
|
||||
VERIFY( *end02 == L'1' );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
125
libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/19.cc
Normal file
125
libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/19.cc
Normal file
@ -0,0 +1,125 @@
|
||||
// 2004-03-15 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
// Copyright (C) 2004 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>
|
||||
|
||||
struct My_money_io_01 : public std::moneypunct<wchar_t, false>
|
||||
{
|
||||
std::wstring do_curr_symbol() const { return L"$"; }
|
||||
std::wstring do_positive_sign() const { return L""; }
|
||||
std::wstring do_negative_sign() const { return L""; }
|
||||
|
||||
pattern do_neg_format() const
|
||||
{
|
||||
pattern pat = { { value, symbol, none, sign } };
|
||||
return pat;
|
||||
}
|
||||
};
|
||||
|
||||
struct My_money_io_02 : public std::moneypunct<wchar_t, false>
|
||||
{
|
||||
std::wstring do_curr_symbol() const { return L"%"; }
|
||||
std::wstring do_positive_sign() const { return L""; }
|
||||
std::wstring do_negative_sign() const { return L"-"; }
|
||||
|
||||
pattern do_neg_format() const
|
||||
{
|
||||
pattern pat = { { value, symbol, sign, none } };
|
||||
return pat;
|
||||
}
|
||||
};
|
||||
|
||||
struct My_money_io_03 : public std::moneypunct<wchar_t, false>
|
||||
{
|
||||
std::wstring do_curr_symbol() const { return L"&"; }
|
||||
std::wstring do_positive_sign() const { return L""; }
|
||||
std::wstring do_negative_sign() const { return L""; }
|
||||
|
||||
pattern do_neg_format() const
|
||||
{
|
||||
pattern pat = { { value, space, symbol, sign } };
|
||||
return pat;
|
||||
}
|
||||
};
|
||||
|
||||
// When both do_positive_sign and do_negative_sign return an empty
|
||||
// string, patterns of the forms { value, symbol, none, sign },
|
||||
// { value, symbol, sign, none } and { X, Y, symbol, sign } imply
|
||||
// that the symbol is not consumed since no other characters are
|
||||
// needed to complete the format.
|
||||
void test01()
|
||||
{
|
||||
using namespace std;
|
||||
typedef istreambuf_iterator<wchar_t> iterator_type;
|
||||
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
// basic construction
|
||||
locale loc_01(locale::classic(), new My_money_io_01);
|
||||
locale loc_02(locale::classic(), new My_money_io_02);
|
||||
locale loc_03(locale::classic(), new My_money_io_03);
|
||||
|
||||
iterator_type end, end01, end02, end03;
|
||||
wistringstream iss_01, iss_02, iss_03;
|
||||
iss_01.imbue(loc_01);
|
||||
iss_02.imbue(loc_02);
|
||||
iss_03.imbue(loc_03);
|
||||
// cache the money_get facet
|
||||
const money_get<wchar_t>& mon_get_01 =
|
||||
use_facet<money_get<wchar_t> >(iss_01.getloc());
|
||||
const money_get<wchar_t>& mon_get_02 =
|
||||
use_facet<money_get<wchar_t> >(iss_02.getloc());
|
||||
const money_get<wchar_t>& mon_get_03 =
|
||||
use_facet<money_get<wchar_t> >(iss_03.getloc());
|
||||
|
||||
iss_01.str(L"10$");
|
||||
iterator_type is_it01(iss_01);
|
||||
wstring result01;
|
||||
ios_base::iostate err01 = ios_base::goodbit;
|
||||
end01 = mon_get_01.get(is_it01, end, false, iss_01, err01, result01);
|
||||
VERIFY( err01 == ios_base::goodbit );
|
||||
VERIFY( *end01 == L'$' );
|
||||
|
||||
iss_02.str(L"50%");
|
||||
iterator_type is_it02(iss_02);
|
||||
wstring result02;
|
||||
ios_base::iostate err02 = ios_base::goodbit;
|
||||
end02 = mon_get_02.get(is_it02, end, false, iss_02, err02, result02);
|
||||
VERIFY( err02 == ios_base::goodbit );
|
||||
VERIFY( *end02 == L'%' );
|
||||
|
||||
iss_03.str(L"7 &");
|
||||
iterator_type is_it03(iss_03);
|
||||
wstring result03;
|
||||
ios_base::iostate err03 = ios_base::goodbit;
|
||||
end03 = mon_get_03.get(is_it03, end, false, iss_03, err03, result03);
|
||||
VERIFY( err03 == ios_base::goodbit );
|
||||
VERIFY( *end03 == L'&' );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user