Move fmt::fprintf to printf.h
diff --git a/doc/api.rst b/doc/api.rst
index c48dfb0..ba847ae 100644
--- a/doc/api.rst
+++ b/doc/api.rst
@@ -81,8 +81,6 @@
.. doxygenfunction:: print(std::ostream&, CStringRef, ArgList)
-.. doxygenfunction:: fprintf(std::ostream&, CStringRef, ArgList)
-
Argument formatters
-------------------
@@ -140,6 +138,8 @@
.. doxygenfunction:: fprintf(std::FILE *, CStringRef, ArgList)
+.. doxygenfunction:: fprintf(std::ostream&, CStringRef, ArgList)
+
.. doxygenfunction:: sprintf(CStringRef, ArgList)
.. doxygenclass:: fmt::PrintfFormatter
diff --git a/fmt/ostream.cc b/fmt/ostream.cc
index e1d9acc..2890b4a 100644
--- a/fmt/ostream.cc
+++ b/fmt/ostream.cc
@@ -8,13 +8,11 @@
*/
#include "fmt/ostream.h"
-#include "fmt/printf.h"
namespace fmt {
-namespace {
-// Write the content of w to os.
-void write(std::ostream &os, Writer &w) {
+namespace internal {
+FMT_FUNC void write(std::ostream &os, Writer &w) {
const char *data = w.data();
typedef internal::MakeUnsigned<std::streamsize>::Type UnsignedStreamSize;
UnsignedStreamSize size = w.size();
@@ -32,13 +30,6 @@
FMT_FUNC void print(std::ostream &os, CStringRef format_str, ArgList args) {
MemoryWriter w;
w.write(format_str, args);
- write(os, w);
-}
-
-FMT_FUNC int fprintf(std::ostream &os, CStringRef format, ArgList args) {
- MemoryWriter w;
- printf(w, format, args);
- write(os, w);
- return static_cast<int>(w.size());
+ internal::write(os, w);
}
} // namespace fmt
diff --git a/fmt/ostream.h b/fmt/ostream.h
index 599d8d7..00b7d71 100644
--- a/fmt/ostream.h
+++ b/fmt/ostream.h
@@ -66,6 +66,9 @@
value = sizeof(convert(get<DummyStream>() << get<T>())) == sizeof(No)
};
};
+
+// Write the content of w to os.
+void write(std::ostream &os, Writer &w);
} // namespace internal
// Formats a value.
@@ -94,18 +97,6 @@
*/
FMT_API void print(std::ostream &os, CStringRef format_str, ArgList args);
FMT_VARIADIC(void, print, std::ostream &, CStringRef)
-
-/**
- \rst
- Prints formatted data to the stream *os*.
-
- **Example**::
-
- fprintf(cerr, "Don't %s!", "panic");
- \endrst
- */
-FMT_API int fprintf(std::ostream &os, CStringRef format_str, ArgList args);
-FMT_VARIADIC(int, fprintf, std::ostream &, CStringRef)
} // namespace fmt
#ifdef FMT_HEADER_ONLY
diff --git a/fmt/printf.h b/fmt/printf.h
index 080b002..f0c0b9a 100644
--- a/fmt/printf.h
+++ b/fmt/printf.h
@@ -13,7 +13,7 @@
#include <algorithm> // std::fill_n
#include <limits> // std::numeric_limits
-#include "fmt/format.h"
+#include "fmt/ostream.h"
namespace fmt {
namespace internal {
@@ -536,6 +536,23 @@
return fprintf(stdout, format, args);
}
FMT_VARIADIC(int, printf, CStringRef)
+
+/**
+ \rst
+ Prints formatted data to the stream *os*.
+
+ **Example**::
+
+ fprintf(cerr, "Don't %s!", "panic");
+ \endrst
+ */
+inline int fprintf(std::ostream &os, CStringRef format_str, ArgList args) {
+ MemoryWriter w;
+ printf(w, format_str, args);
+ internal::write(os, w);
+ return static_cast<int>(w.size());
+}
+FMT_VARIADIC(int, fprintf, std::ostream &, CStringRef)
} // namespace fmt
#endif // FMT_PRINTF_H_
diff --git a/test/ostream-test.cc b/test/ostream-test.cc
index bbcce95..4081b43 100644
--- a/test/ostream-test.cc
+++ b/test/ostream-test.cc
@@ -25,7 +25,7 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "fmt/ostream.cc"
+#include "fmt/ostream.h"
#include <sstream>
#include "gmock/gmock.h"
@@ -35,13 +35,6 @@
using fmt::format;
using fmt::FormatError;
-template <typename Char>
-std::basic_ostream<Char> &operator<<(
- std::basic_ostream<Char> &os, const BasicTestString<Char> &s) {
- os << s.value();
- return os;
-}
-
std::ostream &operator<<(std::ostream &os, const Date &d) {
os << d.year() << '-' << d.month() << '-' << d.day();
return os;
@@ -128,22 +121,11 @@
EXPECT_EQ("Don't panic!", os.str());
}
-TEST(OStreamTest, PrintfCustom) {
- EXPECT_EQ("abc", fmt::sprintf("%s", TestString("abc")));
-}
-
-TEST(OStreamTest, FPrintf) {
- std::ostringstream os;
- int ret = fmt::fprintf(os, "Don't %s!", "panic");
- EXPECT_EQ("Don't panic!", os.str());
- EXPECT_EQ(12, ret);
-}
-
TEST(OStreamTest, WriteToOStream) {
std::ostringstream os;
fmt::MemoryWriter w;
w << "foo";
- fmt::write(os, w);
+ fmt::internal::write(os, w);
EXPECT_EQ("foo", os.str());
}
@@ -188,5 +170,5 @@
data += n;
size -= static_cast<std::size_t>(n);
} while (size != 0);
- fmt::write(os, w);
+ fmt::internal::write(os, w);
}
diff --git a/test/printf-test.cc b/test/printf-test.cc
index 2e3f19c..6bba02e 100644
--- a/test/printf-test.cc
+++ b/test/printf-test.cc
@@ -479,3 +479,14 @@
TEST(PrintfTest, WideString) {
EXPECT_EQ(L"abc", fmt::sprintf(L"%s", L"abc"));
}
+
+TEST(PrintfTest, PrintfCustom) {
+ EXPECT_EQ("abc", fmt::sprintf("%s", TestString("abc")));
+}
+
+TEST(PrintfTest, OStream) {
+ std::ostringstream os;
+ int ret = fmt::fprintf(os, "Don't %s!", "panic");
+ EXPECT_EQ("Don't panic!", os.str());
+ EXPECT_EQ(12, ret);
+}
diff --git a/test/util.h b/test/util.h
index 21d76b2..b7faf62 100644
--- a/test/util.h
+++ b/test/util.h
@@ -87,6 +87,13 @@
typedef BasicTestString<char> TestString;
typedef BasicTestString<wchar_t> TestWString;
+template <typename Char>
+std::basic_ostream<Char> &operator<<(
+ std::basic_ostream<Char> &os, const BasicTestString<Char> &s) {
+ os << s.value();
+ return os;
+}
+
class Date {
int year_, month_, day_;
public: