diff --git a/fmt/string.h b/fmt/string.h index 1f82f957..e7beb039 100644 --- a/fmt/string.h +++ b/fmt/string.h @@ -20,7 +20,7 @@ namespace internal { template class StringBuffer : public Buffer { private: - std::string data_; + std::basic_string data_; protected: virtual void grow(std::size_t size) { @@ -31,7 +31,7 @@ class StringBuffer : public Buffer { public: // Moves the data to ``str`` clearing the buffer. - void move_to(std::string &str) { + void move_to(std::basic_string &str) { data_.resize(this->size_); str.swap(data_); this->capacity_ = this->size_ = 0; @@ -82,14 +82,14 @@ class BasicStringWriter : public BasicWriter { Constructs a :class:`fmt::BasicStringWriter` object. \endrst */ - BasicStringWriter() : Writer(buffer_) {} + BasicStringWriter() : BasicWriter(buffer_) {} /** \rst Moves the buffer content to *str* clearing the buffer. \endrst */ - void move_to(std::string &str) { + void move_to(std::basic_string &str) { buffer_.move_to(str); } }; diff --git a/test/string-test.cc b/test/string-test.cc index 06265daa..f74a5b8a 100644 --- a/test/string-test.cc +++ b/test/string-test.cc @@ -67,6 +67,14 @@ TEST(StringWriterTest, MoveTo) { EXPECT_EQ(0, out.size()); } +TEST(StringWriterTest, WString) { + fmt::WStringWriter out; + out << "The answer is " << 42 << "\n"; + std::wstring s; + out.move_to(s); + EXPECT_EQ(L"The answer is 42\n", s); +} + TEST(StringTest, ToString) { EXPECT_EQ("42", fmt::to_string(42)); }