[libcxx] r203290 - 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.

Marshall Clow mclow.lists at gmail.com
Fri Mar 7 13:45:32 PST 2014


Author: marshall
Date: Fri Mar  7 15:45:32 2014
New Revision: 203290

URL: http://llvm.org/viewvc/llvm-project?rev=203290&view=rev
Log:
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.

Modified:
    libcxx/trunk/include/iomanip
    libcxx/trunk/test/input.output/iostream.format/quoted.manip/quoted.pass.cpp

Modified: libcxx/trunk/include/iomanip
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/iomanip?rev=203290&r1=203289&r2=203290&view=diff
==============================================================================
--- libcxx/trunk/include/iomanip (original)
+++ libcxx/trunk/include/iomanip Fri Mar  7 15:45:32 2014
@@ -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>

Modified: libcxx/trunk/test/input.output/iostream.format/quoted.manip/quoted.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/input.output/iostream.format/quoted.manip/quoted.pass.cpp?rev=203290&r1=203289&r2=203290&view=diff
==============================================================================
--- libcxx/trunk/test/input.output/iostream.format/quoted.manip/quoted.pass.cpp (original)
+++ libcxx/trunk/test/input.output/iostream.format/quoted.manip/quoted.pass.cpp Fri Mar  7 15:45:32 2014
@@ -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, cha
     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





More information about the cfe-commits mailing list