Skip to content

Commit

Permalink
to_wstring added
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev authored and foonathan committed Aug 27, 2017
1 parent 37eb419 commit 89654cd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ Utilities

.. doxygenfunction:: fmt::to_string(const T&)

.. doxygenfunction:: fmt::to_wstring(const T&)

.. doxygenclass:: fmt::BasicStringRef
:members:

Expand Down
18 changes: 18 additions & 0 deletions fmt/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@ std::string to_string(const T &value) {
w << value;
return w.str();
}

/**
\rst
Converts *value* to ``std::wstring`` using the default format for type *T*.
**Example**::
#include "fmt/string.h"
std::wstring answer = fmt::to_wstring(42);
\endrst
*/
template <typename T>
std::wstring to_wstring(const T &value) {
fmt::WMemoryWriter w;
w << value;
return w.str();
}
}

#endif // FMT_STRING_H_
4 changes: 4 additions & 0 deletions test/string-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ TEST(StringWriterTest, WString) {
TEST(StringTest, ToString) {
EXPECT_EQ("42", fmt::to_string(42));
}

TEST(StringTest, ToWString) {
EXPECT_EQ(L"42", fmt::to_wstring(42));
}

0 comments on commit 89654cd

Please sign in to comment.