str/cat: Implement StrBuf appending
Change-Id: I67841cc8fb54808754bb5e37d7ece14786c3ae8a
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/include/stdplus/str/cat.hpp b/include/stdplus/str/cat.hpp
index 6ce7ee3..f717abc 100644
--- a/include/stdplus/str/cat.hpp
+++ b/include/stdplus/str/cat.hpp
@@ -5,6 +5,10 @@
namespace stdplus
{
+
+template <typename CharT, std::size_t ObjSize, typename Alloc>
+class BasicStrBuf;
+
namespace detail
{
@@ -15,6 +19,14 @@
dst.reserve((dst.size() + ... + strs.size()));
(dst.append(strs), ...);
}
+template <typename CharT, std::size_t ObjSize, typename Alloc,
+ typename... CharTs>
+constexpr void strAppend(stdplus::BasicStrBuf<CharT, ObjSize, Alloc>& dst,
+ std::basic_string_view<CharTs>... strs)
+{
+ [[maybe_unused]] auto out = dst.append((strs.size() + ... + 0));
+ ((out = std::copy(strs.begin(), strs.end(), out)), ...);
+}
template <typename CharT>
struct DedSV : std::basic_string_view<CharT>
diff --git a/test/str/cat.cpp b/test/str/cat.cpp
index ef958ea..a61800f 100644
--- a/test/str/cat.cpp
+++ b/test/str/cat.cpp
@@ -1,3 +1,4 @@
+#include <stdplus/str/buf.hpp>
#include <stdplus/str/cat.hpp>
#include <stdplus/zstring_view.hpp>
@@ -34,4 +35,13 @@
EXPECT_EQ("func world", strCat("func"s, " world"));
}
+TEST(StrAppend, Buf)
+{
+ StrBuf buf;
+ strAppend(buf, "a ");
+ strAppend(buf);
+ strAppend(buf, "b"s, " c"sv);
+ EXPECT_EQ("a b c", buf);
+}
+
} // namespace stdplus