From 34c0c7754ffdbc03b94de64f55eb046b9bbaec0d Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Mon, 6 Oct 2025 14:48:24 +0200 Subject: [PATCH] cmString: add methods append and insert --- Source/cmString.hxx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Source/cmString.hxx b/Source/cmString.hxx index c346230c5d..f7dcb2bf97 100644 --- a/Source/cmString.hxx +++ b/Source/cmString.hxx @@ -425,6 +425,16 @@ public: r.append(v.data(), v.size()); return *this = std::move(r); } + template + typename std::enable_if::value, String&>::type append(T&& s) + { + string_view v = AsStringView::view(std::forward(s)); + std::string r; + r.reserve(this->size() + v.size()); + r.assign(this->data(), this->size()); + r.append(v.data(), v.size()); + return *this = std::move(r); + } /** Assign to an empty string. */ void clear() { *this = ""_s; } @@ -432,6 +442,20 @@ public: /** Insert 'count' copies of 'ch' at position 'index'. */ String& insert(size_type index, size_type count, char ch); + /** Insert into the string using any type that implements the + AsStringView trait. */ + template + typename std::enable_if::value, String&>::type insert( + size_type index, T&& s) + { + string_view v = AsStringView::view(std::forward(s)); + std::string r; + r.reserve(this->size() + v.size()); + r.assign(this->data(), this->size()); + r.insert(index, v.data(), v.size()); + return *this = std::move(r); + } + /** Erase 'count' characters starting at position 'index'. */ String& erase(size_type index = 0, size_type count = npos);