This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

[PATCH] Group octs and hexs too (was: Re: [RFC] 27_io/ios_manip_basefield.cc)


Ok, here it is.

I think I have strictly implemented our current best interpretation. I have also
added a few more tests. If the patch is ok, please let me know if it is ok for
the branch too.

Another thing: of course there are no regressions in the testsuite, but I think
we have still to *carefully* check that this kind of output can be parsed
successfully by the corresponding get code. Benjamin could you possibly help me
on this? Which are the most delicate points?

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.

diff -prN libstdc++-v3-orig/include/bits/locale_facets.tcc
libstdc++-v3/include/bits/locale_facets.tcc
*** libstdc++-v3-orig/include/bits/locale_facets.tcc Mon Feb 18 20:57:11 2002
--- libstdc++-v3/include/bits/locale_facets.tcc Tue Feb 26 14:26:36 2002
*************** namespace std
*** 726,743 ****
             * __len * 2));
        __ctype.widen(__cs, __cs + __len, __ws);

!       // 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)
   {
     _CharT* __p;
!    __p = __add_grouping(__ws2, __np.thousands_sep(), __grouping.c_str(),
            __grouping.c_str() + __grouping.size(),
!           __ws, __ws + __len);
     __len = __p - __ws2;
     // Switch strings.
     __ws = __ws2;
--- 726,757 ----
             * __len * 2));
        __ctype.widen(__cs, __cs + __len, __ws);

!       // Add grouping, if necessary.
        const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
        const string __grouping = __np.grouping();
!       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 + __off, __np.thousands_sep(),
__grouping.c_str(),
            __grouping.c_str() + __grouping.size(),
!           __ws + __off, __ws + __len);
     __len = __p - __ws2;
     // Switch strings.
     __ws = __ws2;
diff -prN libstdc++-v3-orig/testsuite/27_io/ios_manip_basefield.cc
libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc
*** libstdc++-v3-orig/testsuite/27_io/ios_manip_basefield.cc Wed Feb 20 22:51:52
2002
--- libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc Tue Feb 26 21:14:20 2002

*************** int
*** 45,52 ****
  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";
    std::ostringstream oss;
    oss.imbue(std::locale(std::locale(), new MyNP));
    oss << std::oct << std::showbase;
--- 45,56 ----
  test01()
  {
    bool test = true;
!
!   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;
*************** test01()
*** 55,69 ****
    oss << ":" << std::setw(11);
    oss << -01234567l << ":" << std::endl;

!   oss << ":" << std::setw(11) << std::left;
    oss << -0123456l << ":" << std::endl;

!   oss << ":" << std::setw(11) << std::right;
    oss << -012345l << ":" << std::endl;

!   oss << ":" << std::setw(11) << std::internal;
    oss << -01234l << ":" << std::endl;

    oss << std::hex;
    oss << std::setfill('0');
    oss << std::internal;
--- 59,85 ----
    oss << ":" << std::setw(11);
    oss << -01234567l << ":" << std::endl;

!   oss << ":" << std::setw(18) << std::left;
    oss << -0123456l << ":" << std::endl;

!   oss << ":" << std::setw(18) << std::right;
    oss << -012345l << ":" << std::endl;

!   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;
*************** main()
*** 112,122 ****

  // Projected output:
  /*
! -0 123 456
! :-01 234 567:
! :-0 123 456 :
! :   -012 345:
! :-    01 234:
  0x000012 345 678
  */
-
--- 128,141 ----

  // Projected output:
  /*
! 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]