Merge printf.cc into printf.h

This commit is contained in:
Victor Zverovich 2017-12-17 08:36:19 -08:00
parent ccaae0c019
commit 955062da2e
4 changed files with 9 additions and 24 deletions

View File

@ -83,7 +83,7 @@ endfunction()
# Define the fmt library, its includes and the needed defines.
# format.cc is added to FMT_HEADERS for the header-only configuration.
add_headers(FMT_HEADERS core.h format.h format.cc locale.h ostream.h ostream.cc
printf.h printf.cc string.h time.h)
printf.h string.h time.h)
if (HAVE_OPEN)
add_headers(FMT_HEADERS posix.h)
add_headers(FMT_SOURCES posix.cc)

View File

@ -1,21 +0,0 @@
#include "fmt/printf.h"
namespace fmt {
template <typename Char>
void printf(basic_writer<Char> &w, basic_string_view<Char> format,
format_args args);
FMT_FUNC int vfprintf(std::FILE *f, string_view format, printf_args args) {
memory_buffer buffer;
printf(buffer, format, args);
std::size_t size = buffer.size();
return std::fwrite(
buffer.data(), 1, size, f) < size ? -1 : static_cast<int>(size);
}
#ifndef FMT_HEADER_ONLY
template void printf_context<char>::format(buffer &);
template void printf_context<wchar_t>::format(wbuffer &);
#endif
}

View File

@ -555,7 +555,13 @@ inline std::wstring sprintf(wstring_view format_str, const Args & ... args) {
return vsprintf(format_str, vargs);
}
FMT_API int vfprintf(std::FILE *f, string_view format, printf_args args);
inline int vfprintf(std::FILE *f, string_view format, printf_args args) {
memory_buffer buffer;
printf(buffer, format, args);
std::size_t size = buffer.size();
return std::fwrite(
buffer.data(), 1, size, f) < size ? -1 : static_cast<int>(size);
}
/**
\rst

View File

@ -30,7 +30,7 @@
// Include format.cc instead of format.h to test implementation-specific stuff.
#include "fmt/format.cc"
#include "fmt/printf.cc"
#include "fmt/printf.h"
#include <algorithm>
#include <cstring>