diff options
author | Paolo Carlini <pcarlini@unitus.it> | 2002-02-26 21:56:24 +0100 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2002-02-26 20:56:24 +0000 |
commit | 2d13abcf868ab46317b62f14702fa62c7948f212 (patch) | |
tree | d51601783a5306bccf35929ddfdc9ad4d3aab9bb | |
parent | 06e224f7e851bf8bf6bb5adfe52ae99de43197aa (diff) | |
download | gcc-2d13abcf868ab46317b62f14702fa62c7948f212.zip gcc-2d13abcf868ab46317b62f14702fa62c7948f212.tar.gz gcc-2d13abcf868ab46317b62f14702fa62c7948f212.tar.bz2 |
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
-rw-r--r-- | libstdc++-v3/ChangeLog | 7 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/locale_facets.tcc | 28 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc | 41 |
3 files changed, 58 insertions, 18 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 12baa57..fc4229c 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +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> * src/ios.cc (ios_base::~ios_base): Tweak. diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 02ae96e..4f4cb11 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -726,18 +726,32 @@ namespace std * __len * 2)); __ctype.widen(__cs, __cs + __len, __ws); - // Add grouping, if necessary. + // Add grouping, if necessary. const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc); const string __grouping = __np.grouping(); - ios_base::fmtflags __basefield = __io.flags() & ios_base::basefield; - bool __dec = __basefield != ios_base::oct - && __basefield != ios_base::hex; - if (__grouping.size() && __dec) + const ios_base::fmtflags __basefield = __io.flags() & ios_base::basefield; + if (__grouping.size()) { + // 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; - __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(), - __ws, __ws + __len); + __ws + __off, __ws + __len); __len = __p - __ws2; // Switch strings. __ws = __ws2; diff --git a/libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc b/libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc index e84d2e6..1c5522b 100644 --- a/libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc +++ b/libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc @@ -45,8 +45,12 @@ int test01() { 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; oss.imbue(std::locale(std::locale(), new MyNP)); oss << std::oct << std::showbase; @@ -55,15 +59,27 @@ test01() oss << ":" << std::setw(11); oss << -01234567l << ":" << std::endl; - oss << ":" << std::setw(11) << std::left; + oss << ":" << std::setw(18) << std::left; oss << -0123456l << ":" << std::endl; - oss << ":" << std::setw(11) << std::right; + oss << ":" << std::setw(18) << std::right; oss << -012345l << ":" << std::endl; - oss << ":" << std::setw(11) << std::internal; + oss << ":" << std::setw(18) << std::internal; 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::setfill('0'); oss << std::internal; @@ -112,11 +128,14 @@ main() // Projected output: /* --0 123 456 -:-01 234 567: -:-0 123 456 : -: -012 345: -:- 01 234: +037 777 654 322 +:037 776 543 211: +:037 777 654 322 : +: 037 777 765 433: +: 037 777 776 544: +: 04 553 207: +:0361 100 : +: 030 071: +: 02 322: 0x000012 345 678 */ - |