print: Split out function for directly writing out strings
Change-Id: I5d7a671ac75c63f98facca70321ede0a5a372271
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/include/stdplus/print.hpp b/include/stdplus/print.hpp
index d74f2f1..bc49570 100644
--- a/include/stdplus/print.hpp
+++ b/include/stdplus/print.hpp
@@ -1,12 +1,12 @@
#include <stdplus/str/buf.hpp>
-#include <cstdio>
#include <format>
-#include <system_error>
namespace stdplus
{
+void prints(std::FILE* stream, std::string_view data);
+
template <bool ln>
struct Printer
{
@@ -21,11 +21,7 @@
{
buf.push_back('\n');
}
- int r = std::fwrite(buf.data(), sizeof(char), buf.size(), stream);
- if (r < 0)
- {
- throw std::system_error(errno, std::generic_category());
- }
+ prints(stream, buf);
}
};
diff --git a/src/print.cpp b/src/print.cpp
index 4c16fe3..5a54d9e 100644
--- a/src/print.cpp
+++ b/src/print.cpp
@@ -1 +1,16 @@
#include <stdplus/print.hpp>
+
+#include <cstdio>
+#include <system_error>
+
+namespace stdplus
+{
+void prints(std::FILE* stream, std::string_view data)
+{
+ int r = std::fwrite(data.data(), sizeof(char), data.size(), stream);
+ if (r < 0)
+ {
+ throw std::system_error(errno, std::generic_category());
+ }
+}
+} // namespace stdplus