2021-05-18 03:47:38 +00:00
|
|
|
// Formatting library for C++ - experimental wchar_t support
|
|
|
|
//
|
|
|
|
// Copyright (c) 2012 - present, Victor Zverovich
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// For the license information refer to format.h.
|
|
|
|
|
|
|
|
#ifndef FMT_WCHAR_H_
|
|
|
|
#define FMT_WCHAR_H_
|
|
|
|
|
2021-05-18 05:19:59 +00:00
|
|
|
#include <cwchar>
|
|
|
|
|
2021-05-18 03:47:38 +00:00
|
|
|
#include "format.h"
|
|
|
|
|
|
|
|
namespace fmt {
|
|
|
|
|
|
|
|
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
|
|
|
|
// Workaround broken conversion on older gcc.
|
|
|
|
template <typename... Args> using wformat_string = wstring_view;
|
|
|
|
#else
|
|
|
|
template <typename... Args>
|
|
|
|
using wformat_string = basic_format_string<wchar_t, type_identity_t<Args>...>;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
constexpr format_arg_store<wformat_context, Args...> make_wformat_args(
|
|
|
|
const Args&... args) {
|
|
|
|
return {args...};
|
|
|
|
}
|
|
|
|
|
2021-05-18 05:19:59 +00:00
|
|
|
inline void vprint(std::FILE* f, wstring_view fmt, wformat_args args) {
|
|
|
|
wmemory_buffer buffer;
|
|
|
|
detail::vformat_to(buffer, fmt, args);
|
|
|
|
buffer.push_back(L'\0');
|
|
|
|
if (std::fputws(buffer.data(), f) == -1)
|
|
|
|
FMT_THROW(system_error(errno, "cannot write to file"));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void vprint(wstring_view fmt, wformat_args args) {
|
|
|
|
vprint(stdout, fmt, args);
|
|
|
|
}
|
|
|
|
|
2021-05-18 03:47:38 +00:00
|
|
|
template <typename... T>
|
2021-05-18 05:19:59 +00:00
|
|
|
void print(std::FILE* f, wformat_string<T...> fmt, T&&... args) {
|
|
|
|
return vprint(f, wstring_view(fmt), make_wformat_args(args...));
|
2021-05-18 03:47:38 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 05:19:59 +00:00
|
|
|
template <typename... T> void print(wformat_string<T...> fmt, T&&... args) {
|
|
|
|
return vprint(wstring_view(fmt), make_wformat_args(args...));
|
2021-05-18 03:47:38 +00:00
|
|
|
}
|
|
|
|
} // namespace fmt
|
|
|
|
|
|
|
|
#endif // FMT_WCHAR_H_
|