Move printf-related code to printf.cc

This commit is contained in:
Victor Zverovich 2017-07-15 09:46:18 -04:00
parent 361911dd18
commit d16582a038
4 changed files with 22 additions and 17 deletions

View File

@ -1,6 +1,6 @@
# Define the fmt library, its includes and the needed defines.
# format.cc is added to FMT_HEADERS for the header-only configuration.
set(FMT_HEADERS format.h format.cc ostream.h ostream.cc printf.h
set(FMT_HEADERS format.h format.cc ostream.h ostream.cc printf.h printf.cc
string.h time.h)
if (HAVE_OPEN)
set(FMT_HEADERS ${FMT_HEADERS} posix.h)

View File

@ -26,7 +26,6 @@
*/
#include "fmt/format.h"
#include "fmt/printf.h"
#include <string.h>
@ -438,17 +437,6 @@ FMT_FUNC void vprint_colored(Color c, cstring_view format, args args) {
std::fputs(RESET_COLOR, stdout);
}
template <typename Char>
void printf(basic_writer<Char> &w, basic_cstring_view<Char> format, args args);
FMT_FUNC int vfprintf(std::FILE *f, cstring_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 struct internal::basic_data<void>;
@ -459,8 +447,6 @@ template void basic_fixed_buffer<char>::grow(std::size_t);
template void internal::arg_map<context>::init(const args &args);
template void printf_context<char>::format(buffer &);
template int internal::char_traits<char>::format_float(
char *buffer, std::size_t size, const char *format,
unsigned width, int precision, double value);
@ -477,8 +463,6 @@ template void basic_fixed_buffer<wchar_t>::grow(std::size_t);
template void internal::arg_map<wcontext>::init(const wargs &args);
template void printf_context<wchar_t>::format(wbuffer &);
template int internal::char_traits<wchar_t>::format_float(
wchar_t *buffer, std::size_t size, const wchar_t *format,
unsigned width, int precision, double value);

20
fmt/printf.cc Normal file
View File

@ -0,0 +1,20 @@
#include "fmt/printf.h"
namespace fmt {
template <typename Char>
void printf(basic_writer<Char> &w, basic_cstring_view<Char> format, args args);
FMT_FUNC int vfprintf(std::FILE *f, cstring_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

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