diff options
author | Paolo Carlini <pcarlini@unitus.it> | 2001-11-02 04:48:09 +0100 |
---|---|---|
committer | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2001-11-02 03:48:09 +0000 |
commit | 2dc8835ac8fd61aee2e5a3e68a66adf305bd62b5 (patch) | |
tree | 7a4c2f7f2c91db37f7fbfdbae56101129be185e4 /libstdc++-v3 | |
parent | b8a2a84bbe495a4f255fb5f973a8703339c33059 (diff) | |
download | gcc-2dc8835ac8fd61aee2e5a3e68a66adf305bd62b5.zip gcc-2dc8835ac8fd61aee2e5a3e68a66adf305bd62b5.tar.gz gcc-2dc8835ac8fd61aee2e5a3e68a66adf305bd62b5.tar.bz2 |
ios_manip_fmtflags.cc: Fix for non-interactive output.
2001-11-01 Paolo Carlini <pcarlini@unitus.it>
Benjamin Kosnik <bkoz@redhat.com>
* testsuite/27_io/ios_manip_fmtflags.cc: Fix for non-interactive
output.
* include/bits/locale_facets.tcc (num_put::do_put(bool)): Fix.
Co-Authored-By: Benjamin Kosnik <bkoz@redhat.com>
From-SVN: r46709
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 7 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/locale_facets.tcc | 22 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/ios_manip_fmtflags.cc | 72 |
3 files changed, 66 insertions, 35 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f29936c..988bfbf 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2001-11-01 Paolo Carlini <pcarlini@unitus.it> + Benjamin Kosnik <bkoz@redhat.com> + + * testsuite/27_io/ios_manip_fmtflags.cc: Fix for non-interactive + output. + * include/bits/locale_facets.tcc (num_put::do_put(bool)): Fix. + 2001-11-01 Egor Duda <deo@logos-m.ru> * config/os/newlib/bits/ctype_noninline.h diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 4b2de13a..0fe180b 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -662,9 +662,25 @@ namespace std __first = __fmt->_M_falsename.data(); __last = __first + __fmt->_M_falsename.size(); } - copy(__first, __last, __s); - } - return __s; + 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> diff --git a/libstdc++-v3/testsuite/27_io/ios_manip_fmtflags.cc b/libstdc++-v3/testsuite/27_io/ios_manip_fmtflags.cc index 5fe1194..a8391d2 100644 --- a/libstdc++-v3/testsuite/27_io/ios_manip_fmtflags.cc +++ b/libstdc++-v3/testsuite/27_io/ios_manip_fmtflags.cc @@ -1,6 +1,6 @@ // 981027 ncm work with libstdc++v3 -// Copyright (C) 1997-1999, 2000 Free Software Foundation, Inc. +// Copyright (C) 1997-2001 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -27,7 +27,6 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#include <iostream> #include <sstream> #include <locale> #include <iomanip> @@ -39,41 +38,52 @@ struct MyNP : std::numpunct<char> std::string do_falsename() const; }; -std::string MyNP::do_truename() const { static std::string s("yea"); return s; } -std::string MyNP::do_falsename() const { static std::string s("nay"); return s; } +std::string MyNP::do_truename() const +{ + static std::string s("yea"); + return s; +} + +std::string MyNP::do_falsename() const +{ + static std::string s("nay"); + return s; +} -int +void test01() { - std::cout << true << " " << false << std::endl; - std::cout << std::boolalpha; - std::cout << true << " " << false << std::endl; - - std::cout << ":" << std::setw(6) << std::internal << true << ":" << std::endl; - std::cout << ":" << std::setw(6) << std::left << true << ":" << std::endl; - std::cout << ":" << std::setw(6) << std::right << false << ":" << std::endl; - std::cout << std::noboolalpha; - std::cout << ":" << std::setw(3) << std::internal << true << ":" << std::endl; - std::cout << ":" << std::setw(3) << std::left << true << ":" << std::endl; - std::cout << ":" << std::setw(3) << std::right << false << ":" << std::endl; + bool test = true; + const char lit[] = "1 0\ntrue false\n: true:\n:true :\n: false:\n: 1:" + "\n:1 :\n: 0:\nyea nay\n: yea:\n:yea :\n: nay:\n"; + std::ostringstream oss; + oss << true << " " << false << std::endl; + oss << std::boolalpha; + oss << true << " " << false << std::endl; + + oss << ":" << std::setw(6) << std::internal << true << ":" << std::endl; + oss << ":" << std::setw(6) << std::left << true << ":" << std::endl; + oss << ":" << std::setw(6) << std::right << false << ":" << std::endl; + oss << std::noboolalpha; + oss << ":" << std::setw(3) << std::internal << true << ":" << std::endl; + oss << ":" << std::setw(3) << std::left << true << ":" << std::endl; + oss << ":" << std::setw(3) << std::right << false << ":" << std::endl; std::locale loc = std::locale (std::locale(), new MyNP); - std::cout.imbue(loc); + oss.imbue(loc); - std::cout << std::boolalpha; - std::cout << true << " " << false << std::endl; + oss << std::boolalpha; + oss << true << " " << false << std::endl; - std::cout << ":" << std::setw(6) << std::internal << true << ":" << std::endl; - std::cout << ":" << std::setw(6) << std::left << true << ":" << std::endl; - std::cout << ":" << std::setw(6) << std::right << false << ":" << std::endl; + oss << ":" << std::setw(6) << std::internal << true << ":" << std::endl; + oss << ":" << std::setw(6) << std::left << true << ":" << std::endl; + oss << ":" << std::setw(6) << std::right << false << ":" << std::endl; -#ifdef DEBUG_ASSERT - assert (std::cout.good()); -#endif - return 0; + VERIFY( oss.good() ); + VERIFY( oss.str() == lit ); } -int +void test02() { bool test = true; @@ -96,14 +106,12 @@ test02() str02 = ostr01.str(); VERIFY( str02 == sfalse ); -#ifdef DEBUG_ASSERT - assert(test); -#endif - return 0; + VERIFY( test ); } int -main() { +main() +{ test01(); test02(); return 0; |