Issue 205: Make iostream support optional.
This commit is contained in:
parent
221eeda912
commit
2cca51c744
@ -1252,11 +1252,13 @@ FMT_FUNC void fmt::print(CStringRef format_str, ArgList args) {
|
|||||||
print(stdout, format_str, args);
|
print(stdout, format_str, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef FMT_NO_STREAM_LIBRARIES
|
||||||
FMT_FUNC void fmt::print(std::ostream &os, CStringRef format_str, ArgList args) {
|
FMT_FUNC void fmt::print(std::ostream &os, CStringRef format_str, ArgList args) {
|
||||||
MemoryWriter w;
|
MemoryWriter w;
|
||||||
w.write(format_str, args);
|
w.write(format_str, args);
|
||||||
os.write(w.data(), w.size());
|
os.write(w.data(), w.size());
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
FMT_FUNC void fmt::print_colored(Color c, CStringRef format, ArgList args) {
|
FMT_FUNC void fmt::print_colored(Color c, CStringRef format, ArgList args) {
|
||||||
char escape[] = "\x1b[30m";
|
char escape[] = "\x1b[30m";
|
||||||
|
12
format.h
12
format.h
@ -38,9 +38,12 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#ifndef FMT_NO_STREAM_LIBRARIES
|
||||||
|
# include <sstream>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if _SECURE_SCL
|
#if _SECURE_SCL
|
||||||
# include <iterator>
|
# include <iterator>
|
||||||
#endif
|
#endif
|
||||||
@ -2685,6 +2688,8 @@ void print(std::FILE *f, CStringRef format_str, ArgList args);
|
|||||||
*/
|
*/
|
||||||
void print(CStringRef format_str, ArgList args);
|
void print(CStringRef format_str, ArgList args);
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef FMT_NO_STREAM_LIBRARIES
|
||||||
/**
|
/**
|
||||||
\rst
|
\rst
|
||||||
Prints formatted data to the stream *os*.
|
Prints formatted data to the stream *os*.
|
||||||
@ -2695,6 +2700,7 @@ void print(CStringRef format_str, ArgList args);
|
|||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
void print(std::ostream &os, CStringRef format_str, ArgList args);
|
void print(std::ostream &os, CStringRef format_str, ArgList args);
|
||||||
|
#endif
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
void printf(BasicWriter<Char> &w, BasicCStringRef<Char> format, ArgList args) {
|
void printf(BasicWriter<Char> &w, BasicCStringRef<Char> format, ArgList args) {
|
||||||
@ -3007,7 +3013,11 @@ FMT_VARIADIC(std::string, format, CStringRef)
|
|||||||
FMT_VARIADIC_W(std::wstring, format, WCStringRef)
|
FMT_VARIADIC_W(std::wstring, format, WCStringRef)
|
||||||
FMT_VARIADIC(void, print, CStringRef)
|
FMT_VARIADIC(void, print, CStringRef)
|
||||||
FMT_VARIADIC(void, print, std::FILE *, CStringRef)
|
FMT_VARIADIC(void, print, std::FILE *, CStringRef)
|
||||||
|
|
||||||
|
#ifndef FMT_NO_STREAM_LIBRARIES
|
||||||
FMT_VARIADIC(void, print, std::ostream &, CStringRef)
|
FMT_VARIADIC(void, print, std::ostream &, CStringRef)
|
||||||
|
#endif
|
||||||
|
|
||||||
FMT_VARIADIC(void, print_colored, Color, CStringRef)
|
FMT_VARIADIC(void, print_colored, Color, CStringRef)
|
||||||
FMT_VARIADIC(std::string, sprintf, CStringRef)
|
FMT_VARIADIC(std::string, sprintf, CStringRef)
|
||||||
FMT_VARIADIC_W(std::wstring, sprintf, WCStringRef)
|
FMT_VARIADIC_W(std::wstring, sprintf, WCStringRef)
|
||||||
|
@ -1539,6 +1539,7 @@ TEST(FormatIntTest, FormatDec) {
|
|||||||
EXPECT_EQ("42", format_decimal(42ull));
|
EXPECT_EQ("42", format_decimal(42ull));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef FMT_NO_STREAM_LIBRARIES
|
||||||
TEST(FormatTest, Print) {
|
TEST(FormatTest, Print) {
|
||||||
#if FMT_USE_FILE_DESCRIPTORS
|
#if FMT_USE_FILE_DESCRIPTORS
|
||||||
EXPECT_WRITE(stdout, fmt::print("Don't {}!", "panic"), "Don't panic!");
|
EXPECT_WRITE(stdout, fmt::print("Don't {}!", "panic"), "Don't panic!");
|
||||||
@ -1549,6 +1550,7 @@ TEST(FormatTest, Print) {
|
|||||||
fmt::print(os, "Don't {}!", "panic");
|
fmt::print(os, "Don't {}!", "panic");
|
||||||
EXPECT_EQ("Don't panic!", os.str());
|
EXPECT_EQ("Don't panic!", os.str());
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if FMT_USE_FILE_DESCRIPTORS
|
#if FMT_USE_FILE_DESCRIPTORS
|
||||||
TEST(FormatTest, PrintColored) {
|
TEST(FormatTest, PrintColored) {
|
||||||
|
Loading…
Reference in New Issue
Block a user