forked from fmtlib/fmt
Add to_wstring
This commit is contained in:
@ -1327,10 +1327,16 @@ class arg_formatter_base {
|
|||||||
|
|
||||||
FMT_DISALLOW_COPY_AND_ASSIGN(arg_formatter_base);
|
FMT_DISALLOW_COPY_AND_ASSIGN(arg_formatter_base);
|
||||||
|
|
||||||
void write_char(char_type value) {
|
struct char_writer {
|
||||||
writer_.write_padded(1, specs_, [value](auto &&it) {
|
char_type value;
|
||||||
|
template <typename It>
|
||||||
|
void operator()(It &&it) const {
|
||||||
*it++ = internal::char_traits<char_type>::cast(value);
|
*it++ = internal::char_traits<char_type>::cast(value);
|
||||||
});
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void write_char(char_type value) {
|
||||||
|
writer_.write_padded(1, specs_, char_writer{value});
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_pointer(const void *p) {
|
void write_pointer(const void *p) {
|
||||||
@ -2172,11 +2178,11 @@ template <typename Range>
|
|||||||
class basic_writer {
|
class basic_writer {
|
||||||
public:
|
public:
|
||||||
using char_type = typename Range::value_type;
|
using char_type = typename Range::value_type;
|
||||||
|
using iterator = decltype(std::declval<Range>().begin());
|
||||||
using format_specs = basic_format_specs<char_type>;
|
using format_specs = basic_format_specs<char_type>;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Output iterator.
|
// Output iterator.
|
||||||
using iterator = decltype(std::declval<Range>().begin());
|
|
||||||
iterator out_;
|
iterator out_;
|
||||||
|
|
||||||
std::unique_ptr<locale_provider> locale_;
|
std::unique_ptr<locale_provider> locale_;
|
||||||
@ -3145,6 +3151,14 @@ std::string to_string(const T &value) {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::wstring to_wstring(const T &value) {
|
||||||
|
std::wstring str;
|
||||||
|
internal::container_buffer<std::wstring> buf(str);
|
||||||
|
wwriter(buf).write(value);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
std::basic_string<Char> to_string(const basic_memory_buffer<Char> &buffer) {
|
std::basic_string<Char> to_string(const basic_memory_buffer<Char> &buffer) {
|
||||||
return std::basic_string<Char>(buffer.data(), buffer.size());
|
return std::basic_string<Char>(buffer.data(), buffer.size());
|
||||||
|
@ -1608,6 +1608,10 @@ TEST(FormatTest, ToString) {
|
|||||||
EXPECT_EQ("42", fmt::to_string(42));
|
EXPECT_EQ("42", fmt::to_string(42));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(FormatTest, ToWString) {
|
||||||
|
EXPECT_EQ(L"42", fmt::to_wstring(42));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(FormatTest, OutputIterators) {
|
TEST(FormatTest, OutputIterators) {
|
||||||
std::list<char> out;
|
std::list<char> out;
|
||||||
fmt::format_to(std::back_inserter(out), "{}", 42);
|
fmt::format_to(std::back_inserter(out), "{}", 42);
|
||||||
|
Reference in New Issue
Block a user