+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).
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.
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;
// 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;
__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.
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.
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);
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);
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;
}
if (__w > __len)
{
- __pad(__out, __out.fill(), __pads, __ws, __w, __len);
+ __pad(__out, __out.fill(), __pads, __ws, __w, __len, false);
__str = __pads;
__len = __w;
}
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;
}
#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;
}
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
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
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;
}