mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-06 23:30:29 +00:00
Update the API.
This commit is contained in:
parent
856e129cc6
commit
d5b8196749
12
format.cc
12
format.cc
@ -1111,6 +1111,18 @@ void fmt::print(StringRef format, const ArgList &args) {
|
||||
std::fwrite(w.data(), 1, w.size(), stdout);
|
||||
}
|
||||
|
||||
void fmt::print(std::FILE *f, StringRef format, const ArgList &args) {
|
||||
Writer w;
|
||||
w.format(format, args);
|
||||
std::fwrite(w.data(), 1, w.size(), f);
|
||||
}
|
||||
|
||||
void fmt::printf(StringRef format, const ArgList &args) {
|
||||
Writer w;
|
||||
w.printf(format, args);
|
||||
std::fwrite(w.data(), 1, w.size(), stdout);
|
||||
}
|
||||
|
||||
// Explicit instantiations for char.
|
||||
|
||||
template fmt::BasicWriter<char>::CharPtr
|
||||
|
36
format.h
36
format.h
@ -1962,6 +1962,15 @@ inline WWriter format(WStringRef format, const ArgList &args) {
|
||||
}
|
||||
|
||||
void print(StringRef format, const ArgList &args);
|
||||
void print(std::FILE *f, StringRef format, const ArgList &args);
|
||||
|
||||
inline Writer sprintf(StringRef format, const ArgList &args) {
|
||||
Writer w;
|
||||
w.printf(format, args);
|
||||
return move(w);
|
||||
}
|
||||
|
||||
void printf(StringRef format, const ArgList &args);
|
||||
|
||||
#if FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES
|
||||
|
||||
@ -2005,6 +2014,10 @@ void Print(StringRef format, const Args & ... args) {
|
||||
std::fwrite(w.data(), 1, w.size(), stdout);
|
||||
}
|
||||
|
||||
// This function is deprecated, use fmt::print instead.
|
||||
template<typename... Args>
|
||||
FMT_DEPRECATED(void Print(std::FILE *f, StringRef format, const Args & ... args));
|
||||
|
||||
template<typename... Args>
|
||||
void Print(std::FILE *f, StringRef format, const Args & ... args) {
|
||||
Writer w;
|
||||
@ -2012,20 +2025,6 @@ void Print(std::FILE *f, StringRef format, const Args & ... args) {
|
||||
std::fwrite(w.data(), 1, w.size(), f);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline Writer sprintf(StringRef format, const Args & ... args) {
|
||||
Writer w;
|
||||
w.printf(format, args...);
|
||||
return std::move(w);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void printf(StringRef format, const Args & ... args) {
|
||||
Writer w;
|
||||
w.printf(format, args...);
|
||||
std::fwrite(w.data(), 1, w.size(), stdout);
|
||||
}
|
||||
|
||||
#endif // FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES
|
||||
|
||||
/**
|
||||
@ -2224,9 +2223,12 @@ inline void FormatDec(char *&buffer, T value) {
|
||||
FMT_VARIADIC_(wchar_t, ReturnType, func, __VA_ARGS__)
|
||||
|
||||
namespace fmt {
|
||||
FMT_VARIADIC(fmt::Writer, format, fmt::StringRef)
|
||||
FMT_VARIADIC_W(fmt::WWriter, format, fmt::WStringRef)
|
||||
FMT_VARIADIC(void, print, fmt::StringRef)
|
||||
FMT_VARIADIC(Writer, format, StringRef)
|
||||
FMT_VARIADIC_W(WWriter, format, WStringRef)
|
||||
FMT_VARIADIC(void, print, StringRef)
|
||||
FMT_VARIADIC(void, print, std::FILE *, StringRef)
|
||||
FMT_VARIADIC(Writer, sprintf, StringRef)
|
||||
FMT_VARIADIC(void, printf, StringRef)
|
||||
}
|
||||
|
||||
// Restore warnings.
|
||||
|
@ -1590,16 +1590,9 @@ TEST(FormatIntTest, FormatDec) {
|
||||
TEST(FormatTest, Print) {
|
||||
EXPECT_WRITE(stdout, fmt::print("Don't {}!", "panic"), "Don't panic!");
|
||||
EXPECT_WRITE(stderr,
|
||||
fmt::Print(stderr, "Don't {}!") << "panic", "Don't panic!");
|
||||
fmt::print(stderr, "Don't {}!", "panic"), "Don't panic!");
|
||||
}
|
||||
|
||||
#if FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES
|
||||
TEST(FormatTest, PrintVariadic) {
|
||||
EXPECT_WRITE(stderr,
|
||||
fmt::Print(stderr, "Don't {}!", "panic"), "Don't panic!");
|
||||
}
|
||||
#endif // FMT_USE_VARIADIC_TEMPLATES
|
||||
|
||||
TEST(FormatTest, PrintColored) {
|
||||
EXPECT_WRITE(stdout, fmt::PrintColored(fmt::RED, "Hello, {}!\n") << "world",
|
||||
"\x1b[31mHello, world!\n\x1b[0m");
|
||||
|
@ -32,8 +32,6 @@
|
||||
#include "gtest-extra.h"
|
||||
#include "util.h"
|
||||
|
||||
#if FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES
|
||||
|
||||
using fmt::format;
|
||||
using fmt::FormatError;
|
||||
|
||||
@ -283,5 +281,3 @@ TEST(PrintfTest, Length) {
|
||||
}
|
||||
|
||||
// TODO: test type specifier
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user