From a9a9018191b6a31dbfdac1ee0ec4d56fb56e116d Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 29 May 2021 08:26:04 -0700 Subject: [PATCH] Move wmemory_buffer to wchar.h --- include/fmt/format.h | 13 ++----------- include/fmt/wchar.h | 1 + test/format-test.cc | 12 +++++------- test/wchar-test.cc | 6 ++++++ 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 1bb5b3ff..0f10e5e9 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -647,15 +647,7 @@ enum { inline_buffer_size = 500 }; A dynamically growing memory buffer for trivially copyable/constructible types with the first ``SIZE`` elements stored in the object itself. - You can use one of the following type aliases for common character types: - - +----------------+------------------------------+ - | Type | Definition | - +================+==============================+ - | memory_buffer | basic_memory_buffer | - +----------------+------------------------------+ - | wmemory_buffer | basic_memory_buffer | - +----------------+------------------------------+ + You can use the ```memory_buffer`` type alias for ``char`` instead. **Example**:: @@ -785,7 +777,6 @@ void basic_memory_buffer::grow(size_t size) { } using memory_buffer = basic_memory_buffer; -using wmemory_buffer = basic_memory_buffer; template struct is_contiguous> : std::true_type { @@ -1152,7 +1143,7 @@ inline It format_uint(It out, UInt value, int num_digits, bool upper = false) { // A converter from UTF-8 to UTF-16. class utf8_to_utf16 { private: - wmemory_buffer buffer_; + basic_memory_buffer buffer_; public: FMT_API explicit utf8_to_utf16(string_view s); diff --git a/include/fmt/wchar.h b/include/fmt/wchar.h index 91f3bb3a..d3987976 100644 --- a/include/fmt/wchar.h +++ b/include/fmt/wchar.h @@ -24,6 +24,7 @@ using wstring_view = basic_string_view; using wformat_parse_context = basic_format_parse_context; using wformat_context = buffer_context; using wformat_args = basic_format_args; +using wmemory_buffer = basic_memory_buffer; #if FMT_GCC_VERSION && FMT_GCC_VERSION < 409 // Workaround broken conversion on older gcc. diff --git a/test/format-test.cc b/test/format-test.cc index 44a2415d..d1b01043 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -13,7 +13,8 @@ #include "fmt/format.h" // clang-format on -#include // uint32_t +#include // uint32_t + #include // INT_MAX #include // std::signbit #include // std::strlen @@ -1896,12 +1897,9 @@ TEST(format_test, format_to_wide) { } TEST(format_test, format_to_memory_buffer) { - fmt::basic_memory_buffer buffer; - fmt::format_to(buffer, "{}", "foo"); - EXPECT_EQ("foo", to_string(buffer)); - fmt::wmemory_buffer wbuffer; - fmt::format_to(wbuffer, L"{}", L"foo"); - EXPECT_EQ(L"foo", to_string(wbuffer)); + auto buf = fmt::basic_memory_buffer(); + fmt::format_to(buf, "{}", "foo"); + EXPECT_EQ("foo", to_string(buf)); } TEST(format_test, format_to_vector) { diff --git a/test/wchar-test.cc b/test/wchar-test.cc index c3d54d3b..ca776414 100644 --- a/test/wchar-test.cc +++ b/test/wchar-test.cc @@ -37,6 +37,12 @@ TEST(wchar_test, vformat_to) { EXPECT_EQ(L"42", w); } +TEST(wchar_test, format_to_memory_buffer) { + auto buf = fmt::wmemory_buffer(); + fmt::format_to(buf, L"{}", L"foo"); + EXPECT_EQ(L"foo", to_string(buf)); +} + TEST(format_test, wide_format_to_n) { wchar_t buffer[4]; buffer[3] = L'x';