mirror of
https://github.com/fmtlib/fmt.git
synced 2025-04-16 23:42:38 +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 unsigned char micro[] = "\u00B5";
|
||||||
|
|
||||||
constexpr bool is_utf8() {
|
template <typename Char> constexpr bool is_unicode() {
|
||||||
return FMT_UNICODE ||
|
return FMT_UNICODE || sizeof(Char) != 1 ||
|
||||||
(sizeof(micro) == 3 && micro[0] == 0xC2 && micro[1] == 0xB5);
|
(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,
|
buffer<Char>& buf, basic_string_view<Char> format_str,
|
||||||
basic_format_args<buffer_context<type_identity_t<Char>>> args);
|
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
|
#ifndef _WIN32
|
||||||
inline void vprint_mojibake(std::FILE*, string_view, format_args) {}
|
inline void vprint_mojibake(std::FILE*, string_view, format_args) {}
|
||||||
#endif
|
#endif
|
||||||
@ -1751,10 +1754,9 @@ FMT_API void vprint(std::FILE*, string_view, format_args);
|
|||||||
fmt::print(stderr, "Don't {}!", "panic");
|
fmt::print(stderr, "Don't {}!", "panic");
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
template <typename S, typename... Args,
|
template <typename S, typename... Args, typename Char = char_t<S>>
|
||||||
FMT_ENABLE_IF(internal::is_string<S>::value)>
|
|
||||||
inline void print(std::FILE* f, const S& format_str, Args&&... args) {
|
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),
|
? vprint(f, to_string_view(format_str),
|
||||||
internal::make_args_checked<Args...>(format_str, args...))
|
internal::make_args_checked<Args...>(format_str, args...))
|
||||||
: internal::vprint_mojibake(
|
: 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);
|
fmt::print("Elapsed time: {0:.2f} seconds", 1.23);
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
template <typename S, typename... Args,
|
template <typename S, typename... Args, typename Char = char_t<S>>
|
||||||
FMT_ENABLE_IF(internal::is_string<S>::value)>
|
|
||||||
inline void print(const S& format_str, Args&&... args) {
|
inline void print(const S& format_str, Args&&... args) {
|
||||||
return internal::is_utf8()
|
return internal::is_unicode<Char>()
|
||||||
? vprint(to_string_view(format_str),
|
? vprint(to_string_view(format_str),
|
||||||
internal::make_args_checked<Args...>(format_str, args...))
|
internal::make_args_checked<Args...>(format_str, args...))
|
||||||
: internal::vprint_mojibake(
|
: internal::vprint_mojibake(
|
||||||
|
@ -1757,6 +1757,8 @@ TEST(FormatTest, Print) {
|
|||||||
EXPECT_WRITE(stderr, fmt::print(stderr, "Don't {}!", "panic"),
|
EXPECT_WRITE(stderr, fmt::print(stderr, "Don't {}!", "panic"),
|
||||||
"Don't panic!");
|
"Don't panic!");
|
||||||
#endif
|
#endif
|
||||||
|
// Check that the wide print overload compiles.
|
||||||
|
if (fmt::internal::const_check(false)) fmt::print(L"test");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FormatTest, Variadic) {
|
TEST(FormatTest, Variadic) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user