* include/bits/locale_facets.tcc (money_get::do_get(string)):
First construct a tentative returned string, then, only if the
parsing succeeds, copy it into the string passed by reference.
* testsuite/22_locale/money_get_members_char.cc: Add test06.
* testsuite/22_locale/money_get_members_wchar_t.cc: Add test06.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@49523
138bc75d-0d04-0410-961f-
82ee72b054a4
+2002-02-05 Paolo Carlini <pcarlini@unitus.it>
+
+ * include/bits/locale_facets.tcc (money_get::do_get(string)):
+ First construct a tentative returned string, then, only if the
+ parsing succeeds, copy it into the string passed by reference.
+ * testsuite/22_locale/money_get_members_char.cc: Add test06.
+ * testsuite/22_locale/money_get_members_wchar_t.cc: Add test06.
+
2002-02-04 Phil Edwards <pme@gcc.gnu.org>
* docs/doxygen/TODO: Impl-defined behavior now documented...
// Flag marking when a decimal point is found.
bool __testdecfound = false;
+ // The tentative returned string is stored here.
+ string_type __temp_units;
+
char_type __c = *__beg;
char_type __eof = static_cast<char_type>(char_traits<char_type>::eof());
for (int __i = 0; __beg != __end && __i < 4 && __testvalid; ++__i)
}
else
{
- __units += __c;
+ __temp_units += __c;
++__sep_pos;
}
__c = *(++__beg);
}
// Strip leading zeros.
- while (__units[0] == __ctype.widen('0'))
- __units.erase(__units.begin());
+ while (__temp_units[0] == __ctype.widen('0'))
+ __temp_units.erase(__temp_units.begin());
if (__sign.size() && __sign == __neg_sign)
- __units.insert(__units.begin(), __ctype.widen('-'));
+ __temp_units.insert(__temp_units.begin(), __ctype.widen('-'));
// Test for grouping fidelity.
if (__grouping.size() && __grouping_tmp.size())
__err |= ios_base::eofbit;
// Iff valid sequence is not recognized.
- if (!__testvalid || !__units.size())
+ if (!__testvalid || !__temp_units.size())
__err |= ios_base::failbit;
+ else
+ // Use the "swap trick" to copy __temp_units into __units.
+ __temp_units.swap(__units);
+
return __beg;
}
VERIFY( valn_ns == "-123456" );
}
+void test06()
+{
+ using namespace std;
+
+ typedef istreambuf_iterator<char> InIt;
+ InIt iend1, iend2, iend3;
+
+ locale loc;
+ string buffer1("123");
+ string buffer2("456");
+ string buffer3("Golgafrincham"); // From Nathan's original idea.
+
+ string val;
+
+ ios_base::iostate err;
+
+ const money_get<char,InIt>& mg =
+ use_facet<money_get<char, InIt> >(loc);
+
+ istringstream fmt1(buffer1);
+ InIt ibeg1(fmt1);
+ mg.get(ibeg1,iend1,false,fmt1,err,val);
+ VERIFY( val == buffer1 );
+
+ istringstream fmt2(buffer2);
+ InIt ibeg2(fmt2);
+ mg.get(ibeg2,iend2,false,fmt2,err,val);
+ VERIFY( val == buffer2 );
+
+ val = buffer3;
+ istringstream fmt3(buffer3);
+ InIt ibeg3(fmt3);
+ mg.get(ibeg3,iend3,false,fmt3,err,val);
+ VERIFY( val == buffer3 );
+}
+
int main()
{
test01();
test03();
test04();
test05();
+ test06();
return 0;
}
mg.get(ibegn_ns,iendn_ns,intl,fmtn_ns,err,valn_ns);
VERIFY( valn_ns == L"-123456" );
}
+
+void test06()
+{
+ using namespace std;
+
+ typedef istreambuf_iterator<wchar_t> InIt;
+ InIt iend1, iend2, iend3;
+
+ locale loc;
+ wstring buffer1(L"123");
+ wstring buffer2(L"456");
+ wstring buffer3(L"Golgafrincham");
+
+ wstring val;
+
+ ios_base::iostate err;
+
+ const money_get<wchar_t,InIt>& mg =
+ use_facet<money_get<wchar_t, InIt> >(loc);
+
+ wistringstream fmt1(buffer1);
+ InIt ibeg1(fmt1);
+ mg.get(ibeg1,iend1,false,fmt1,err,val);
+ VERIFY( val == buffer1 );
+
+ wistringstream fmt2(buffer2);
+ InIt ibeg2(fmt2);
+ mg.get(ibeg2,iend2,false,fmt2,err,val);
+ VERIFY( val == buffer2 );
+
+ val = buffer3;
+ wistringstream fmt3(buffer3);
+ InIt ibeg3(fmt3);
+ mg.get(ibeg3,iend3,false,fmt3,err,val);
+ VERIFY( val == buffer3 );
+}
#endif
int main()
test03();
test04();
test05();
+ test06();
#endif
return 0;
}