locale_facets.tcc (money_get::do_get(string)): Deal correctly with !(__io.flags() & ios_base::showbase) for case...
2002-02-04 Paolo Carlini <pcarlini@unitus.it> libstdc++/5579 * include/bits/locale_facets.tcc (money_get::do_get(string)): Deal correctly with !(__io.flags() & ios_base::showbase) for case money_base::symbol. * testsuite/22_locale/money_get_members_char.cc: Add test05. * testsuite/22_locale/money_get_members_wchar_t.cc: Add test05. From-SVN: r49489
This commit is contained in:
parent
24c545ff92
commit
53804e7c80
@ -1,3 +1,12 @@
|
||||
2002-02-04 Paolo Carlini <pcarlini@unitus.it>
|
||||
|
||||
libstdc++/5579
|
||||
* include/bits/locale_facets.tcc (money_get::do_get(string)):
|
||||
Deal correctly with !(__io.flags() & ios_base::showbase)
|
||||
for case money_base::symbol.
|
||||
* testsuite/22_locale/money_get_members_char.cc: Add test05.
|
||||
* testsuite/22_locale/money_get_members_wchar_t.cc: Add test05.
|
||||
|
||||
2002-02-02 Paolo Carlini <pcarlini@unitus.it>
|
||||
|
||||
* testsuite/22_locale/operators.cc
|
||||
|
@ -938,20 +938,25 @@ namespace std
|
||||
switch (__which)
|
||||
{
|
||||
case money_base::symbol:
|
||||
if (__io.flags() & ios_base::showbase)
|
||||
if (__io.flags() & ios_base::showbase || __i < 2 ||
|
||||
__i == 2 && static_cast<part>(__p.field[3]) != money_base::none)
|
||||
{
|
||||
// Symbol is required.
|
||||
// According to 22.2.6.1.2.2, 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 string_type __symbol = __intl ? __mpt.curr_symbol()
|
||||
: __mpf.curr_symbol();
|
||||
size_type __len = __symbol.size();
|
||||
size_type __i = 0;
|
||||
size_type __j = 0;
|
||||
while (__beg != __end
|
||||
&& __i < __len && __symbol[__i] == __c)
|
||||
&& __j < __len && __symbol[__j] == __c)
|
||||
{
|
||||
__c = *(++__beg);
|
||||
++__i;
|
||||
++__j;
|
||||
}
|
||||
if (__i != __len)
|
||||
// When (__io.flags() & ios_base::showbase) symbol is required.
|
||||
if (__j != __len && (__io.flags() & ios_base::showbase))
|
||||
__testvalid = false;
|
||||
}
|
||||
break;
|
||||
|
@ -309,11 +309,86 @@ void test04()
|
||||
#endif
|
||||
}
|
||||
|
||||
class My_money_io : public std::moneypunct<char,false>
|
||||
{
|
||||
public:
|
||||
explicit My_money_io(size_t r = 0): std::moneypunct<char,false>(r) { }
|
||||
char_type do_decimal_point() const { return '.'; }
|
||||
char_type do_thousands_sep() const { return ','; }
|
||||
std::string do_grouping() const { return "\004"; }
|
||||
|
||||
std::string do_curr_symbol() const { return "$"; }
|
||||
std::string do_positive_sign() const { return ""; }
|
||||
std::string do_negative_sign() const { return "-"; }
|
||||
|
||||
int do_frac_digits() const { return 2; }
|
||||
|
||||
pattern do_pos_format() const
|
||||
{
|
||||
static pattern pat = { { symbol, none, sign, value } };
|
||||
return pat;
|
||||
}
|
||||
|
||||
pattern do_neg_format() const
|
||||
{
|
||||
static pattern pat = { { symbol, none, sign, value } };
|
||||
return pat;
|
||||
}
|
||||
};
|
||||
|
||||
// libstdc++/5579
|
||||
void test05()
|
||||
{
|
||||
using namespace std;
|
||||
typedef istreambuf_iterator<char> InIt;
|
||||
|
||||
locale loc(locale::classic(), new My_money_io);
|
||||
|
||||
string bufferp("$1234.56");
|
||||
string buffern("$-1234.56");
|
||||
string bufferp_ns("1234.56");
|
||||
string buffern_ns("-1234.56");
|
||||
|
||||
bool intl = false;
|
||||
|
||||
InIt iendp, iendn, iendp_ns, iendn_ns;
|
||||
ios_base::iostate err;
|
||||
string valp, valn, valp_ns, valn_ns;
|
||||
|
||||
const money_get<char,InIt>& mg =
|
||||
use_facet<money_get<char, InIt> >(loc);
|
||||
|
||||
istringstream fmtp(bufferp);
|
||||
fmtp.imbue(loc);
|
||||
InIt ibegp(fmtp);
|
||||
mg.get(ibegp,iendp,intl,fmtp,err,valp);
|
||||
VERIFY( valp == "123456" );
|
||||
|
||||
istringstream fmtn(buffern);
|
||||
fmtn.imbue(loc);
|
||||
InIt ibegn(fmtn);
|
||||
mg.get(ibegn,iendn,intl,fmtn,err,valn);
|
||||
VERIFY( valn == "-123456" );
|
||||
|
||||
istringstream fmtp_ns(bufferp_ns);
|
||||
fmtp_ns.imbue(loc);
|
||||
InIt ibegp_ns(fmtp_ns);
|
||||
mg.get(ibegp_ns,iendp_ns,intl,fmtp_ns,err,valp_ns);
|
||||
VERIFY( valp_ns == "123456" );
|
||||
|
||||
istringstream fmtn_ns(buffern_ns);
|
||||
fmtn_ns.imbue(loc);
|
||||
InIt ibegn_ns(fmtn_ns);
|
||||
mg.get(ibegn_ns,iendn_ns,intl,fmtn_ns,err,valn_ns);
|
||||
VERIFY( valn_ns == "-123456" );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
test02();
|
||||
test03();
|
||||
test04();
|
||||
test05();
|
||||
return 0;
|
||||
}
|
||||
|
@ -310,8 +310,81 @@ void test04()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
class My_money_io : public std::moneypunct<wchar_t,false>
|
||||
{
|
||||
public:
|
||||
explicit My_money_io(size_t r = 0): std::moneypunct<wchar_t,false>(r) { }
|
||||
char_type do_decimal_point() const { return L'.'; }
|
||||
char_type do_thousands_sep() const { return L','; }
|
||||
std::string do_grouping() const { return "\004"; }
|
||||
|
||||
std::wstring do_curr_symbol() const { return L"$"; }
|
||||
std::wstring do_positive_sign() const { return L""; }
|
||||
std::wstring do_negative_sign() const { return L"-"; }
|
||||
|
||||
int do_frac_digits() const { return 2; }
|
||||
|
||||
pattern do_pos_format() const
|
||||
{
|
||||
static pattern pat = { { symbol, none, sign, value } };
|
||||
return pat;
|
||||
}
|
||||
|
||||
pattern do_neg_format() const
|
||||
{
|
||||
static pattern pat = { { symbol, none, sign, value } };
|
||||
return pat;
|
||||
}
|
||||
};
|
||||
|
||||
// libstdc++/5579
|
||||
void test05()
|
||||
{
|
||||
using namespace std;
|
||||
typedef istreambuf_iterator<wchar_t> InIt;
|
||||
|
||||
locale loc(locale::classic(), new My_money_io);
|
||||
|
||||
wstring bufferp(L"$1234.56");
|
||||
wstring buffern(L"$-1234.56");
|
||||
wstring bufferp_ns(L"1234.56");
|
||||
wstring buffern_ns(L"-1234.56");
|
||||
|
||||
bool intl = false;
|
||||
|
||||
InIt iendp, iendn, iendp_ns, iendn_ns;
|
||||
ios_base::iostate err;
|
||||
wstring valp, valn, valp_ns, valn_ns;
|
||||
|
||||
const money_get<wchar_t,InIt>& mg =
|
||||
use_facet<money_get<wchar_t, InIt> >(loc);
|
||||
|
||||
wistringstream fmtp(bufferp);
|
||||
fmtp.imbue(loc);
|
||||
InIt ibegp(fmtp);
|
||||
mg.get(ibegp,iendp,intl,fmtp,err,valp);
|
||||
VERIFY( valp == L"123456" );
|
||||
|
||||
wistringstream fmtn(buffern);
|
||||
fmtn.imbue(loc);
|
||||
InIt ibegn(fmtn);
|
||||
mg.get(ibegn,iendn,intl,fmtn,err,valn);
|
||||
VERIFY( valn == L"-123456" );
|
||||
|
||||
wistringstream fmtp_ns(bufferp_ns);
|
||||
fmtp_ns.imbue(loc);
|
||||
InIt ibegp_ns(fmtp_ns);
|
||||
mg.get(ibegp_ns,iendp_ns,intl,fmtp_ns,err,valp_ns);
|
||||
VERIFY( valp_ns == L"123456" );
|
||||
|
||||
wistringstream fmtn_ns(buffern_ns);
|
||||
fmtn_ns.imbue(loc);
|
||||
InIt ibegn_ns(fmtn_ns);
|
||||
mg.get(ibegn_ns,iendn_ns,intl,fmtn_ns,err,valn_ns);
|
||||
VERIFY( valn_ns == L"-123456" );
|
||||
}
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
@ -320,6 +393,7 @@ int main()
|
||||
test02();
|
||||
test03();
|
||||
test04();
|
||||
test05();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user