mirror of
https://github.com/fmtlib/fmt.git
synced 2025-08-01 11:44:46 +02:00
committed by
Jonathan Müller
parent
f5b1c16e2c
commit
1d2049b53e
@@ -1,6 +1,6 @@
|
|||||||
# Define the fmt library, its includes and the needed defines.
|
# Define the fmt library, its includes and the needed defines.
|
||||||
# format.cc is added to FMT_HEADERS for the header-only configuration.
|
# *.cc are 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)
|
string.h time.h)
|
||||||
if (HAVE_OPEN)
|
if (HAVE_OPEN)
|
||||||
set(FMT_HEADERS ${FMT_HEADERS} posix.h)
|
set(FMT_HEADERS ${FMT_HEADERS} posix.h)
|
||||||
|
@@ -26,7 +26,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "format.h"
|
#include "format.h"
|
||||||
#include "printf.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -106,8 +105,6 @@ inline int fmt_snprintf(char *buffer, size_t size, const char *format, ...) {
|
|||||||
# define FMT_SWPRINTF swprintf
|
# define FMT_SWPRINTF swprintf
|
||||||
#endif // defined(_WIN32) && defined(__MINGW32__) && !defined(__NO_ISOCEXT)
|
#endif // defined(_WIN32) && defined(__MINGW32__) && !defined(__NO_ISOCEXT)
|
||||||
|
|
||||||
const char RESET_COLOR[] = "\x1b[0m";
|
|
||||||
|
|
||||||
typedef void (*FormatFunc)(Writer &, int, StringRef);
|
typedef void (*FormatFunc)(Writer &, int, StringRef);
|
||||||
|
|
||||||
// Portable thread-safe version of strerror.
|
// Portable thread-safe version of strerror.
|
||||||
@@ -486,34 +483,6 @@ FMT_FUNC void report_windows_error(
|
|||||||
}
|
}
|
||||||
#endif
|
#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<char>('0' + c);
|
|
||||||
std::fputs(escape, stdout);
|
|
||||||
print(format, args);
|
|
||||||
std::fputs(RESET_COLOR, stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Char>
|
|
||||||
void printf(BasicWriter<Char> &w, BasicCStringRef<Char> format, ArgList args);
|
|
||||||
|
|
||||||
FMT_FUNC int fprintf(std::FILE *f, CStringRef format, ArgList args) {
|
|
||||||
MemoryWriter w;
|
|
||||||
printf(w, format, args);
|
|
||||||
std::size_t size = w.size();
|
|
||||||
return std::fwrite(w.data(), 1, size, f) < size ? -1 : static_cast<int>(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef FMT_HEADER_ONLY
|
#ifndef FMT_HEADER_ONLY
|
||||||
|
|
||||||
template struct internal::BasicData<void>;
|
template struct internal::BasicData<void>;
|
||||||
@@ -524,8 +493,6 @@ template void internal::FixedBuffer<char>::grow(std::size_t);
|
|||||||
|
|
||||||
template void internal::ArgMap<char>::init(const ArgList &args);
|
template void internal::ArgMap<char>::init(const ArgList &args);
|
||||||
|
|
||||||
template void PrintfFormatter<char>::format(CStringRef format);
|
|
||||||
|
|
||||||
template int internal::CharTraits<char>::format_float(
|
template int internal::CharTraits<char>::format_float(
|
||||||
char *buffer, std::size_t size, const char *format,
|
char *buffer, std::size_t size, const char *format,
|
||||||
unsigned width, int precision, double value);
|
unsigned width, int precision, double value);
|
||||||
@@ -540,8 +507,6 @@ template void internal::FixedBuffer<wchar_t>::grow(std::size_t);
|
|||||||
|
|
||||||
template void internal::ArgMap<wchar_t>::init(const ArgList &args);
|
template void internal::ArgMap<wchar_t>::init(const ArgList &args);
|
||||||
|
|
||||||
template void PrintfFormatter<wchar_t>::format(WCStringRef format);
|
|
||||||
|
|
||||||
template int internal::CharTraits<wchar_t>::format_float(
|
template int internal::CharTraits<wchar_t>::format_float(
|
||||||
wchar_t *buffer, std::size_t size, const wchar_t *format,
|
wchar_t *buffer, std::size_t size, const wchar_t *format,
|
||||||
unsigned width, int precision, double value);
|
unsigned width, int precision, double value);
|
||||||
|
56
fmt/printf.cc
Normal file
56
fmt/printf.cc
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
Formatting library for C++
|
||||||
|
|
||||||
|
Copyright (c) 2012 - 2016, Victor Zverovich
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
For the license information refer to format.h.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "format.h"
|
||||||
|
#include "printf.h"
|
||||||
|
|
||||||
|
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<char>('0' + c);
|
||||||
|
std::fputs(escape, stdout);
|
||||||
|
print(format, args);
|
||||||
|
std::fputs(RESET_COLOR, stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Char>
|
||||||
|
void printf(BasicWriter<Char> &w, BasicCStringRef<Char> format, ArgList args);
|
||||||
|
|
||||||
|
FMT_FUNC int fprintf(std::FILE *f, CStringRef format, ArgList args) {
|
||||||
|
MemoryWriter w;
|
||||||
|
printf(w, format, args);
|
||||||
|
std::size_t size = w.size();
|
||||||
|
return std::fwrite(w.data(), 1, size, f) < size ? -1 : static_cast<int>(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef FMT_HEADER_ONLY
|
||||||
|
|
||||||
|
template void PrintfFormatter<char>::format(CStringRef format);
|
||||||
|
template void PrintfFormatter<wchar_t>::format(WCStringRef format);
|
||||||
|
|
||||||
|
#endif // FMT_HEADER_ONLY
|
||||||
|
|
||||||
|
} // namespace fmt
|
@@ -555,4 +555,8 @@ inline int fprintf(std::ostream &os, CStringRef format_str, ArgList args) {
|
|||||||
FMT_VARIADIC(int, fprintf, std::ostream &, CStringRef)
|
FMT_VARIADIC(int, fprintf, std::ostream &, CStringRef)
|
||||||
} // namespace fmt
|
} // namespace fmt
|
||||||
|
|
||||||
|
#ifdef FMT_HEADER_ONLY
|
||||||
|
# include "printf.cc"
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // FMT_PRINTF_H_
|
#endif // FMT_PRINTF_H_
|
||||||
|
@@ -99,7 +99,7 @@ endif ()
|
|||||||
|
|
||||||
if (HAVE_OPEN)
|
if (HAVE_OPEN)
|
||||||
add_fmt_executable(posix-mock-test
|
add_fmt_executable(posix-mock-test
|
||||||
posix-mock-test.cc ../fmt/format.cc ${TEST_MAIN_SRC})
|
posix-mock-test.cc ../fmt/format.cc ../fmt/printf.cc ${TEST_MAIN_SRC})
|
||||||
target_include_directories(posix-mock-test PRIVATE ${PROJECT_SOURCE_DIR})
|
target_include_directories(posix-mock-test PRIVATE ${PROJECT_SOURCE_DIR})
|
||||||
target_compile_definitions(posix-mock-test PRIVATE FMT_USE_FILE_DESCRIPTORS=1)
|
target_compile_definitions(posix-mock-test PRIVATE FMT_USE_FILE_DESCRIPTORS=1)
|
||||||
target_link_libraries(posix-mock-test gmock)
|
target_link_libraries(posix-mock-test gmock)
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
#include "fmt/format.h"
|
#include "fmt/printf.h"
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
for(int i = 0; i < argc; ++i)
|
for(int i = 0; i < argc; ++i)
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
#include "fmt/format.h"
|
#include "fmt/printf.h"
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
for(int i = 0; i < argc; ++i)
|
for(int i = 0; i < argc; ++i)
|
||||||
|
@@ -28,8 +28,9 @@
|
|||||||
#define FMT_NOEXCEPT
|
#define FMT_NOEXCEPT
|
||||||
#include "test-assert.h"
|
#include "test-assert.h"
|
||||||
|
|
||||||
// Include format.cc instead of format.h to test implementation-specific stuff.
|
// Include *.cc instead of *.h to test implementation-specific stuff.
|
||||||
#include "fmt/format.cc"
|
#include "fmt/format.cc"
|
||||||
|
#include "fmt/printf.cc"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
Reference in New Issue
Block a user