locale_facets.tcc (__pad): Add bool parameter to correctly pad internal-adjusted...
authorPaolo Carlini <pcarlini@unitus.it>
Thu, 29 Nov 2001 22:31:02 +0000 (23:31 +0100)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Thu, 29 Nov 2001 22:31:02 +0000 (22:31 +0000)
2001-11-29  Paolo Carlini  <pcarlini@unitus.it>

libstdc++/3655
* include/bits/locale_facets.tcc (__pad): Add bool parameter to
correctly pad internal-adjusted const char*-type objects.
* include/bits/locale_facts.tcc (num_put::_M_insert): Update call.
* include/bits/ostream.tcc (operator<<(_CharT , char, const
_CharT*, const char*, const basic_string&): Update calls.
* src/locale-inst.tcc: Update declarations.
* testsuite/27_io/ostream_inserter_arith.cc (test04): Add test.

From-SVN: r47459

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/locale_facets.tcc
libstdc++-v3/include/bits/ostream.tcc
libstdc++-v3/src/locale-inst.cc
libstdc++-v3/testsuite/27_io/ostream_inserter_arith.cc

index 58e899f..410041d 100644 (file)
@@ -1,3 +1,14 @@
+2001-11-29  Paolo Carlini  <pcarlini@unitus.it>
+
+       libstdc++/3655
+       * include/bits/locale_facets.tcc (__pad): Add bool parameter to
+       correctly pad internal-adjusted const char*-type objects.
+       * include/bits/locale_facts.tcc (num_put::_M_insert): Update call.
+       * include/bits/ostream.tcc (operator<<(_CharT , char, const
+       _CharT*, const char*, const basic_string&): Update calls.
+       * src/locale-inst.tcc: Update declarations.
+       * testsuite/27_io/ostream_inserter_arith.cc (test04): Add test.
+
 2001-11-29  Phil Edwards  <pme@gcc.gnu.org>
 
        * docs/html/ext/howto.html:  Finish allocator notes (inst and 3.0).
@@ -9,7 +20,6 @@
 
 2001-11-28  Paolo Carlini  <pcarlini@unitus.it>
 
-       libstdc++/3655
        * include/bits/locale_facets.tcc (__pad): Correctly pad
        internal-adjusted hex numbers.
        * testsuite/27_io/ostream_inserter_arith.cc: Add testcase.
index 894fa49..835a0ae 100644 (file)
@@ -814,7 +814,7 @@ namespace std
       streamsize __w = __io.width();
       if (__w > static_cast<streamsize>(__len))
        {
-         __pad(__io, __fill, __ws2, __ws, __w, __len);
+         __pad(__io, __fill, __ws2, __ws, __w, __len, true);
          __len = static_cast<int>(__w);
          // Switch strings.
          __ws = __ws2;
@@ -1913,11 +1913,15 @@ namespace std
   // Assumes 
   // __newlen > __oldlen
   // __news is allocated for __newlen size
-  // Used by both num_put and ostream inserters.
+  // Used by both num_put and ostream inserters: if __num,
+  // internal-adjusted objects are padded according to the rules below
+  // concerning 0[xX] and +-, otherwise, exactly as right-adjusted
+  // ones are.
   template<typename _CharT, typename _Traits>
     void
     __pad(ios_base& __io, _CharT __fill, _CharT* __news, const _CharT* __olds,
-         const streamsize __newlen, const streamsize __oldlen)
+         const streamsize __newlen, const streamsize __oldlen, 
+         const bool __num)
     {
       typedef _CharT   char_type;
       typedef _Traits  traits_type;
@@ -1940,7 +1944,7 @@ namespace std
          __beglen = __oldlen;
          __end = __pads;
        }
-      else if (__adjust == ios_base::internal)
+      else if (__adjust == ios_base::internal && __num)
        {
          // Pad after the sign, if there is one.
          // Pad after 0[xX], if there is one.
@@ -1997,10 +2001,11 @@ namespace std
   template<typename _CharT>
     void
     __pad(ios_base& __io, _CharT __fill, _CharT* __news, const _CharT* __olds,
-         const streamsize __newlen, const streamsize __oldlen)
+         const streamsize __newlen, const streamsize __oldlen, 
+         const bool __num)
     { 
-      return __pad<_CharT, char_traits<_CharT> >(__io, __fill, __news, 
-                                                __olds, __newlen, __oldlen); 
+      return __pad<_CharT, char_traits<_CharT> >(__io, __fill, __news, __olds,
+                                                __newlen, __oldlen, __num); 
     }
 
   // Used by both numeric and monetary facets.
index 8ecd019..ff3c958 100644 (file)
@@ -481,7 +481,7 @@ namespace std
              streamsize __len = 1;
              if (__w > __len)
                {
-                 __pad(__out, __out.fill(), __pads, &__c, __w, __len);
+                 __pad(__out, __out.fill(), __pads, &__c, __w, __len, false);
                  __len = __w;
                }
              __out.write(__pads, __len);
@@ -516,7 +516,7 @@ namespace std
              streamsize __len = 1;
              if (__w > __len)
                {
-                 __pad(__out, __out.fill(), __pads, &__c, __w, __len);
+                 __pad(__out, __out.fill(), __pads, &__c, __w, __len, false);
                  __len = __w;
                }
              __out.write(__pads, __len);
@@ -549,7 +549,7 @@ namespace std
              streamsize __len = static_cast<streamsize>(_Traits::length(__s));
              if (__w > __len)
                {
-                 __pad(__out, __out.fill(), __pads, __s, __w, __len);
+                 __pad(__out, __out.fill(), __pads, __s, __w, __len, false);
                  __s = __pads;
                  __len = __w;
                }
@@ -595,7 +595,7 @@ namespace std
              
              if (__w > __len)
                {
-                 __pad(__out, __out.fill(), __pads, __ws, __w, __len);
+                 __pad(__out, __out.fill(), __pads, __ws, __w, __len, false);
                  __str = __pads;
                  __len = __w;
                }
@@ -630,7 +630,7 @@ namespace std
              streamsize __len = static_cast<streamsize>(_Traits::length(__s));
              if (__w > __len)
                {
-                 __pad(__out, __out.fill(), __pads, __s, __w, __len);
+                 __pad(__out, __out.fill(), __pads, __s, __w, __len, false);
                  __s = __pads;
                  __len = __w;
                }
@@ -668,7 +668,7 @@ namespace std
 #endif
          if (__w > __len)
            {
-             __pad(__out, __out.fill(), __pads, __s, __w, __len);
+             __pad(__out, __out.fill(), __pads, __s, __w, __len, false);
              __s = __pads;
              __len = __w;
            }
index 5107a29..0688db9 100644 (file)
@@ -337,12 +337,12 @@ namespace std
   template
     void 
     __pad<char>(ios_base&, char, char*, const char *, streamsize, 
-               streamsize);
+               streamsize, const bool);
 
   template
     void 
-    __pad<char, char_traits<char> >(ios_base&, char, char*, 
-                                   const char *, streamsize, streamsize);
+    __pad<char, char_traits<char> >(ios_base&, char, char*, const char *, 
+                                   streamsize, streamsize, const bool);
 
 #ifdef _GLIBCPP_USE_WCHAR_T
   template 
@@ -363,13 +363,13 @@ namespace std
   template
     void 
     __pad<wchar_t>(ios_base&, wchar_t, wchar_t*, const wchar_t*, 
-                  streamsize, streamsize);
+                  streamsize, streamsize, const bool);
 
   template
     void 
     __pad<wchar_t, char_traits<wchar_t> >(ios_base&, wchar_t, wchar_t*, 
-                                         const wchar_t*, 
-                                         streamsize, streamsize);
+                                         const wchar_t*, streamsize, 
+                                         streamsize, const bool);
 #endif // _GLIBCPP_USE_WCHAR_T
 
   template 
index 25a0c12..2e57922 100644 (file)
@@ -312,12 +312,14 @@ test03()
 int
 test04()
 {
-  stringbuf strbuf;
-  ostream o(&strbuf);
-
-  o << hex << showbase << setw(6) << internal << 255;
-  VERIFY( strbuf.str() == "0x  ff" );
+  stringbuf strbuf1, strbuf2;
+  ostream o1(&strbuf1), o2(&strbuf2);
+  o1 << hex << showbase << setw(6) << internal << 0xff;
+  VERIFY( strbuf1.str() == "0x  ff" );
   
+  // ... vs internal-adjusted const char*-type objects
+  o2 << hex << showbase << setw(6) << internal << "0xff";
+  VERIFY( strbuf2.str() == "  0xff" );
   return 0;
 }