mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-26 00:21:13 +00:00
Fix handling of wide strings in StringWriter
This commit is contained in:
parent
c110c6eca7
commit
65cd664195
@ -20,7 +20,7 @@ namespace internal {
|
|||||||
template <typename Char>
|
template <typename Char>
|
||||||
class StringBuffer : public Buffer<Char> {
|
class StringBuffer : public Buffer<Char> {
|
||||||
private:
|
private:
|
||||||
std::string data_;
|
std::basic_string<Char> data_;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void grow(std::size_t size) {
|
virtual void grow(std::size_t size) {
|
||||||
@ -31,7 +31,7 @@ class StringBuffer : public Buffer<Char> {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Moves the data to ``str`` clearing the buffer.
|
// Moves the data to ``str`` clearing the buffer.
|
||||||
void move_to(std::string &str) {
|
void move_to(std::basic_string<Char> &str) {
|
||||||
data_.resize(this->size_);
|
data_.resize(this->size_);
|
||||||
str.swap(data_);
|
str.swap(data_);
|
||||||
this->capacity_ = this->size_ = 0;
|
this->capacity_ = this->size_ = 0;
|
||||||
@ -82,14 +82,14 @@ class BasicStringWriter : public BasicWriter<Char> {
|
|||||||
Constructs a :class:`fmt::BasicStringWriter` object.
|
Constructs a :class:`fmt::BasicStringWriter` object.
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
BasicStringWriter() : Writer(buffer_) {}
|
BasicStringWriter() : BasicWriter<Char>(buffer_) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\rst
|
\rst
|
||||||
Moves the buffer content to *str* clearing the buffer.
|
Moves the buffer content to *str* clearing the buffer.
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
void move_to(std::string &str) {
|
void move_to(std::basic_string<Char> &str) {
|
||||||
buffer_.move_to(str);
|
buffer_.move_to(str);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -67,6 +67,14 @@ TEST(StringWriterTest, MoveTo) {
|
|||||||
EXPECT_EQ(0, out.size());
|
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) {
|
TEST(StringTest, ToString) {
|
||||||
EXPECT_EQ("42", fmt::to_string(42));
|
EXPECT_EQ("42", fmt::to_string(42));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user