Commit 2d13abcf by Paolo Carlini Committed by Paolo Carlini

locale_facets.tcc (num_put::_M_widen_int): Group all the integral types, not only decs.

2002-02-26  Paolo Carlini  <pcarlini@unitus.it>

	* include/bits/locale_facets.tcc (num_put::_M_widen_int):
	Group all the integral types, not only decs.
	* testsuite/27_io/ios_manip_basefield.cc (test01): Tweak existing
	tests, add a few more.

From-SVN: r50057
parent 06e224f7
2002-02-26 Paolo Carlini <pcarlini@unitus.it>
* include/bits/locale_facets.tcc (num_put::_M_widen_int):
Group all the integral types, not only decs.
* testsuite/27_io/ios_manip_basefield.cc (test01): Tweak existing
tests, add a few more.
2002-02-25 Benjamin Kosnik <bkoz@redhat.com> 2002-02-25 Benjamin Kosnik <bkoz@redhat.com>
* src/ios.cc (ios_base::~ios_base): Tweak. * src/ios.cc (ios_base::~ios_base): Tweak.
......
...@@ -729,15 +729,29 @@ namespace std ...@@ -729,15 +729,29 @@ namespace std
// Add grouping, if necessary. // Add grouping, if necessary.
const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc); const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
const string __grouping = __np.grouping(); const string __grouping = __np.grouping();
ios_base::fmtflags __basefield = __io.flags() & ios_base::basefield; const ios_base::fmtflags __basefield = __io.flags() & ios_base::basefield;
bool __dec = __basefield != ios_base::oct if (__grouping.size())
&& __basefield != ios_base::hex; {
if (__grouping.size() && __dec) // By itself __add_grouping cannot deal correctly with __ws when
// ios::showbase is set and ios_base::oct || ios_base::hex.
// Therefore we take care "by hand" of the initial 0, 0x or 0X.
streamsize __off = 0;
if (__io.flags() & ios_base::showbase)
if (__basefield == ios_base::oct)
{ {
__off = 1;
*__ws2 = *__ws;
}
else if (__basefield == ios_base::hex)
{
__off = 2;
*__ws2 = *__ws;
*(__ws2 + 1) = *(__ws + 1);
}
_CharT* __p; _CharT* __p;
__p = __add_grouping(__ws2, __np.thousands_sep(), __grouping.c_str(), __p = __add_grouping(__ws2 + __off, __np.thousands_sep(), __grouping.c_str(),
__grouping.c_str() + __grouping.size(), __grouping.c_str() + __grouping.size(),
__ws, __ws + __len); __ws + __off, __ws + __len);
__len = __p - __ws2; __len = __p - __ws2;
// Switch strings. // Switch strings.
__ws = __ws2; __ws = __ws2;
......
...@@ -45,8 +45,12 @@ int ...@@ -45,8 +45,12 @@ int
test01() test01()
{ {
bool test = true; bool test = true;
const char lit[] = "-0 123 456\n:-01 234 567:\n:-0 123 456 :"
"\n: -012 345:\n:- 01 234:\n0x000012 345 678"; const char lit[] = "037 777 654 322\n:037 776 543 211:\n:037 777 654 322 :\n"
": 037 777 765 433:\n: 037 777 776 544:\n: 04 553 207:\n"
":0361 100 :\n: 030 071:\n: 02 322:\n"
"0x000012 345 678\n";
std::ostringstream oss; std::ostringstream oss;
oss.imbue(std::locale(std::locale(), new MyNP)); oss.imbue(std::locale(std::locale(), new MyNP));
oss << std::oct << std::showbase; oss << std::oct << std::showbase;
...@@ -55,15 +59,27 @@ test01() ...@@ -55,15 +59,27 @@ test01()
oss << ":" << std::setw(11); oss << ":" << std::setw(11);
oss << -01234567l << ":" << std::endl; oss << -01234567l << ":" << std::endl;
oss << ":" << std::setw(11) << std::left; oss << ":" << std::setw(18) << std::left;
oss << -0123456l << ":" << std::endl; oss << -0123456l << ":" << std::endl;
oss << ":" << std::setw(11) << std::right; oss << ":" << std::setw(18) << std::right;
oss << -012345l << ":" << std::endl; oss << -012345l << ":" << std::endl;
oss << ":" << std::setw(11) << std::internal; oss << ":" << std::setw(18) << std::internal;
oss << -01234l << ":" << std::endl; oss << -01234l << ":" << std::endl;
oss << ":" << std::setw(11);
oss << 1234567l << ":" << std::endl;
oss << ":" << std::setw(11) << std::left;
oss << 123456l << ":" << std::endl;
oss << ":" << std::setw(11) << std::right;
oss << 12345l << ":" << std::endl;
oss << ":" << std::setw(11) << std::internal;
oss << 1234l << ":" << std::endl;
oss << std::hex; oss << std::hex;
oss << std::setfill('0'); oss << std::setfill('0');
oss << std::internal; oss << std::internal;
...@@ -112,11 +128,14 @@ main() ...@@ -112,11 +128,14 @@ main()
// Projected output: // Projected output:
/* /*
-0 123 456 037 777 654 322
:-01 234 567: :037 776 543 211:
:-0 123 456 : :037 777 654 322 :
: -012 345: : 037 777 765 433:
:- 01 234: : 037 777 776 544:
: 04 553 207:
:0361 100 :
: 030 071:
: 02 322:
0x000012 345 678 0x000012 345 678
*/ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment