Skip to content

Commit

Permalink
Use fputws for outputting wide strings
Browse files Browse the repository at this point in the history
Also adds fwide byte/wide orientation checking to verify streams are
able to receive the character type in question.

On Windows, the fwide calls are no-ops that pass through the second
arg and optimize out the if statement entirely.
  • Loading branch information
jackoalan authored and vitaut committed Jul 25, 2019
1 parent 1235f0a commit 8bd59ec
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <cstdarg>
#include <cstddef> // for std::ptrdiff_t
#include <cstring> // for std::memmove
#include <cwchar>
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
# include <locale>
#endif
Expand Down Expand Up @@ -977,7 +978,10 @@ FMT_FUNC void vprint(std::FILE* f, string_view format_str, format_args args) {
FMT_FUNC void vprint(std::FILE* f, wstring_view format_str, wformat_args args) {
wmemory_buffer buffer;
internal::vformat_to(buffer, format_str, args);
internal::fwrite_fully(buffer.data(), sizeof(wchar_t), buffer.size(), f);
buffer.push_back(L'\0');
if (std::fputws(buffer.data(), f) == -1) {
FMT_THROW(system_error(errno, "cannot write to file"));
}
}

FMT_FUNC void vprint(string_view format_str, format_args args) {
Expand Down

0 comments on commit 8bd59ec

Please sign in to comment.