From: Paolo Carlini Date: Thu, 29 Nov 2001 22:31:02 +0000 (+0100) Subject: locale_facets.tcc (__pad): Add bool parameter to correctly pad internal-adjusted... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b3340046164ef39d1a2d30e49314511f96aa8d23;p=gcc.git locale_facets.tcc (__pad): Add bool parameter to correctly pad internal-adjusted const char*-type objects. 2001-11-29 Paolo Carlini 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 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 58e899f3cfc..410041da435 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,14 @@ +2001-11-29 Paolo Carlini + + 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 * docs/html/ext/howto.html: Finish allocator notes (inst and 3.0). @@ -9,7 +20,6 @@ 2001-11-28 Paolo Carlini - libstdc++/3655 * include/bits/locale_facets.tcc (__pad): Correctly pad internal-adjusted hex numbers. * testsuite/27_io/ostream_inserter_arith.cc: Add testcase. diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 894fa4929fc..835a0ae62a6 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -814,7 +814,7 @@ namespace std streamsize __w = __io.width(); if (__w > static_cast(__len)) { - __pad(__io, __fill, __ws2, __ws, __w, __len); + __pad(__io, __fill, __ws2, __ws, __w, __len, true); __len = static_cast(__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 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 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. diff --git a/libstdc++-v3/include/bits/ostream.tcc b/libstdc++-v3/include/bits/ostream.tcc index 8ecd01998c2..ff3c958c05e 100644 --- a/libstdc++-v3/include/bits/ostream.tcc +++ b/libstdc++-v3/include/bits/ostream.tcc @@ -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(_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(_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; } diff --git a/libstdc++-v3/src/locale-inst.cc b/libstdc++-v3/src/locale-inst.cc index 5107a2963d4..0688db9104d 100644 --- a/libstdc++-v3/src/locale-inst.cc +++ b/libstdc++-v3/src/locale-inst.cc @@ -337,12 +337,12 @@ namespace std template void __pad(ios_base&, char, char*, const char *, streamsize, - streamsize); + streamsize, const bool); template void - __pad >(ios_base&, char, char*, - const char *, streamsize, streamsize); + __pad >(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(ios_base&, wchar_t, wchar_t*, const wchar_t*, - streamsize, streamsize); + streamsize, streamsize, const bool); template void __pad >(ios_base&, wchar_t, wchar_t*, - const wchar_t*, - streamsize, streamsize); + const wchar_t*, streamsize, + streamsize, const bool); #endif // _GLIBCPP_USE_WCHAR_T template diff --git a/libstdc++-v3/testsuite/27_io/ostream_inserter_arith.cc b/libstdc++-v3/testsuite/27_io/ostream_inserter_arith.cc index 25a0c1283a5..2e57922b1e9 100644 --- a/libstdc++-v3/testsuite/27_io/ostream_inserter_arith.cc +++ b/libstdc++-v3/testsuite/27_io/ostream_inserter_arith.cc @@ -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; }