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]

[PATCH] Properly align boolalpha-ized booleans


Hi,

some time ago (in a note of PR1019) I noticed that the test
27_io/ios_manip_fmtflags.cc, instead of the projected output:

1 0
true false
:  true:
:true  :
: false:
:  1:
:1  :
:  0:
yea nay
:   yea:
:yea   :
:   nay:

did produce:

1 0
true false
:true     :
:true:     
:false     :
:  1:
:1  :
:  0:
yea nay
:yea     :
:yea:     
:nay     :

i.e., boolalpha-ized booleans were not properly aligned.

To date, this minor feature is still not implemented in the body of
num_put<_CharT, _OutIter>::
  do_put(iter_type __s, ios_base& __io, char_type __fill, bool __v) const

Therefore, I implemented it, closely following the style and conventions of
the other members functions having to do with alignment and data padding.

As usual, I tested the code on i686-pc-linux-gnu. The patch should be in
general safe, involving only the body of that function, without side effects,
dealing only with the output of booleans.

At this point, perhaps it would be useful to check in
27_io/ios_manip_fmtflags.cc that the actual output matches the expected. What
do you suggest about this? (I'm not so much into DejaGnu, unfortunately ;-)

Cheers,
Paolo Carlini.

*** locale_facets.tcc.orig      Wed Oct 31 20:33:55 2001
--- locale_facets.tcc   Wed Oct 31 23:47:21 2001
*************** namespace std
*** 662,670 ****
                __first = __fmt->_M_falsename.data();
                __last = __first + __fmt->_M_falsename.size();
              }
!           copy(__first, __last, __s);
!         }
!       return __s;
      }
  
    template<typename _CharT, typename _OutIter, typename _ValueT>
--- 662,686 ----
                __first = __fmt->_M_falsename.data();
                __last = __first + __fmt->_M_falsename.size();
              }
!         streamsize __width = __io.width(0);
!         if (__last - __first >= __width)
!           return copy(__first, __last, __s);
!         else
!           {
!             int __padding = __width - (__last - __first);
!             ios_base::fmtflags __aflags = __flags & ios_base::adjustfield;
!             if (__aflags != ios_base::left)
!               {
!                 __pad(__s, __fill, __padding);
!                 return copy(__first, __last, __s);
!               }
!             else
!               {
!                 copy(__first, __last, __s);
!                 return __pad(__s, __fill, __padding);
!               }
!           }
!       }
      }
  
    template<typename _CharT, typename _OutIter, typename _ValueT>


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