From 25f8ad13ddc6920f81f82853f724cf380871ff03 Mon Sep 17 00:00:00 2001 From: alabuzhev Date: Fri, 11 Nov 2016 19:27:39 +0200 Subject: [PATCH] Correction of 418 (#420) --- fmt/format.cc | 20 ++++++++++++++++++++ fmt/printf.cc | 24 ------------------------ test/add-subdirectory-test/main.cc | 2 +- test/find-package-test/main.cc | 2 +- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/fmt/format.cc b/fmt/format.cc index ab460242..b2bb7687 100644 --- a/fmt/format.cc +++ b/fmt/format.cc @@ -105,6 +105,8 @@ inline int fmt_snprintf(char *buffer, size_t size, const char *format, ...) { # define FMT_SWPRINTF swprintf #endif // defined(_WIN32) && defined(__MINGW32__) && !defined(__NO_ISOCEXT) +const char RESET_COLOR[] = "\x1b[0m"; + typedef void (*FormatFunc)(Writer &, int, StringRef); // Portable thread-safe version of strerror. @@ -483,6 +485,24 @@ FMT_FUNC void report_windows_error( } #endif +FMT_FUNC void print(std::FILE *f, CStringRef format_str, ArgList args) { + MemoryWriter w; + w.write(format_str, args); + std::fwrite(w.data(), 1, w.size(), f); +} + +FMT_FUNC void print(CStringRef format_str, ArgList args) { + print(stdout, format_str, args); +} + +FMT_FUNC void print_colored(Color c, CStringRef format, ArgList args) { + char escape[] = "\x1b[30m"; + escape[3] = static_cast('0' + c); + std::fputs(escape, stdout); + print(format, args); + std::fputs(RESET_COLOR, stdout); +} + #ifndef FMT_HEADER_ONLY template struct internal::BasicData; diff --git a/fmt/printf.cc b/fmt/printf.cc index be523447..95d7a36a 100644 --- a/fmt/printf.cc +++ b/fmt/printf.cc @@ -12,30 +12,6 @@ namespace fmt { -namespace { - -const char RESET_COLOR[] = "\x1b[0m"; - -} // namespace - -FMT_FUNC void print(std::FILE *f, CStringRef format_str, ArgList args) { - MemoryWriter w; - w.write(format_str, args); - std::fwrite(w.data(), 1, w.size(), f); -} - -FMT_FUNC void print(CStringRef format_str, ArgList args) { - print(stdout, format_str, args); -} - -FMT_FUNC void print_colored(Color c, CStringRef format, ArgList args) { - char escape[] = "\x1b[30m"; - escape[3] = static_cast('0' + c); - std::fputs(escape, stdout); - print(format, args); - std::fputs(RESET_COLOR, stdout); -} - template void printf(BasicWriter &w, BasicCStringRef format, ArgList args); diff --git a/test/add-subdirectory-test/main.cc b/test/add-subdirectory-test/main.cc index 4585ea1b..f39f377c 100644 --- a/test/add-subdirectory-test/main.cc +++ b/test/add-subdirectory-test/main.cc @@ -1,4 +1,4 @@ -#include "fmt/printf.h" +#include "fmt/format.h" int main(int argc, char** argv) { for(int i = 0; i < argc; ++i) diff --git a/test/find-package-test/main.cc b/test/find-package-test/main.cc index 4585ea1b..f39f377c 100644 --- a/test/find-package-test/main.cc +++ b/test/find-package-test/main.cc @@ -1,4 +1,4 @@ -#include "fmt/printf.h" +#include "fmt/format.h" int main(int argc, char** argv) { for(int i = 0; i < argc; ++i)