diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2014-03-07 21:45:32 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2014-03-07 21:45:32 +0000 |
commit | b90686c1ec584d2e9dc91b32384d8782f99a9fd9 (patch) | |
tree | 8136a24ce7e00707bd39db3762b729bea0acd1a5 | |
parent | 471f3c67db32e9d0592bdd80bfb93765749508a8 (diff) | |
download | libcxx_35a-b90686c1ec584d2e9dc91b32384d8782f99a9fd9.tar.gz |
Implement LWG #2344: quoted()'s interaction with padding is unclear. I think that anyone using quoted with padding is really confused, but it should work the way the rest of iostreams works.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@203290 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/iomanip | 11 | ||||
-rw-r--r-- | test/input.output/iostream.format/quoted.manip/quoted.pass.cpp | 23 |
2 files changed, 25 insertions, 9 deletions
diff --git a/include/iomanip b/include/iomanip index e334c7de..a5042c7d 100644 --- a/include/iomanip +++ b/include/iomanip @@ -519,15 +519,16 @@ std::basic_ostream<_CharT, _Traits> & __quoted_output ( basic_ostream<_CharT, _Traits> &__os, _ForwardIterator __first, _ForwardIterator __last, _CharT __delim, _CharT __escape ) { - __os << __delim; + _VSTD::basic_string<_CharT, _Traits> __str; + __str.push_back(__delim); for ( ; __first != __last; ++ __first ) { if (_Traits::eq (*__first, __escape) || _Traits::eq (*__first, __delim)) - __os << __escape; - __os << *__first; + __str.push_back(__escape); + __str.push_back(*__first); } - __os << __delim; - return __os; + __str.push_back(__delim); + return __put_character_sequence(__os, __str.data(), __str.size()); } template <class _CharT, class _Traits, class _String> diff --git a/test/input.output/iostream.format/quoted.manip/quoted.pass.cpp b/test/input.output/iostream.format/quoted.manip/quoted.pass.cpp index 1f6b1267..d09b3cae 100644 --- a/test/input.output/iostream.format/quoted.manip/quoted.pass.cpp +++ b/test/input.output/iostream.format/quoted.manip/quoted.pass.cpp @@ -28,13 +28,13 @@ bool is_skipws ( const std::wistream *is ) { } void both_ways ( const char *p ) { - std::string str(p); - auto q = std::quoted(str); + std::string str(p); + auto q = std::quoted(str); std::stringstream ss; bool skippingws = is_skipws ( &ss ); - ss << q; - ss >> q; + ss << q; + ss >> q; } void round_trip ( const char *p ) { @@ -92,6 +92,20 @@ std::string unquote ( const char *p, char delim='"', char escape='\\' ) { return s; } +void test_padding () { + { + std::stringstream ss; + ss << std::left << std::setw(10) << std::setfill('!') << std::quoted("abc", '`'); + assert ( ss.str() == "`abc`!!!!!" ); + } + + { + std::stringstream ss; + ss << std::right << std::setw(10) << std::setfill('!') << std::quoted("abc", '`'); + assert ( ss.str() == "!!!!!`abc`" ); + } +} + void round_trip ( const wchar_t *p ) { std::wstringstream ss; @@ -197,6 +211,7 @@ int main() assert ( unquote ( "" ) == "" ); // nothing there assert ( unquote ( L"" ) == L"" ); // nothing there + test_padding (); } #else |