fd/fmt: Support direct string writing
Change-Id: Id49ba3aef72fdc583dbd1b1defe5a0d8b107b238
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/include-fd/stdplus/fd/fmt.hpp b/include-fd/stdplus/fd/fmt.hpp
index 73402a7..bc535b1 100644
--- a/include-fd/stdplus/fd/fmt.hpp
+++ b/include-fd/stdplus/fd/fmt.hpp
@@ -3,6 +3,7 @@
#include <stdplus/fd/intf.hpp>
#include <stdplus/str/buf.hpp>
+#include <stdplus/str/cat.hpp>
#include <format>
#include <functional>
@@ -47,6 +48,12 @@
writeIfNeeded();
}
+ inline void appends(const auto&... s)
+ {
+ strAppend(buf, s...);
+ writeIfNeeded();
+ }
+
void flush();
private:
diff --git a/test/fd/fmt.cpp b/test/fd/fmt.cpp
index 397fcae..bdac7a4 100644
--- a/test/fd/fmt.cpp
+++ b/test/fd/fmt.cpp
@@ -22,18 +22,17 @@
auto fd = ManagedFd(CHECK_ERRNO(memfd_create("test", 0), "memfd_create"));
{
FormatBuffer buf(fd, 4096);
- buf.append("hi\n");
- buf.append("hi\n"sv);
+ buf.appends("hi\n", "hi\n"sv);
EXPECT_EQ(0, fd.lseek(0, Whence::Cur));
buf.flush();
EXPECT_EQ(6, fd.lseek(0, Whence::Cur));
buf.append(FMT_COMPILE("{}"), std::string(2050, 'a'));
EXPECT_EQ(6, fd.lseek(0, Whence::Cur));
- buf.append(FMT_COMPILE("{}"), std::string(2050, 'a'));
+ buf.append("{}", std::string(2050, 'a'));
EXPECT_EQ(4106, fd.lseek(0, Whence::Cur));
- buf.append("hi\n");
+ buf.appends("hi\n");
EXPECT_EQ(4106, fd.lseek(0, Whence::Cur));
}
EXPECT_EQ(4109, fd.lseek(0, Whence::Cur));