summaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@unitus.it>2002-02-04 20:51:32 +0100
committerPaolo Carlini <paolo@gcc.gnu.org>2002-02-04 19:51:32 +0000
commit53804e7c808fd0512da802348aa61d472263a709 (patch)
treed998abb5f16adb648bf040b0709b73aadab1468d /libstdc++-v3
parent24c545ff924c8a6a24f5b85f6352cac27bd18247 (diff)
downloadgcc-53804e7c808fd0512da802348aa61d472263a709.tar.gz
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
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog9
-rw-r--r--libstdc++-v3/include/bits/locale_facets.tcc17
-rw-r--r--libstdc++-v3/testsuite/22_locale/money_get_members_char.cc75
-rw-r--r--libstdc++-v3/testsuite/22_locale/money_get_members_wchar_t.cc76
4 files changed, 170 insertions, 7 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index c18850bedd0..6ca364e75f3 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -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
diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc
index 9cdcf019e40..e4595828461 100644
--- a/libstdc++-v3/include/bits/locale_facets.tcc
+++ b/libstdc++-v3/include/bits/locale_facets.tcc
@@ -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;
diff --git a/libstdc++-v3/testsuite/22_locale/money_get_members_char.cc b/libstdc++-v3/testsuite/22_locale/money_get_members_char.cc
index 705d8741fc6..84fb93d3f10 100644
--- a/libstdc++-v3/testsuite/22_locale/money_get_members_char.cc
+++ b/libstdc++-v3/testsuite/22_locale/money_get_members_char.cc
@@ -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;
}
diff --git a/libstdc++-v3/testsuite/22_locale/money_get_members_wchar_t.cc b/libstdc++-v3/testsuite/22_locale/money_get_members_wchar_t.cc
index 0e892e7f5e6..fcca3452b34 100644
--- a/libstdc++-v3/testsuite/22_locale/money_get_members_wchar_t.cc
+++ b/libstdc++-v3/testsuite/22_locale/money_get_members_wchar_t.cc
@@ -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;
}