mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-27 06:35:37 +00:00
Fix wide print overload (#1609)
This commit is contained in:
parent
2864e8432a
commit
80ce222ca6
@ -326,8 +326,8 @@ FMT_CONSTEXPR typename std::make_unsigned<Int>::type to_unsigned(Int value) {
|
||||
|
||||
constexpr unsigned char micro[] = "\u00B5";
|
||||
|
||||
constexpr bool is_utf8() {
|
||||
return FMT_UNICODE ||
|
||||
template <typename Char> constexpr bool is_unicode() {
|
||||
return FMT_UNICODE || sizeof(Char) != 1 ||
|
||||
(sizeof(micro) == 3 && micro[0] == 0xC2 && micro[1] == 0xB5);
|
||||
}
|
||||
|
||||
@ -1659,8 +1659,11 @@ typename buffer_context<Char>::iterator vformat_to(
|
||||
buffer<Char>& buf, basic_string_view<Char> format_str,
|
||||
basic_format_args<buffer_context<type_identity_t<Char>>> args);
|
||||
|
||||
FMT_API void vprint_mojibake(std::FILE*, string_view, format_args);
|
||||
template <typename Char, typename Args,
|
||||
FMT_ENABLE_IF(!std::is_same<Char, char>::value)>
|
||||
inline void vprint_mojibake(std::FILE*, basic_string_view<Char>, const Args&) {}
|
||||
|
||||
FMT_API void vprint_mojibake(std::FILE*, string_view, format_args);
|
||||
#ifndef _WIN32
|
||||
inline void vprint_mojibake(std::FILE*, string_view, format_args) {}
|
||||
#endif
|
||||
@ -1751,10 +1754,9 @@ FMT_API void vprint(std::FILE*, string_view, format_args);
|
||||
fmt::print(stderr, "Don't {}!", "panic");
|
||||
\endrst
|
||||
*/
|
||||
template <typename S, typename... Args,
|
||||
FMT_ENABLE_IF(internal::is_string<S>::value)>
|
||||
template <typename S, typename... Args, typename Char = char_t<S>>
|
||||
inline void print(std::FILE* f, const S& format_str, Args&&... args) {
|
||||
return internal::is_utf8()
|
||||
return internal::is_unicode<Char>()
|
||||
? vprint(f, to_string_view(format_str),
|
||||
internal::make_args_checked<Args...>(format_str, args...))
|
||||
: internal::vprint_mojibake(
|
||||
@ -1773,10 +1775,9 @@ inline void print(std::FILE* f, const S& format_str, Args&&... args) {
|
||||
fmt::print("Elapsed time: {0:.2f} seconds", 1.23);
|
||||
\endrst
|
||||
*/
|
||||
template <typename S, typename... Args,
|
||||
FMT_ENABLE_IF(internal::is_string<S>::value)>
|
||||
template <typename S, typename... Args, typename Char = char_t<S>>
|
||||
inline void print(const S& format_str, Args&&... args) {
|
||||
return internal::is_utf8()
|
||||
return internal::is_unicode<Char>()
|
||||
? vprint(to_string_view(format_str),
|
||||
internal::make_args_checked<Args...>(format_str, args...))
|
||||
: internal::vprint_mojibake(
|
||||
|
@ -1757,6 +1757,8 @@ TEST(FormatTest, Print) {
|
||||
EXPECT_WRITE(stderr, fmt::print(stderr, "Don't {}!", "panic"),
|
||||
"Don't panic!");
|
||||
#endif
|
||||
// Check that the wide print overload compiles.
|
||||
if (fmt::internal::const_check(false)) fmt::print(L"test");
|
||||
}
|
||||
|
||||
TEST(FormatTest, Variadic) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user