locale_facets.tcc (num_put::_M_widen_int): Group all the integral types, not only...
authorPaolo Carlini <pcarlini@unitus.it>
Tue, 26 Feb 2002 20:56:24 +0000 (21:56 +0100)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 26 Feb 2002 20:56:24 +0000 (20:56 +0000)
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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/locale_facets.tcc
libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc

index 12baa573132770783e46a7d336907d1a747a4cac..fc4229c86f9411c5cbc457578268eb4324a2fe0c 100644 (file)
@@ -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.
index 02ae96eeb51269e032e0225e838dfcec1873603b..4f4cb11ea636d3e6ba78e8e90cd3c857d3a3d7bb 100644 (file)
@@ -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;
index e84d2e6705cfab0bf1873a9a37ea441e18bda59e..1c5522b9809640a16915be1552603c1f04d24c6c 100644 (file)
@@ -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
 */
-