Commit b3340046 by Paolo Carlini Committed by Benjamin Kosnik

locale_facets.tcc (__pad): Add bool parameter to correctly pad internal-adjusted…

locale_facets.tcc (__pad): Add bool parameter to correctly pad internal-adjusted const char*-type objects.


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
parent 7d5b8b11
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> 2001-11-29 Phil Edwards <pme@gcc.gnu.org>
* docs/html/ext/howto.html: Finish allocator notes (inst and 3.0). * docs/html/ext/howto.html: Finish allocator notes (inst and 3.0).
...@@ -9,7 +20,6 @@ ...@@ -9,7 +20,6 @@
2001-11-28 Paolo Carlini <pcarlini@unitus.it> 2001-11-28 Paolo Carlini <pcarlini@unitus.it>
libstdc++/3655
* include/bits/locale_facets.tcc (__pad): Correctly pad * include/bits/locale_facets.tcc (__pad): Correctly pad
internal-adjusted hex numbers. internal-adjusted hex numbers.
* testsuite/27_io/ostream_inserter_arith.cc: Add testcase. * testsuite/27_io/ostream_inserter_arith.cc: Add testcase.
......
...@@ -814,7 +814,7 @@ namespace std ...@@ -814,7 +814,7 @@ namespace std
streamsize __w = __io.width(); streamsize __w = __io.width();
if (__w > static_cast<streamsize>(__len)) 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); __len = static_cast<int>(__w);
// Switch strings. // Switch strings.
__ws = __ws2; __ws = __ws2;
...@@ -1913,11 +1913,15 @@ namespace std ...@@ -1913,11 +1913,15 @@ namespace std
// Assumes // Assumes
// __newlen > __oldlen // __newlen > __oldlen
// __news is allocated for __newlen size // __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> template<typename _CharT, typename _Traits>
void void
__pad(ios_base& __io, _CharT __fill, _CharT* __news, const _CharT* __olds, __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 _CharT char_type;
typedef _Traits traits_type; typedef _Traits traits_type;
...@@ -1940,7 +1944,7 @@ namespace std ...@@ -1940,7 +1944,7 @@ namespace std
__beglen = __oldlen; __beglen = __oldlen;
__end = __pads; __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 the sign, if there is one.
// Pad after 0[xX], if there is one. // Pad after 0[xX], if there is one.
...@@ -1997,10 +2001,11 @@ namespace std ...@@ -1997,10 +2001,11 @@ namespace std
template<typename _CharT> template<typename _CharT>
void void
__pad(ios_base& __io, _CharT __fill, _CharT* __news, const _CharT* __olds, __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, return __pad<_CharT, char_traits<_CharT> >(__io, __fill, __news, __olds,
__olds, __newlen, __oldlen); __newlen, __oldlen, __num);
} }
// Used by both numeric and monetary facets. // Used by both numeric and monetary facets.
......
...@@ -481,7 +481,7 @@ namespace std ...@@ -481,7 +481,7 @@ namespace std
streamsize __len = 1; streamsize __len = 1;
if (__w > __len) if (__w > __len)
{ {
__pad(__out, __out.fill(), __pads, &__c, __w, __len); __pad(__out, __out.fill(), __pads, &__c, __w, __len, false);
__len = __w; __len = __w;
} }
__out.write(__pads, __len); __out.write(__pads, __len);
...@@ -516,7 +516,7 @@ namespace std ...@@ -516,7 +516,7 @@ namespace std
streamsize __len = 1; streamsize __len = 1;
if (__w > __len) if (__w > __len)
{ {
__pad(__out, __out.fill(), __pads, &__c, __w, __len); __pad(__out, __out.fill(), __pads, &__c, __w, __len, false);
__len = __w; __len = __w;
} }
__out.write(__pads, __len); __out.write(__pads, __len);
...@@ -549,7 +549,7 @@ namespace std ...@@ -549,7 +549,7 @@ namespace std
streamsize __len = static_cast<streamsize>(_Traits::length(__s)); streamsize __len = static_cast<streamsize>(_Traits::length(__s));
if (__w > __len) if (__w > __len)
{ {
__pad(__out, __out.fill(), __pads, __s, __w, __len); __pad(__out, __out.fill(), __pads, __s, __w, __len, false);
__s = __pads; __s = __pads;
__len = __w; __len = __w;
} }
...@@ -595,7 +595,7 @@ namespace std ...@@ -595,7 +595,7 @@ namespace std
if (__w > __len) if (__w > __len)
{ {
__pad(__out, __out.fill(), __pads, __ws, __w, __len); __pad(__out, __out.fill(), __pads, __ws, __w, __len, false);
__str = __pads; __str = __pads;
__len = __w; __len = __w;
} }
...@@ -630,7 +630,7 @@ namespace std ...@@ -630,7 +630,7 @@ namespace std
streamsize __len = static_cast<streamsize>(_Traits::length(__s)); streamsize __len = static_cast<streamsize>(_Traits::length(__s));
if (__w > __len) if (__w > __len)
{ {
__pad(__out, __out.fill(), __pads, __s, __w, __len); __pad(__out, __out.fill(), __pads, __s, __w, __len, false);
__s = __pads; __s = __pads;
__len = __w; __len = __w;
} }
...@@ -668,7 +668,7 @@ namespace std ...@@ -668,7 +668,7 @@ namespace std
#endif #endif
if (__w > __len) if (__w > __len)
{ {
__pad(__out, __out.fill(), __pads, __s, __w, __len); __pad(__out, __out.fill(), __pads, __s, __w, __len, false);
__s = __pads; __s = __pads;
__len = __w; __len = __w;
} }
......
...@@ -337,12 +337,12 @@ namespace std ...@@ -337,12 +337,12 @@ namespace std
template template
void void
__pad<char>(ios_base&, char, char*, const char *, streamsize, __pad<char>(ios_base&, char, char*, const char *, streamsize,
streamsize); streamsize, const bool);
template template
void void
__pad<char, char_traits<char> >(ios_base&, char, char*, __pad<char, char_traits<char> >(ios_base&, char, char*, const char *,
const char *, streamsize, streamsize); streamsize, streamsize, const bool);
#ifdef _GLIBCPP_USE_WCHAR_T #ifdef _GLIBCPP_USE_WCHAR_T
template template
...@@ -363,13 +363,13 @@ namespace std ...@@ -363,13 +363,13 @@ namespace std
template template
void void
__pad<wchar_t>(ios_base&, wchar_t, wchar_t*, const wchar_t*, __pad<wchar_t>(ios_base&, wchar_t, wchar_t*, const wchar_t*,
streamsize, streamsize); streamsize, streamsize, const bool);
template template
void void
__pad<wchar_t, char_traits<wchar_t> >(ios_base&, wchar_t, wchar_t*, __pad<wchar_t, char_traits<wchar_t> >(ios_base&, wchar_t, wchar_t*,
const wchar_t*, const wchar_t*, streamsize,
streamsize, streamsize); streamsize, const bool);
#endif // _GLIBCPP_USE_WCHAR_T #endif // _GLIBCPP_USE_WCHAR_T
template template
......
...@@ -312,12 +312,14 @@ test03() ...@@ -312,12 +312,14 @@ test03()
int int
test04() test04()
{ {
stringbuf strbuf; stringbuf strbuf1, strbuf2;
ostream o(&strbuf); ostream o1(&strbuf1), o2(&strbuf2);
o1 << hex << showbase << setw(6) << internal << 0xff;
o << hex << showbase << setw(6) << internal << 255; VERIFY( strbuf1.str() == "0x ff" );
VERIFY( strbuf.str() == "0x ff" );
// ... vs internal-adjusted const char*-type objects
o2 << hex << showbase << setw(6) << internal << "0xff";
VERIFY( strbuf2.str() == " 0xff" );
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment