[Libreoffice-commits] core.git: Branch 'libreoffice-6-2' - include/o3tl o3tl/qa
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Sun Dec 16 19:30:34 UTC 2018
include/o3tl/string_view.hxx | 11 +++++------
o3tl/qa/test-string_view.cxx | 9 +++++++++
2 files changed, 14 insertions(+), 6 deletions(-)
New commits:
commit fc0e731611ad7d485ebd46c600e796bbf1e75537
Author: Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Sun Dec 16 12:52:56 2018 +0100
Commit: Stephan Bergmann <sbergman at redhat.com>
CommitDate: Sun Dec 16 20:30:15 2018 +0100
Fix o3tl::string_view streaming operator <<
(The unnecessary os.setstate(std::ios_base::failbit) was due to a misreading of
C++17 [ostream.formatted.reqmts]/1.)
Change-Id: I7d8285230cb316c7af45c76029e9629517d05d56
Reviewed-on: https://gerrit.libreoffice.org/65217
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
(cherry picked from commit 0d2ac93f4a3bec9d2fe2719b270333193d20596b)
Reviewed-on: https://gerrit.libreoffice.org/65223
diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index bdc81e8d7261..abc6de416c4b 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -792,12 +792,13 @@ operator <<(
std::basic_ostream<charT, traits> & os,
basic_string_view<charT, traits> str)
{
- typename std::basic_ostream<charT, traits>::sentry sentry;
+ typename std::basic_ostream<charT, traits>::sentry sentry(os);
if (sentry) {
auto const w = os.width();
- auto const pad
- = std::max<std::make_unsigned<decltype(w + str.size())>::type>(
- w < 0 ? 0 : w, str.size());
+ auto pad
+ = std::max<typename std::make_unsigned<decltype(w + str.size())>::type>(
+ w < 0 ? 0 : w, str.size())
+ - str.size();
auto const after = (os.flags() & std::ios_base::adjustfield)
== std::ios_base::left;
if (pad != 0 && !after) {
@@ -814,8 +815,6 @@ operator <<(
}
}
os.width(0);
- } else {
- os.setstate(std::ios_base::failbit);
}
return os;
}
diff --git a/o3tl/qa/test-string_view.cxx b/o3tl/qa/test-string_view.cxx
index 977cfebc460a..fb6239fca379 100644
--- a/o3tl/qa/test-string_view.cxx
+++ b/o3tl/qa/test-string_view.cxx
@@ -9,7 +9,9 @@
#include <sal/config.h>
+#include <sstream>
#include <stdexcept>
+#include <string>
#include <cppunit/TestAssert.h>
#include <cppunit/TestFixture.h>
@@ -27,6 +29,7 @@ private:
CPPUNIT_TEST(testChar32Literal);
CPPUNIT_TEST(testWcharLiteral);
CPPUNIT_TEST(testOperations);
+ CPPUNIT_TEST(testOutput);
CPPUNIT_TEST_SUITE_END();
void testCharLiteral() {
@@ -203,6 +206,12 @@ private:
v.find_last_not_of("fxo", o3tl::string_view::npos, 2));
CPPUNIT_ASSERT_EQUAL(npos, v.find_last_not_of("fxo"));
}
+
+ void testOutput() {
+ std::ostringstream s;
+ s << o3tl::string_view("foo");
+ CPPUNIT_ASSERT_EQUAL(std::string("foo"), s.str());
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
More information about the Libreoffice-commits
mailing list