From 11539da8514c68bab4578789eb437c00afea0a81 Mon Sep 17 00:00:00 2001 From: Marian Krivos Date: Sun, 13 May 2012 17:23:57 +0000 Subject: [PATCH] added Buffer append() --- Foundation/include/Poco/Buffer.h | 16 ++++++++++++++++ Foundation/testsuite/src/CoreTest.cpp | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/Foundation/include/Poco/Buffer.h b/Foundation/include/Poco/Buffer.h index 5a461bf38..7f44625e3 100644 --- a/Foundation/include/Poco/Buffer.h +++ b/Foundation/include/Poco/Buffer.h @@ -116,6 +116,22 @@ public: _used = newCapacity; } + void append(const T* buf, std::size_t sz) + /// Resizes this buffer and appends the argument buffer. + { + if (0 == sz) + return; + std::size_t oldSize = _used; + resize(_used + sz, true); + std::memcpy(_ptr + oldSize, buf, sz); + } + + void append(const Buffer& buf) + /// Resizes this buffer and appends the argument buffer. + { + append(buf.begin(), buf.size()); + } + std::size_t capacity() const /// Returns the allocated memory size. { diff --git a/Foundation/testsuite/src/CoreTest.cpp b/Foundation/testsuite/src/CoreTest.cpp index 0773c4d38..28139fad9 100644 --- a/Foundation/testsuite/src/CoreTest.cpp +++ b/Foundation/testsuite/src/CoreTest.cpp @@ -251,6 +251,14 @@ void CoreTest::testBuffer() Buffer f = e; assert (f == e); + + buffer g; + g.append("hello", 5); + assert (g.size() == 5); + + g.append(g); + assert (g.size() == 10); + assert ( !memcmp(g.begin(), "hellohello", 10) ); }