This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] Group all the integral types, not only decs


Hi,

I have committed mainline and branch the following patch, approved by Benjamin
Kosnik. Tested i686-pc-linux-gnu.

Ciao, Paolo.

///////////////

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.

===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/locale_facets.tcc,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -r1.63 -r1.64
--- gcc/libstdc++-v3/include/bits/locale_facets.tcc     2002/02/18 21:23:24
1.63
+++ gcc/libstdc++-v3/include/bits/locale_facets.tcc     2002/02/26 20:56:24
1.64
@@ -726,18 +726,32 @@
                                                            * __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;

===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- gcc/libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc     2002/02/20
21:06:41     1.6
+++ gcc/libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc     2002/02/26
20:56:24     1.7
@@ -45,8 +45,12 @@
 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 @@
   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 @@

 // 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
 */
-



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]