From 95c358f72154e7ea852c061b6864e0a0aed09354 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 19 May 2021 08:52:16 -0700 Subject: [PATCH] Improve separation between code unit types --- include/fmt/core.h | 18 ++---------------- include/fmt/format.h | 7 +++++++ include/fmt/wchar.h | 4 ++++ test/format-test.cc | 10 ---------- test/locale-test.cc | 6 ++++-- test/wchar-test.cc | 12 ++++++++++++ 6 files changed, 29 insertions(+), 28 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 0075ec54..d245726b 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -494,12 +494,10 @@ template class basic_string_view { }; using string_view = basic_string_view; -using wstring_view = basic_string_view; /** Specifies if ``T`` is a character type. Can be specialized by users. */ template struct is_char : std::false_type {}; template <> struct is_char : std::true_type {}; -template <> struct is_char : std::true_type {}; /** \rst @@ -597,16 +595,7 @@ template using char_t = typename detail::char_t_impl::type; \rst Parsing context consisting of a format string range being parsed and an argument counter for automatic indexing. - - You can use one of the following type aliases for common character types: - - +-----------------------+-------------------------------------+ - | Type | Definition | - +=======================+=====================================+ - | format_parse_context | basic_format_parse_context | - +-----------------------+-------------------------------------+ - | wformat_parse_context | basic_format_parse_context | - +-----------------------+-------------------------------------+ + You can use the ```format_parse_context`` type alias for ``char`` instead. \endrst */ template @@ -673,7 +662,6 @@ class basic_format_parse_context : private ErrorHandler { }; using format_parse_context = basic_format_parse_context; -using wformat_parse_context = basic_format_parse_context; template class basic_format_arg; template class basic_format_args; @@ -1565,7 +1553,6 @@ template using buffer_context = basic_format_context, Char>; using format_context = buffer_context; -using wformat_context = buffer_context; // Workaround an alias issue: https://stackoverflow.com/q/62767544/471164. #define FMT_BUFFER_CONTEXT(Char) \ @@ -1777,10 +1764,9 @@ template class basic_format_args { }; /** An alias to ``basic_format_args``. */ -// Separate types would result in shorter symbols but break ABI compatibility +// A separate type would result in shorter symbols but break ABI compatibility // between clang and gcc on ARM (#1919). using format_args = basic_format_args; -using wformat_args = basic_format_args; // We cannot use enum classes as bit fields because of a gcc bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61414. diff --git a/include/fmt/format.h b/include/fmt/format.h index e5efd1b4..a2287704 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -623,6 +623,9 @@ void iterator_buffer::flush() { FMT_MODULE_EXPORT_BEGIN +using wstring_view = basic_string_view; + +template <> struct is_char : std::true_type {}; template <> struct is_char : std::true_type {}; template <> struct is_char : std::true_type {}; template <> struct is_char : std::true_type {}; @@ -2888,4 +2891,8 @@ FMT_END_NAMESPACE # define FMT_FUNC #endif +#ifdef FMT_DEPRECATED_WCHAR +# include "wchar.h" +#endif + #endif // FMT_FORMAT_H_ diff --git a/include/fmt/wchar.h b/include/fmt/wchar.h index 172c1bf4..7336b88c 100644 --- a/include/fmt/wchar.h +++ b/include/fmt/wchar.h @@ -14,6 +14,10 @@ FMT_BEGIN_NAMESPACE +using wformat_parse_context = basic_format_parse_context; +using wformat_context = buffer_context; +using wformat_args = basic_format_args; + #if FMT_GCC_VERSION && FMT_GCC_VERSION < 409 // Workaround broken conversion on older gcc. template using wformat_string = wstring_view; diff --git a/test/format-test.cc b/test/format-test.cc index 0ff5a49e..aaff8125 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2380,16 +2380,6 @@ TEST(format_test, vformat_to) { s.clear(); fmt::vformat_to(std::back_inserter(s), FMT_STRING("{}"), args); EXPECT_EQ("42", s); - - using wcontext = fmt::wformat_context; - fmt::basic_format_arg warg = fmt::detail::make_arg(42); - auto wargs = fmt::basic_format_args(&warg, 1); - auto w = std::wstring(); - fmt::vformat_to(std::back_inserter(w), L"{}", wargs); - EXPECT_EQ(L"42", w); - w.clear(); - fmt::vformat_to(std::back_inserter(w), FMT_STRING(L"{}"), wargs); - EXPECT_EQ(L"42", w); } template static std::string fmt_to_string(const T& t) { diff --git a/test/locale-test.cc b/test/locale-test.cc index 69be7cea..f2cdd335 100644 --- a/test/locale-test.cc +++ b/test/locale-test.cc @@ -88,8 +88,10 @@ TEST(locale_test, wformat) { auto loc = std::locale(std::locale(), new numpunct()); EXPECT_EQ(L"1234567", fmt::format(std::locale(), L"{:L}", 1234567)); EXPECT_EQ(L"1~234~567", fmt::format(loc, L"{:L}", 1234567)); - fmt::format_arg_store as{1234567}; - EXPECT_EQ(L"1~234~567", fmt::vformat(loc, L"{:L}", fmt::wformat_args(as))); + using wcontext = fmt::buffer_context; + fmt::format_arg_store as{1234567}; + EXPECT_EQ(L"1~234~567", + fmt::vformat(loc, L"{:L}", fmt::basic_format_args(as))); EXPECT_EQ(L"1234567", fmt::format(std::locale("C"), L"{:L}", 1234567)); auto no_grouping_loc = std::locale(std::locale(), new no_grouping()); diff --git a/test/wchar-test.cc b/test/wchar-test.cc index edb5910f..0a472420 100644 --- a/test/wchar-test.cc +++ b/test/wchar-test.cc @@ -9,6 +9,18 @@ #include "gtest/gtest.h" +TEST(format_test, vformat_to) { + using wcontext = fmt::wformat_context; + fmt::basic_format_arg warg = fmt::detail::make_arg(42); + auto wargs = fmt::basic_format_args(&warg, 1); + auto w = std::wstring(); + fmt::vformat_to(std::back_inserter(w), L"{}", wargs); + EXPECT_EQ(L"42", w); + w.clear(); + fmt::vformat_to(std::back_inserter(w), FMT_STRING(L"{}"), wargs); + EXPECT_EQ(L"42", w); +} + #if FMT_USE_USER_DEFINED_LITERALS TEST(format_test, format_udl) { using namespace fmt::literals;